@@ -120,6 +120,9 @@ def is_git_state_same(before, after):
return ret
+def git_attach_head(temp_branch):
+ run_sh(f"git switch -C {temp_branch}")
+
def git_detach_head():
run_sh("git switch --detach HEAD")
assert run_sh("git rev-parse --abbrev-ref HEAD") == "HEAD", "Failed to enter detached HEAD state"
@@ -136,10 +139,15 @@ def test(root, patch):
return results
-def test_head_attached(patches, counts):
+def test_head_attached(patches, counts, branch):
+
+ git_attach_head(branch)
+ git_state_before = get_git_state()
for patch_info in patches:
results = test(patch_info["root"], patch_info["patch"])
counts = analyze_result(results, patch_info, counts)
+ git_state_after = get_git_state()
+ assert is_git_state_same(git_state_before, git_state_after), "Repository state changed after attached HEAD test."
return counts
def test_head_detached(patches, counts):
@@ -159,10 +167,13 @@ def test_head_detached(patches, counts):
return counts
def run_tests(patches, counts):
+ temp_branch = "test_patchtest_head_attached"
git_state = get_git_state()
- counts = test_head_attached(patches, counts)
+ assert git_state['branch'] != temp_branch, f"Cannot run patchtest selftest while on branch '{temp_branch}'"
+ counts = test_head_attached(patches, counts, temp_branch)
counts = test_head_detached(patches, counts)
restore_git_state(git_state)
+ run_sh(f"git branch -D {temp_branch}")
return counts