Read the branch's reflog in rule-hook overrides when a path shares its name
CI / tests (pull_request) Successful in 2m11s

This commit is contained in:
2026-11-10 11:17:17 +01:00
parent cda45a931c
commit 509804da0d
5 changed files with 28 additions and 6 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ def print_overrides(directory: str) -> int:
return 1
found = guarded_git(directory, "branch", "--show-current")
branch = found if isinstance(found, str) and found else "HEAD"
reflog = guarded_git(directory, "reflog", "show", "--format=%H", branch)
reflog = guarded_git(directory, "reflog", "show", "--format=%H", branch, "--")
head = guarded_git(directory, "rev-parse", "HEAD")
unread = unread_reflog(reflog, head)
if unread:
+9
View File
@@ -682,6 +682,15 @@ class Hook(unittest.TestCase):
git(self.repo, "branch", "-m", "renamed")
self.assertIn("\timage-pin\t", self.listed(), "the reflog keeps the amended commit")
def test_a_folder_named_like_the_branch_doesn_t_hide_the_overrides(self):
os.mkdir(f"{self.repo}/chunk")
pathlib.Path(self.repo, "chunk", "notes.md").write_text("x\n", encoding="utf-8")
git(self.repo, "add", "chunk")
git(self.repo, "commit", "-q", "-m", "a folder named like the branch")
content = "# rule-override image-pin: the vendor tags no patch versions\nFROM vendor/tool:2\n"
hook({"cwd": self.repo, "tool_input": {"file_path": f"{self.repo}/Dockerfile", "content": content}, "tool_name": "Write"}, self.repo)
self.assertIn("\timage-pin\t", self.listed())
def test_an_unreadable_reflog_fails_the_listing(self):
unborn = tempfile.mkdtemp()
self.addCleanup(subprocess.run, ["rm", "-rf", unborn])