Skip to content

Commit 36a8faa

Browse files
authored
update verify logic and test case for merge-undo (#273)
# Exercise Review ## Exercise Discussion #269 Removed the unnecessary check that enforces students to be on `main` branch when running `verify`. ## Checklist - [ ] If you require a new remote repository on the `Git-Mastery` organization, have you [created a request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.yaml) for it? - [ ] Have you written unit tests using [`repo-smith`](https://github.com/git-mastery/repo-smith) to validate the exercise grading scheme? - [ ] Have you tested your changes using the instructions posted? - [ ] Have you verified that this exercise does not already exist or is not currently in review? - [ ] Did you introduce a new grading mechanism that should belong to [`git-autograder`](https://github.com/git-mastery/git-autograder)? - [ ] Did you introduce a new dependency that should belong to [`app`](https://github.com/git-mastery/app)?
1 parent d4fa302 commit 36a8faa

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

merge_undo/test_verify.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from .verify import (
66
MAIN_WRONG_COMMIT,
77
MERGES_NOT_UNDONE,
8-
NOT_ON_MAIN,
98
RESET_MESSAGE,
9+
MAIN_BRANCH_MISSING,
1010
verify,
1111
)
1212

@@ -105,7 +105,7 @@ def test_main_wrong_commit():
105105
)
106106

107107

108-
def test_not_main():
108+
def test_main_branch_missing():
109109
with loader.start() as (test, rs):
110110
_create_and_commit_file(rs, "rick.txt", "Scientist", "Add Rick")
111111
_create_and_commit_file(rs, "morty.txt", "Boy", "Add Morty")
@@ -127,7 +127,7 @@ def test_not_main():
127127
""",
128128
"Mention Morty is grandson",
129129
)
130-
rs.git.checkout("daughter")
130+
rs.git.branch("master", old_branch="main", move=True)
131131

132132
output = test.run()
133-
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [NOT_ON_MAIN])
133+
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [MAIN_BRANCH_MISSING])

merge_undo/verify.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@
44
GitAutograderStatus,
55
)
66

7-
NOT_ON_MAIN = (
8-
"You aren't currently on the main branch. Checkout to that branch and try again!"
7+
MAIN_BRANCH_MISSING = (
8+
"Main branch is missing, you can reset the exercises if needed and try again."
99
)
10-
DETACHED_HEAD = "You should not be in a detached HEAD state! Use git checkout main to get back to main"
1110
MERGES_NOT_UNDONE = "It appears the merge commits are still in the history of the 'main' branch. This shouldn't be the case"
1211
MAIN_WRONG_COMMIT = "The 'main' branch is not pointing to the correct commit. It should be pointing to the commit made just before the merges."
1312
RESET_MESSAGE = 'Reset the repository using "gitmastery progress reset" and start again'
1413
SUCCESS_MESSAGE = "Great work with undoing the merges! Try listing the directory to see what has changed."
1514

1615

1716
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
18-
repo = exercise.repo.repo
17+
main_branch = exercise.repo.branches.branch_or_none("main")
1918

20-
try:
21-
if repo.active_branch.name != "main":
22-
raise exercise.wrong_answer([NOT_ON_MAIN])
23-
except TypeError:
24-
raise exercise.wrong_answer([DETACHED_HEAD, RESET_MESSAGE])
19+
if not main_branch:
20+
raise exercise.wrong_answer([MAIN_BRANCH_MISSING, RESET_MESSAGE])
2521

26-
main_branch = exercise.repo.branches.branch("main")
2722
main_history = main_branch.commits
2823

2924
if any(len(c.commit.parents) > 1 for c in main_history):

0 commit comments

Comments
 (0)