32
32
InvalidGitRepositoryError ,
33
33
UnmergedEntriesError ,
34
34
)
35
- from git .index .fun import hook_path
35
+ from git .index .fun import hook_path , run_commit_hook
36
36
from git .index .typ import BaseIndexEntry , IndexEntry
37
37
from git .index .util import TemporaryFileSwap
38
38
from git .objects import Blob
@@ -992,9 +992,32 @@ class Mocked:
992
992
rel = index ._to_relative_path (path )
993
993
self .assertEqual (rel , os .path .relpath (path , root ))
994
994
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
+ )
995
1000
@pytest .mark .xfail (
996
1001
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" ,
998
1021
raises = HookExecutionError ,
999
1022
)
1000
1023
@with_rw_repo ("HEAD" , bare = True )
@@ -1005,7 +1028,7 @@ def test_pre_commit_hook_success(self, rw_repo):
1005
1028
1006
1029
@pytest .mark .xfail (
1007
1030
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" ,
1009
1032
raises = AssertionError ,
1010
1033
)
1011
1034
@with_rw_repo ("HEAD" , bare = True )
@@ -1031,13 +1054,18 @@ def test_pre_commit_hook_fail(self, rw_repo):
1031
1054
raise AssertionError ("Should have caught a HookExecutionError" )
1032
1055
1033
1056
@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 ,
1035
1063
reason = "Specifically seems to fail on WSL bash (in spite of #1399)" ,
1036
1064
raises = AssertionError ,
1037
1065
)
1038
1066
@pytest .mark .xfail (
1039
1067
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" ,
1041
1069
raises = HookExecutionError ,
1042
1070
)
1043
1071
@with_rw_repo ("HEAD" , bare = True )
@@ -1055,7 +1083,7 @@ def test_commit_msg_hook_success(self, rw_repo):
1055
1083
1056
1084
@pytest .mark .xfail (
1057
1085
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" ,
1059
1087
raises = AssertionError ,
1060
1088
)
1061
1089
@with_rw_repo ("HEAD" , bare = True )
0 commit comments