Skip to content

Commit bc65957

Browse files
committed
[branch-bender] Add check for no fast forwarding
1 parent caa082b commit bc65957

9 files changed

Lines changed: 79 additions & 1 deletion

File tree

branch_bender/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You have been working on all of these changes on separate branches and you now w
88

99
### Task 1
1010

11-
Merge the `feature/login` branch into `main` first.
11+
Merge the `feature/login` branch into `main` first. Make sure you do not use fast forwarding when merging!
1212

1313
### Task 2
1414

branch_bender/tests/specs/base.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ initialization:
3131

3232
- type: merge
3333
branch-name: feature/login
34+
no-ff: true
3435
- type: merge
3536
branch-name: feature/dashboard
37+
no-ff: true
3638
- type: merge
3739
branch-name: feature/payments
40+
no-ff: true
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
8+
- type: branch
9+
branch-name: feature/login
10+
- type: commit
11+
empty: true
12+
message: Empty commit on feature/login
13+
- type: checkout
14+
branch-name: main
15+
16+
- type: branch
17+
branch-name: feature/dashboard
18+
- type: commit
19+
empty: true
20+
message: Empty commit on feature/dashboard
21+
- type: checkout
22+
branch-name: main
23+
24+
- type: branch
25+
branch-name: feature/payments
26+
- type: commit
27+
empty: true
28+
message: Empty commit on feature/payments
29+
- type: checkout
30+
branch-name: main
31+
32+
- type: merge
33+
branch-name: feature/login
34+
- type: merge
35+
branch-name: feature/dashboard
36+
- type: merge
37+
branch-name: feature/payments

branch_bender/tests/specs/missing_merges.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ initialization:
3131

3232
- type: merge
3333
branch-name: feature/login
34+
no-ff: true
3435
- type: merge
3536
branch-name: feature/dashboard
37+
no-ff: true

branch_bender/tests/specs/not_dashboard_second.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ initialization:
3131

3232
- type: merge
3333
branch-name: feature/login
34+
no-ff: true
3435
- type: merge
3536
branch-name: feature/payments
37+
no-ff: true
3638
- type: merge
3739
branch-name: feature/dashboard
40+
no-ff: true

branch_bender/tests/specs/not_login_first.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ initialization:
3131

3232
- type: merge
3333
branch-name: feature/dashboard
34+
no-ff: true
3435
- type: merge
3536
branch-name: feature/login
37+
no-ff: true
3638
- type: merge
3739
branch-name: feature/payments
40+
no-ff: true

branch_bender/tests/specs/not_payments_last.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ initialization:
3939

4040
- type: merge
4141
branch-name: feature/login
42+
no-ff: true
4243
- type: merge
4344
branch-name: feature/dashboard
45+
no-ff: true
4446
- type: merge
4547
branch-name: other
48+
no-ff: true

branch_bender/tests/test_verify.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
FEATURE_LOGIN_MERGE_MISSING,
66
FEATURE_PAYMENTS_MERGE_MISSING,
77
MISSING_MERGES,
8+
NO_FAST_FORWARDING,
89
NO_MERGES,
910
NOT_ON_MAIN,
1011
RESET_MESSAGE,
@@ -22,6 +23,15 @@ def test_base():
2223
assert_output(output, GitAutograderStatus.SUCCESSFUL)
2324

2425

26+
def test_ff_fails():
27+
with loader.load("specs/ff_fails.yml", "start") as output:
28+
assert_output(
29+
output,
30+
GitAutograderStatus.UNSUCCESSFUL,
31+
[NO_FAST_FORWARDING.format(branch_name="feature/login"), RESET_MESSAGE],
32+
)
33+
34+
2535
def test_no_merges():
2636
with loader.load("specs/no_merges.yml", "start") as output:
2737
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [NO_MERGES])

branch_bender/verify.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
DETACHED_HEAD = "You should not be in a detached HEAD state! Use git checkout main to get back to main"
1212
MISSING_MERGES = "You are missing some merges"
1313
NO_MERGES = "You need to start merging the feature branches."
14+
NO_FAST_FORWARDING = "You cannot use fast forwarding on {branch_name} when merging."
1415
WRONG_MERGE_ORDER = "You should have merged {branch_name} first. The expected order is feature/login, then feature/dashboard, and last feature/payments"
1516
FEATURE_LOGIN_MERGE_MISSING = "You should have merged feature/login first."
1617
FEATURE_DASHBOARD_MERGE_MISSING = "You should have merged feature/dashboard next."
@@ -31,6 +32,7 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
3132

3233
main_reflog = main_branch.reflog
3334
merge_logs = [entry for entry in main_reflog if entry.action.startswith("merge")]
35+
messages = [entry.message for entry in merge_logs][::-1]
3436
merge_order = [entry.action[len("merge ") :] for entry in merge_logs][::-1]
3537

3638
if len(merge_order) == 0:
@@ -42,12 +44,27 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
4244
if merge_order[0] != "feature/login":
4345
raise exercise.wrong_answer([FEATURE_LOGIN_MERGE_MISSING, RESET_MESSAGE])
4446

47+
if messages[0] == "Fast-forward":
48+
raise exercise.wrong_answer(
49+
[NO_FAST_FORWARDING.format(branch_name="feature/login"), RESET_MESSAGE]
50+
)
51+
4552
if merge_order[1] != "feature/dashboard":
4653
raise exercise.wrong_answer([FEATURE_DASHBOARD_MERGE_MISSING, RESET_MESSAGE])
4754

55+
if messages[1] == "Fast-forward":
56+
raise exercise.wrong_answer(
57+
[NO_FAST_FORWARDING.format(branch_name="feature/dashboard"), RESET_MESSAGE]
58+
)
59+
4860
if merge_order[2] != "feature/payments":
4961
raise exercise.wrong_answer([FEATURE_PAYMENTS_MERGE_MISSING, RESET_MESSAGE])
5062

63+
if messages[2] == "Fast-forward":
64+
raise exercise.wrong_answer(
65+
[NO_FAST_FORWARDING.format(branch_name="feature/payments"), RESET_MESSAGE]
66+
)
67+
5168
return exercise.to_output(
5269
[
5370
"Great work with merging the branches in order! Try running the HTML files locally!"

0 commit comments

Comments
 (0)