Skip to content

Commit 6e58a69

Browse files
Fix bare repo test: use custom-hooks dir inside git_dir
Place hooks inside git_dir to avoid path resolution issues on Windows where absolute paths outside the repo directory fail the relative_to check.
1 parent 7b1acdb commit 6e58a69

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

test/test_index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,9 @@ def test_run_commit_hook_respects_core_hookspath_bare_repo(self, rw_repo):
11541154
"""
11551155
index = rw_repo.index
11561156

1157-
# Create a custom hooks directory (use absolute path for bare repo)
1158-
# Use a unique name based on the repo to avoid conflicts
1159-
custom_hooks_dir = Path(rw_repo.git_dir).parent / "bare-custom-hooks"
1157+
# Create a custom hooks directory inside the git_dir for bare repo
1158+
# This ensures the path is relative to working_dir (which equals git_dir for bare repos)
1159+
custom_hooks_dir = Path(rw_repo.git_dir) / "custom-hooks"
11601160
custom_hooks_dir.mkdir(exist_ok=True)
11611161

11621162
# Create a hook in the custom location
@@ -1171,7 +1171,7 @@ def test_run_commit_hook_respects_core_hookspath_bare_repo(self, rw_repo):
11711171
# Run the hook - it should use the custom path
11721172
run_commit_hook("fake-hook", index)
11731173

1174-
# Output goes to cwd, which for bare repos during hook execution is git_dir
1174+
# Output goes to cwd, which for bare repos during hook execution is working_dir (same as git_dir)
11751175
output_file = Path(rw_repo.git_dir) / "output.txt"
11761176
self.assertTrue(output_file.exists(), "Hook should have created output.txt")
11771177
output = output_file.read_text(encoding="utf-8")

0 commit comments

Comments
 (0)