|
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 |
11 | | -import tempfile |
12 | | -from unittest import skipIf |
13 | 13 | import shutil |
| 14 | +import tempfile |
| 15 | + |
| 16 | +import pytest |
14 | 17 |
|
15 | 18 | from git import ( |
16 | 19 | IndexFile, |
|
28 | 31 | from git.index.fun import hook_path |
29 | 32 | from git.index.typ import BaseIndexEntry, IndexEntry |
30 | 33 | from git.objects import Blob |
31 | | -from test.lib import TestBase, fixture_path, fixture, with_rw_repo |
32 | | -from test.lib import with_rw_directory |
33 | | -from git.util import Actor, rmtree |
34 | | -from git.util import HIDE_WINDOWS_KNOWN_ERRORS, hex_to_bin |
| 34 | +from test.lib import TestBase, fixture, fixture_path, with_rw_directory, with_rw_repo |
| 35 | +from git.util import Actor, hex_to_bin, rmtree |
35 | 36 | from gitdb.base import IStream |
36 | 37 |
|
37 | | -import os.path as osp |
38 | | -from git.cmd import Git |
| 38 | +HOOKS_SHEBANG = "#!/usr/bin/env sh\n" |
39 | 39 |
|
40 | | -from pathlib import Path |
41 | 40 |
|
42 | | -HOOKS_SHEBANG = "#!/usr/bin/env sh\n" |
| 41 | +def _found_in(cmd, directory): |
| 42 | + """Check if a command is resolved in a directory (without following symlinks).""" |
| 43 | + path = shutil.which(cmd) |
| 44 | + return path and Path(path).parent == Path(directory) |
| 45 | + |
43 | 46 |
|
44 | 47 | is_win_without_bash = is_win and not shutil.which("bash.exe") |
45 | 48 |
|
| 49 | +is_win_with_wsl_bash = is_win and _found_in( |
| 50 | + cmd="bash.exe", |
| 51 | + directory=Path(os.getenv("WINDIR")) / "System32", |
| 52 | +) |
| 53 | + |
46 | 54 |
|
47 | 55 | def _make_hook(git_dir, name, content, make_exec=True): |
48 | 56 | """A helper to create a hook""" |
@@ -422,14 +430,6 @@ def _count_existing(self, repo, files): |
422 | 430 |
|
423 | 431 | # END num existing helper |
424 | 432 |
|
425 | | - @skipIf( |
426 | | - HIDE_WINDOWS_KNOWN_ERRORS and Git.is_cygwin(), |
427 | | - """FIXME: File "C:\\projects\\gitpython\\git\\test\\test_index.py", line 642, in test_index_mutation |
428 | | - self.assertEqual(fd.read(), link_target) |
429 | | - AssertionError: '!<symlink>\xff\xfe/\x00e\x00t\x00c\x00/\x00t\x00h\x00a\x00t\x00\x00\x00' |
430 | | - != '/etc/that' |
431 | | - """, |
432 | | - ) |
433 | 433 | @with_rw_repo("0.1.6") |
434 | 434 | def test_index_mutation(self, rw_repo): |
435 | 435 | index = rw_repo.index |
@@ -910,7 +910,11 @@ def test_pre_commit_hook_fail(self, rw_repo): |
910 | 910 | else: |
911 | 911 | raise AssertionError("Should have caught a HookExecutionError") |
912 | 912 |
|
913 | | - @skipIf(HIDE_WINDOWS_KNOWN_ERRORS, "TODO: fix hooks execution on Windows: #703") |
| 913 | + @pytest.mark.xfail( |
| 914 | + is_win_without_bash or is_win_with_wsl_bash, |
| 915 | + reason="Specifically seems to fail on WSL bash (in spite of #1399)", |
| 916 | + raises=AssertionError, |
| 917 | + ) |
914 | 918 | @with_rw_repo("HEAD", bare=True) |
915 | 919 | def test_commit_msg_hook_success(self, rw_repo): |
916 | 920 | commit_message = "commit default head by Frèderic Çaufl€" |
|
0 commit comments