12
12
)
13
13
DETACHED_HEAD = "You should not be in a detached HEAD state! Use git checkout main to get back to main"
14
14
MISSING_MERGES = "You are missing some merges"
15
- WRONG_MERGE_ORDER = "You should have merged {branch_name} first. The expected order is feature/login, feature/dashboard, feature/payments"
15
+ NO_MERGES = "You need to start merging the feature branches."
16
+ WRONG_MERGE_ORDER = "You should have merged {branch_name} first. The expected order is feature/login, then feature/dashboard, and last feature/payments"
17
+ FEATURE_LOGIN_MERGE_MISSING = "You should have merged feature/login first."
18
+ FEATURE_DASHBOARD_MERGE_MISSING = "You should have merged feature/dashboard next."
19
+ FEATURE_PAYMENTS_MERGE_MISSING = "You should have merged feature/payments last."
20
+ RESET_MESSAGE = 'Reset the repository using "gitmastery progress reset" and start again'
16
21
17
22
18
23
def verify (exercise : GitAutograderExercise ) -> GitAutograderOutput :
@@ -27,37 +32,23 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
27
32
raise exercise .wrong_answer ([DETACHED_HEAD ])
28
33
29
34
main_reflog = main_branch .reflog
30
- print (exercise .repo .repo .git .reflog ("show" , "main" ).splitlines ())
31
- print (main_reflog )
32
-
33
- try :
34
- # Merge commits exhibit the behavior of having 2 parents (from/to)
35
- expected_order = ["feature/payments" , "feature/dashboard" , "feature/login" ][
36
- ::- 1
37
- ]
38
- i = 0
39
- for entry in main_reflog :
40
- print (entry )
41
- if not entry .action .startswith ("merge" ) or i >= len (expected_order ):
42
- continue
43
- merged_branch = entry .action [len ("merge " ) :]
44
- if merged_branch != expected_order [i ]:
45
- raise exercise .wrong_answer (
46
- [WRONG_MERGE_ORDER .format (branch_name = expected_order [i ])]
47
- )
48
- else :
49
- i += 1
50
-
51
- if i < len (expected_order ):
52
- raise exercise .wrong_answer ([MISSING_MERGES ])
53
-
54
- return exercise .to_output (
55
- ["Great work with using git merge fix the bugs!" ],
56
- GitAutograderStatus .SUCCESSFUL ,
57
- )
58
- except (GitAutograderWrongAnswerException , GitAutograderInvalidStateException ):
59
- raise
60
- except Exception :
61
- raise exercise .wrong_answer (["Something bad happened" ])
62
- finally :
63
- main_branch .checkout ()
35
+ merge_logs = [entry for entry in main_reflog if entry .action .startswith ("merge" )]
36
+ merge_order = [entry .action [len ("merge " ) :] for entry in merge_logs ][::- 1 ]
37
+ if len (merge_order ) == 0 :
38
+ raise exercise .wrong_answer ([NO_MERGES ])
39
+
40
+ if merge_order [0 ] != "feature/login" :
41
+ raise exercise .wrong_answer ([FEATURE_LOGIN_MERGE_MISSING , RESET_MESSAGE ])
42
+
43
+ if merge_order [1 ] != "feature/dashboard" :
44
+ raise exercise .wrong_answer ([FEATURE_DASHBOARD_MERGE_MISSING , RESET_MESSAGE ])
45
+
46
+ if merge_order [2 ] != "feature/payments" :
47
+ raise exercise .wrong_answer ([FEATURE_PAYMENTS_MERGE_MISSING , RESET_MESSAGE ])
48
+
49
+ return exercise .to_output (
50
+ [
51
+ "Great work with merging the branches in order! Try running the HTML files locally!"
52
+ ],
53
+ GitAutograderStatus .SUCCESSFUL ,
54
+ )
0 commit comments