@@ -1135,6 +1135,48 @@ def test_run_commit_hook_respects_relative_core_hookspath(self, rw_repo):
11351135 output = output_file .read_text (encoding = "utf-8" )
11361136 self .assertEqual (output , "ran from relative hooks path\n " )
11371137
1138+ @pytest .mark .xfail (
1139+ type (_win_bash_status ) is WinBashStatus .Absent ,
1140+ reason = "Can't run a hook on Windows without bash.exe." ,
1141+ raises = HookExecutionError ,
1142+ )
1143+ @pytest .mark .xfail (
1144+ type (_win_bash_status ) is WinBashStatus .WslNoDistro ,
1145+ reason = "Currently uses the bash.exe of WSL, even with no WSL distro installed" ,
1146+ raises = HookExecutionError ,
1147+ )
1148+ @with_rw_repo ("HEAD" , bare = True )
1149+ def test_run_commit_hook_respects_core_hookspath_bare_repo (self , rw_repo ):
1150+ """Test that run_commit_hook() respects core.hooksPath in bare repositories.
1151+
1152+ For bare repos, relative paths should be resolved relative to git_dir since
1153+ there is no working tree.
1154+ """
1155+ index = rw_repo .index
1156+
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"
1160+ custom_hooks_dir .mkdir (exist_ok = True )
1161+
1162+ # Create a hook in the custom location
1163+ custom_hook = custom_hooks_dir / "fake-hook"
1164+ custom_hook .write_text (HOOKS_SHEBANG + "echo 'ran from custom hooks path in bare repo' >output.txt" )
1165+ custom_hook .chmod (0o744 )
1166+
1167+ # Set core.hooksPath in the repo config (absolute path)
1168+ with rw_repo .config_writer () as config :
1169+ config .set_value ("core" , "hooksPath" , str (custom_hooks_dir ))
1170+
1171+ # Run the hook - it should use the custom path
1172+ run_commit_hook ("fake-hook" , index )
1173+
1174+ # Output goes to cwd, which for bare repos during hook execution is git_dir
1175+ output_file = Path (rw_repo .git_dir ) / "output.txt"
1176+ self .assertTrue (output_file .exists (), "Hook should have created output.txt" )
1177+ output = output_file .read_text (encoding = "utf-8" )
1178+ self .assertEqual (output , "ran from custom hooks path in bare repo\n " )
1179+
11381180 @ddt .data ((False ,), (True ,))
11391181 @with_rw_directory
11401182 def test_hook_uses_shell_not_from_cwd (self , rw_dir , case ):
0 commit comments