Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions merge_undo/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from .verify import (
MAIN_WRONG_COMMIT,
MERGES_NOT_UNDONE,
NOT_ON_MAIN,
RESET_MESSAGE,
MAIN_BRANCH_MISSING,
verify,
)

Expand Down Expand Up @@ -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")
Expand All @@ -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])
15 changes: 5 additions & 10 deletions merge_undo/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@
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'
SUCCESS_MESSAGE = "Great work with undoing the merges! Try listing the directory to see what has changed."


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])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User will see duplicate message at here.


main_branch = exercise.repo.branches.branch("main")
main_history = main_branch.commits

if any(len(c.commit.parents) > 1 for c in main_history):
Expand Down
Loading