Skip to content

Commit 6482bb7

Browse files
committed
[conflict-mediator] Add download
1 parent 89292a1 commit 6482bb7

File tree

8 files changed

+128
-0
lines changed

8 files changed

+128
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"exercise_name": "conflict-mediator",
3+
"tags": [
4+
"git-merge",
5+
"merge-conflicts"
6+
],
7+
"requires_git": true,
8+
"requires_github": false,
9+
"base_files": {},
10+
"exercise_repo": {
11+
"repo_type": "local",
12+
"repo_name": "conflict",
13+
"repo_title": null,
14+
"create_fork": null,
15+
"init": true
16+
}
17+
}

conflict_mediator/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# conflict-mediator
2+
3+
<!--- Insert exercise description -->
4+
5+
## Task
6+
7+
<!--- Insert exercise task, simplify what needs to be done -->
8+
9+
## Hints
10+
11+
<!--- Insert hints here -->
12+
<!---
13+
Use Github Markdown's collapsible content:
14+
<details>
15+
<summary>...</summary>
16+
...
17+
</details>
18+
-->

conflict_mediator/__init__.py

Whitespace-only changes.

conflict_mediator/download.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import os
2+
import pathlib
3+
import subprocess
4+
import textwrap
5+
from sys import exit
6+
from typing import List, Optional
7+
8+
9+
def run_command(command: List[str], verbose: bool) -> Optional[str]:
10+
try:
11+
result = subprocess.run(
12+
command,
13+
capture_output=True,
14+
text=True,
15+
check=True,
16+
)
17+
if verbose:
18+
print(result.stdout)
19+
return result.stdout
20+
except subprocess.CalledProcessError as e:
21+
if verbose:
22+
print(e.stderr)
23+
exit(1)
24+
25+
26+
def create_or_update_file(
27+
filepath: str | pathlib.Path, contents: Optional[str] = None
28+
) -> None:
29+
if os.path.dirname(filepath) != "":
30+
os.makedirs(os.path.dirname(filepath), exist_ok=True)
31+
if contents is None:
32+
open(filepath, "a").close()
33+
else:
34+
with open(filepath, "w") as file:
35+
file.write(textwrap.dedent(contents).lstrip())
36+
37+
38+
def setup(verbose: bool = False):
39+
commits_str = run_command(
40+
["git", "log", "--reverse", "--pretty=format:%h"], verbose
41+
)
42+
assert commits_str is not None
43+
first_commit = commits_str.split("\n")[-1]
44+
tag_name = f"git-mastery-start-{first_commit}"
45+
run_command(["git", "tag", tag_name], verbose)
46+
47+
create_or_update_file("script.py", "print('Hello ...')")
48+
run_command(["git", "add", "script.py"], verbose)
49+
run_command(["git", "commit", "-m", "Add base script.py"], verbose)
50+
51+
run_command(["git", "checkout", "-b", "A"], verbose)
52+
create_or_update_file("script.py", "print('Hello World!')")
53+
run_command(["git", "add", "script.py"], verbose)
54+
run_command(["git", "commit", "-m", "Hello world"], verbose)
55+
56+
run_command(["git", "checkout", "main"], verbose)
57+
run_command(["git", "checkout", "-b", "B"], verbose)
58+
create_or_update_file("script.py", "print('Hello Everyone!')")
59+
run_command(["git", "add", "script.py"], verbose)
60+
run_command(["git", "commit", "-m", "Hello everyone"], verbose)
61+
62+
run_command(["git", "checkout", "main"], verbose)
63+
run_command(["git", "merge", "A", "--no-edit"], verbose)
64+
run_command(["git", "merge", "B", "--no-edit"], verbose)

conflict_mediator/tests/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from git_autograder import GitAutograderTestLoader
2+
3+
from ..verify import verify
4+
5+
REPOSITORY_NAME = "conflict-mediator"
6+
7+
loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)
8+
9+
10+
def test():
11+
with loader.load("specs/base.yml", "start"):
12+
pass

conflict_mediator/verify.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from git_autograder import (
2+
GitAutograderOutput,
3+
GitAutograderExercise,
4+
GitAutograderStatus,
5+
)
6+
7+
8+
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
9+
# INSERT YOUR GRADING CODE HERE
10+
11+
return exercise.to_output([], GitAutograderStatus.SUCCESSFUL)

0 commit comments

Comments
 (0)