Skip to content

Commit 6c3cf9a

Browse files
authored
[branch-bender] Fix verify logic to allow retries (#220)
# Exercise Review ## Exercise Discussion Fixes #216 ## 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.md) for it? - [X] Have you written unit tests using [`repo-smith`](https://github.com/git-mastery/repo-smith) to validate the exercise grading scheme? - [X] Have you tested your changes using the instructions posted? - [X] 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 f20a7bb commit 6c3cf9a

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

branch_bender/test_verify.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ def test_base():
5959
assert_output(output, GitAutograderStatus.SUCCESSFUL)
6060

6161

62+
def test_merge_undo_succeeds():
63+
with base_setup() as (test, rs):
64+
rs.git.merge("feature/login", no_ff=False)
65+
rs.git.reset("HEAD~1", hard=True)
66+
rs.git.merge("feature/login", no_ff=True)
67+
rs.git.merge("feature/dashboard", no_ff=True)
68+
rs.git.merge("feature/payments", no_ff=True)
69+
70+
output = test.run()
71+
assert_output(output, GitAutograderStatus.SUCCESSFUL)
72+
73+
6274
def test_ff_fails():
6375
with base_setup() as (test, rs):
6476
rs.git.merge("feature/login")

branch_bender/verify.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,28 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
4141
if len(merge_order) < 3:
4242
raise exercise.wrong_answer([MISSING_MERGES])
4343

44-
if merge_order[0] != "feature/login":
44+
# Use negative indexing to check the last 3 merges (most recent)
45+
# This allows users to undo mistakes (e.g., reset --hard after accidental ff) and redo properly
46+
if merge_order[-3] != "feature/login":
4547
raise exercise.wrong_answer([FEATURE_LOGIN_MERGE_MISSING, RESET_MESSAGE])
4648

47-
if messages[0] == "Fast-forward":
49+
if messages[-3] == "Fast-forward":
4850
raise exercise.wrong_answer(
4951
[NO_FAST_FORWARDING.format(branch_name="feature/login"), RESET_MESSAGE]
5052
)
5153

52-
if merge_order[1] != "feature/dashboard":
54+
if merge_order[-2] != "feature/dashboard":
5355
raise exercise.wrong_answer([FEATURE_DASHBOARD_MERGE_MISSING, RESET_MESSAGE])
5456

55-
if messages[1] == "Fast-forward":
57+
if messages[-2] == "Fast-forward":
5658
raise exercise.wrong_answer(
5759
[NO_FAST_FORWARDING.format(branch_name="feature/dashboard"), RESET_MESSAGE]
5860
)
5961

60-
if merge_order[2] != "feature/payments":
62+
if merge_order[-1] != "feature/payments":
6163
raise exercise.wrong_answer([FEATURE_PAYMENTS_MERGE_MISSING, RESET_MESSAGE])
6264

63-
if messages[2] == "Fast-forward":
65+
if messages[-1] == "Fast-forward":
6466
raise exercise.wrong_answer(
6567
[NO_FAST_FORWARDING.format(branch_name="feature/payments"), RESET_MESSAGE]
6668
)

0 commit comments

Comments
 (0)