Skip to content

Commit 881456b

Browse files
committed
Run test_commit_msg_hook_success on more systems
This changes a default Windows skip of test_commit_msg_hook_success to an xfail, and makes it more specific, expecting failure only when either bash.exe is unavailable (definitely expected) or when bash.exe is the WSL bash wrapper in System32, which fails for some reason even though it's not at all clear it ought to. This showcases the failures rather than skipping, and also lets the test pass on Windows systems where bash.exe is something else, including the Git Bash bash.exe that native Windows CI would use.
1 parent d6a2d28 commit 881456b

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Diff for: test/test_index.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77

88
from io import BytesIO
99
import os
10+
import os.path as osp
11+
from pathlib import Path
1012
from stat import S_ISLNK, ST_MODE
13+
import shutil
1114
import tempfile
1215
from unittest import skipIf
13-
import shutil
16+
17+
import pytest
1418

1519
from git import (
1620
IndexFile,
@@ -23,6 +27,7 @@
2327
GitCommandError,
2428
CheckoutError,
2529
)
30+
from git.cmd import Git
2631
from git.compat import is_win
2732
from git.exc import HookExecutionError, InvalidGitRepositoryError
2833
from git.index.fun import hook_path
@@ -34,15 +39,22 @@
3439
from git.util import HIDE_WINDOWS_KNOWN_ERRORS, hex_to_bin
3540
from gitdb.base import IStream
3641

37-
import os.path as osp
38-
from git.cmd import Git
42+
HOOKS_SHEBANG = "#!/usr/bin/env sh\n"
3943

40-
from pathlib import Path
4144

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+
4350

4451
is_win_without_bash = is_win and not shutil.which("bash.exe")
4552

53+
is_win_with_wsl_bash = is_win and _found_in(
54+
cmd="bash.exe",
55+
directory=Path(os.getenv("WINDIR")) / "System32",
56+
)
57+
4658

4759
def _make_hook(git_dir, name, content, make_exec=True):
4860
"""A helper to create a hook"""
@@ -910,7 +922,11 @@ def test_pre_commit_hook_fail(self, rw_repo):
910922
else:
911923
raise AssertionError("Should have caught a HookExecutionError")
912924

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+
)
914930
@with_rw_repo("HEAD", bare=True)
915931
def test_commit_msg_hook_success(self, rw_repo):
916932
commit_message = "commit default head by Frèderic Çaufl€"

0 commit comments

Comments
 (0)