3232 InvalidGitRepositoryError ,
3333 UnmergedEntriesError ,
3434)
35- from git .index .fun import hook_path
35+ from git .index .fun import hook_path , run_commit_hook
3636from git .index .typ import BaseIndexEntry , IndexEntry
3737from git .index .util import TemporaryFileSwap
3838from git .objects import Blob
@@ -992,9 +992,32 @@ class Mocked:
992992 rel = index ._to_relative_path (path )
993993 self .assertEqual (rel , os .path .relpath (path , root ))
994994
995+ @pytest .mark .xfail (
996+ type (_win_bash_status ) is WinBashStatus .Absent ,
997+ reason = "Can't run a hook on Windows without bash.exe." ,
998+ rasies = HookExecutionError ,
999+ )
9951000 @pytest .mark .xfail (
9961001 type (_win_bash_status ) is WinBashStatus .WslNoDistro ,
997- reason = "Currently uses the bash.exe for WSL even with no WSL distro installed" ,
1002+ reason = "Currently uses the bash.exe of WSL, even with no WSL distro installed" ,
1003+ raises = HookExecutionError ,
1004+ )
1005+ @with_rw_repo ("HEAD" , bare = True )
1006+ def test_run_commit_hook (self , rw_repo ):
1007+ index = rw_repo .index
1008+ _make_hook (index .repo .git_dir , "fake-hook" , "echo 'ran fake hook' >output.txt" )
1009+ run_commit_hook ("fake-hook" , index )
1010+ output = Path (rw_repo .git_dir , "output.txt" ).read_text (encoding = "utf-8" )
1011+ self .assertEqual (output , "ran fake hook\n " )
1012+
1013+ @pytest .mark .xfail (
1014+ type (_win_bash_status ) is WinBashStatus .Absent ,
1015+ reason = "Can't run a hook on Windows without bash.exe." ,
1016+ rasies = HookExecutionError ,
1017+ )
1018+ @pytest .mark .xfail (
1019+ type (_win_bash_status ) is WinBashStatus .WslNoDistro ,
1020+ reason = "Currently uses the bash.exe of WSL, even with no WSL distro installed" ,
9981021 raises = HookExecutionError ,
9991022 )
10001023 @with_rw_repo ("HEAD" , bare = True )
@@ -1005,7 +1028,7 @@ def test_pre_commit_hook_success(self, rw_repo):
10051028
10061029 @pytest .mark .xfail (
10071030 type (_win_bash_status ) is WinBashStatus .WslNoDistro ,
1008- reason = "Currently uses the bash.exe for WSL even with no WSL distro installed" ,
1031+ reason = "Currently uses the bash.exe of WSL, even with no WSL distro installed" ,
10091032 raises = AssertionError ,
10101033 )
10111034 @with_rw_repo ("HEAD" , bare = True )
@@ -1031,13 +1054,18 @@ def test_pre_commit_hook_fail(self, rw_repo):
10311054 raise AssertionError ("Should have caught a HookExecutionError" )
10321055
10331056 @pytest .mark .xfail (
1034- type (_win_bash_status ) in {WinBashStatus .Absent , WinBashStatus .Wsl },
1057+ type (_win_bash_status ) is WinBashStatus .Absent ,
1058+ reason = "Can't run a hook on Windows without bash.exe." ,
1059+ rasies = HookExecutionError ,
1060+ )
1061+ @pytest .mark .xfail (
1062+ type (_win_bash_status ) is WinBashStatus .Wsl ,
10351063 reason = "Specifically seems to fail on WSL bash (in spite of #1399)" ,
10361064 raises = AssertionError ,
10371065 )
10381066 @pytest .mark .xfail (
10391067 type (_win_bash_status ) is WinBashStatus .WslNoDistro ,
1040- reason = "Currently uses the bash.exe for WSL even with no WSL distro installed" ,
1068+ reason = "Currently uses the bash.exe of WSL, even with no WSL distro installed" ,
10411069 raises = HookExecutionError ,
10421070 )
10431071 @with_rw_repo ("HEAD" , bare = True )
@@ -1055,7 +1083,7 @@ def test_commit_msg_hook_success(self, rw_repo):
10551083
10561084 @pytest .mark .xfail (
10571085 type (_win_bash_status ) is WinBashStatus .WslNoDistro ,
1058- reason = "Currently uses the bash.exe for WSL even with no WSL distro installed" ,
1086+ reason = "Currently uses the bash.exe of WSL, even with no WSL distro installed" ,
10591087 raises = AssertionError ,
10601088 )
10611089 @with_rw_repo ("HEAD" , bare = True )
0 commit comments