File tree Expand file tree Collapse file tree 5 files changed +81
-10
lines changed Expand file tree Collapse file tree 5 files changed +81
-10
lines changed Original file line number Diff line number Diff line change 1+ initialization :
2+ steps :
3+ - type : commit
4+ empty : true
5+ message : Empty commit
6+ id : start
7+ - type : branch
8+ branch-name : login
9+ - type : checkout
10+ branch-name : main
11+ - type : branch-rename
12+ branch-name : login
13+ new-name : feature/logi
14+ - type : branch-rename
15+ branch-name : feature/logi
16+ new-name : feature/login
Original file line number Diff line number Diff line change 1+ initialization :
2+ steps :
3+ - type : commit
4+ empty : true
5+ message : Empty commit
6+ id : start
7+ - type : branch
8+ branch-name : login
9+ - type : checkout
10+ branch-name : main
11+ - type : branch-rename
12+ branch-name : login
13+ new-name : feature/login
14+ - type : branch-rename
15+ branch-name : feature/login
16+ new-name : test
Original file line number Diff line number Diff line change @@ -33,3 +33,13 @@ def test_not_rename():
3333 assert_output (
3434 output , GitAutograderStatus .UNSUCCESSFUL , [NO_RENAME_EVIDENCE_FEATURE_LOGIN ]
3535 )
36+
37+
38+ def test_indirect_rename ():
39+ with loader .load ("specs/indirect_rename.yml" ) as output :
40+ assert_output (output , GitAutograderStatus .SUCCESSFUL )
41+
42+
43+ def test_rename_after ():
44+ with loader .load ("specs/rename_after.yml" ) as output :
45+ assert_output (output , GitAutograderStatus .UNSUCCESSFUL , [FEATURE_LOGIN_MISSING ])
Original file line number Diff line number Diff line change 1+ import re
2+
13from git import Repo
24from git_autograder import (
35 GitAutograderExercise ,
1517def branch_has_rename_evidence (
1618 exercise : GitAutograderExercise , new_branch : str , old_branch : str
1719) -> bool :
20+ """Performs a DFS on the branch renames starting with login till feature/login.
21+
22+ This is necessary since the renames could be performed in parts:
23+
24+ login -> feat/login -> feature/login
25+ """
1826 branch = exercise .repo .branches .branch_or_none (new_branch )
1927 if branch is None :
28+ # If new_branch not present at all
2029 return False
2130
22- expected = f"renamed refs/heads/{ old_branch } to refs/heads/{ new_branch } "
23- for entry in branch .reflog :
24- if entry .message == expected :
25- return True
26- return False
31+ rename_regex = re .compile ("^renamed refs/heads/(.+) to refs/heads/(.+)$" )
32+ for entry in branch .reflog [::- 1 ]:
33+ match_group = rename_regex .match (entry .message )
34+ if match_group is None :
35+ continue
36+ original = match_group .group (1 )
37+ new = match_group .group (2 )
38+ if original == old_branch :
39+ old_branch = new
40+
41+ return old_branch == new_branch
2742
2843
2944def verify (exercise : GitAutograderExercise ) -> GitAutograderOutput :
Original file line number Diff line number Diff line change 1+ import re
12from typing import List
23
34from git import Repo
2728def branch_has_rename_evidence (
2829 exercise : GitAutograderExercise , new_branch : str , old_branch : str
2930) -> bool :
31+ """Performs a DFS on the branch renames starting with login till feature/login.
32+
33+ This is necessary since the renames could be performed in parts:
34+
35+ login -> feat/login -> feature/login
36+ """
3037 branch = exercise .repo .branches .branch_or_none (new_branch )
3138 if branch is None :
39+ # If new_branch not present at all
3240 return False
3341
34- expected = f"renamed refs/heads/{ old_branch } to refs/heads/{ new_branch } "
35- for entry in branch .reflog :
36- if entry .message == expected :
37- return True
38- return False
42+ rename_regex = re .compile ("^renamed refs/heads/(.+) to refs/heads/(.+)$" )
43+ for entry in branch .reflog [::- 1 ]:
44+ match_group = rename_regex .match (entry .message )
45+ if match_group is None :
46+ continue
47+ original = match_group .group (1 )
48+ new = match_group .group (2 )
49+ if original == old_branch :
50+ old_branch = new
51+
52+ return old_branch == new_branch
3953
4054
4155def fetch_remotes (repo : Repo ) -> None :
You can’t perform that action at this time.
0 commit comments