diff --git a/merge_undo/test_verify.py b/merge_undo/test_verify.py index dc038bd3..d93bbace 100644 --- a/merge_undo/test_verify.py +++ b/merge_undo/test_verify.py @@ -5,8 +5,8 @@ from .verify import ( MAIN_WRONG_COMMIT, MERGES_NOT_UNDONE, - NOT_ON_MAIN, RESET_MESSAGE, + MAIN_BRANCH_MISSING, verify, ) @@ -105,7 +105,7 @@ def test_main_wrong_commit(): ) -def test_not_main(): +def test_main_branch_missing(): with loader.start() as (test, rs): _create_and_commit_file(rs, "rick.txt", "Scientist", "Add Rick") _create_and_commit_file(rs, "morty.txt", "Boy", "Add Morty") @@ -127,7 +127,7 @@ def test_not_main(): """, "Mention Morty is grandson", ) - rs.git.checkout("daughter") + rs.git.branch("master", old_branch="main", move=True) output = test.run() - assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [NOT_ON_MAIN]) + assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [MAIN_BRANCH_MISSING]) diff --git a/merge_undo/verify.py b/merge_undo/verify.py index 0254c452..811b7be9 100644 --- a/merge_undo/verify.py +++ b/merge_undo/verify.py @@ -4,10 +4,9 @@ GitAutograderStatus, ) -NOT_ON_MAIN = ( - "You aren't currently on the main branch. Checkout to that branch and try again!" +MAIN_BRANCH_MISSING = ( + "Main branch is missing, you can reset the exercises if needed and try again." ) -DETACHED_HEAD = "You should not be in a detached HEAD state! Use git checkout main to get back to main" MERGES_NOT_UNDONE = "It appears the merge commits are still in the history of the 'main' branch. This shouldn't be the case" 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." RESET_MESSAGE = 'Reset the repository using "gitmastery progress reset" and start again' @@ -15,15 +14,11 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput: - repo = exercise.repo.repo + main_branch = exercise.repo.branches.branch_or_none("main") - try: - if repo.active_branch.name != "main": - raise exercise.wrong_answer([NOT_ON_MAIN]) - except TypeError: - raise exercise.wrong_answer([DETACHED_HEAD, RESET_MESSAGE]) + if not main_branch: + raise exercise.wrong_answer([MAIN_BRANCH_MISSING, RESET_MESSAGE]) - main_branch = exercise.repo.branches.branch("main") main_history = main_branch.commits if any(len(c.commit.parents) > 1 for c in main_history):