Skip to content

Commit 460bc96

Browse files
committed
deploy: 98aabff
1 parent 3abeed8 commit 460bc96

File tree

5 files changed

+81
-10
lines changed

5 files changed

+81
-10
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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

branch_rename/tests/test_verify.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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])

branch_rename/verify.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
from git import Repo
24
from git_autograder import (
35
GitAutograderExercise,
@@ -15,15 +17,28 @@
1517
def 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

2944
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:

remote_branch_rename/verify.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from typing import List
23

34
from git import Repo
@@ -27,15 +28,28 @@
2728
def 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

4155
def fetch_remotes(repo: Repo) -> None:

0 commit comments

Comments
 (0)