|
7 | 7 |
|
8 | 8 | from io import BytesIO
|
9 | 9 | import os
|
| 10 | +import os.path as osp |
| 11 | +from pathlib import Path |
10 | 12 | from stat import S_ISLNK, ST_MODE
|
| 13 | +import shutil |
11 | 14 | import tempfile
|
12 | 15 | from unittest import skipIf
|
13 |
| -import shutil |
| 16 | + |
| 17 | +import pytest |
14 | 18 |
|
15 | 19 | from git import (
|
16 | 20 | IndexFile,
|
|
23 | 27 | GitCommandError,
|
24 | 28 | CheckoutError,
|
25 | 29 | )
|
| 30 | +from git.cmd import Git |
26 | 31 | from git.compat import is_win
|
27 | 32 | from git.exc import HookExecutionError, InvalidGitRepositoryError
|
28 | 33 | from git.index.fun import hook_path
|
|
34 | 39 | from git.util import HIDE_WINDOWS_KNOWN_ERRORS, hex_to_bin
|
35 | 40 | from gitdb.base import IStream
|
36 | 41 |
|
37 |
| -import os.path as osp |
38 |
| -from git.cmd import Git |
| 42 | +HOOKS_SHEBANG = "#!/usr/bin/env sh\n" |
39 | 43 |
|
40 |
| -from pathlib import Path |
41 | 44 |
|
42 |
| -HOOKS_SHEBANG = "#!/usr/bin/env sh\n" |
| 45 | +def _found_in(cmd, directory): |
| 46 | + """Check if a command is resolved in a directory (without following symlinks).""" |
| 47 | + path = shutil.which(cmd) |
| 48 | + return path and Path(path).parent == Path(directory) |
| 49 | + |
43 | 50 |
|
44 | 51 | is_win_without_bash = is_win and not shutil.which("bash.exe")
|
45 | 52 |
|
| 53 | +is_win_with_wsl_bash = is_win and _found_in( |
| 54 | + cmd="bash.exe", |
| 55 | + directory=Path(os.getenv("WINDIR")) / "System32", |
| 56 | +) |
| 57 | + |
46 | 58 |
|
47 | 59 | def _make_hook(git_dir, name, content, make_exec=True):
|
48 | 60 | """A helper to create a hook"""
|
@@ -910,7 +922,11 @@ def test_pre_commit_hook_fail(self, rw_repo):
|
910 | 922 | else:
|
911 | 923 | raise AssertionError("Should have caught a HookExecutionError")
|
912 | 924 |
|
913 |
| - @skipIf(HIDE_WINDOWS_KNOWN_ERRORS, "TODO: fix hooks execution on Windows: #703") |
| 925 | + @pytest.mark.xfail( |
| 926 | + is_win_without_bash or is_win_with_wsl_bash, |
| 927 | + reason="Specifically seems to fail on WSL bash (in spite of #1399)", |
| 928 | + raises=AssertionError, |
| 929 | + ) |
914 | 930 | @with_rw_repo("HEAD", bare=True)
|
915 | 931 | def test_commit_msg_hook_success(self, rw_repo):
|
916 | 932 | commit_message = "commit default head by Frèderic Çaufl€"
|
|
0 commit comments