|
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.objects import Blob
|
38 | 38 | from test.lib import TestBase, fixture, fixture_path, with_rw_directory, with_rw_repo
|
@@ -991,6 +991,24 @@ class Mocked:
|
991 | 991 | rel = index._to_relative_path(path)
|
992 | 992 | self.assertEqual(rel, os.path.relpath(path, root))
|
993 | 993 |
|
| 994 | + @pytest.mark.xfail( |
| 995 | + type(_win_bash_status) is WinBashStatus.Absent, |
| 996 | + reason="Can't run a hook on Windows without bash.exe.", |
| 997 | + rasies=HookExecutionError, |
| 998 | + ) |
| 999 | + @pytest.mark.xfail( |
| 1000 | + type(_win_bash_status) is WinBashStatus.WslNoDistro, |
| 1001 | + reason="Currently uses the bash.exe of WSL, even with no WSL distro installed", |
| 1002 | + raises=HookExecutionError, |
| 1003 | + ) |
| 1004 | + @with_rw_repo("HEAD", bare=True) |
| 1005 | + def test_run_commit_hook(self, rw_repo): |
| 1006 | + index = rw_repo.index |
| 1007 | + _make_hook(index.repo.git_dir, "fake-hook", "echo 'ran fake hook' >output.txt") |
| 1008 | + run_commit_hook("fake-hook", index) |
| 1009 | + output = Path(rw_repo.git_dir, "output.txt").read_text(encoding="utf-8") |
| 1010 | + self.assertEqual(output, "ran fake hook\n") |
| 1011 | + |
994 | 1012 | @pytest.mark.xfail(
|
995 | 1013 | type(_win_bash_status) is WinBashStatus.Absent,
|
996 | 1014 | reason="Can't run a hook on Windows without bash.exe.",
|
|
0 commit comments