Skip to content

Commit

Permalink
Run test_commit_msg_hook_success on more systems
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EliahKagan committed Sep 17, 2023
1 parent 1b319e0 commit b119473
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

from io import BytesIO
import os
import os.path as osp
from pathlib import Path
from stat import S_ISLNK, ST_MODE
import shutil
import tempfile
from unittest import skipIf
import shutil

import pytest

from git import (
IndexFile,
Expand All @@ -23,6 +27,7 @@
GitCommandError,
CheckoutError,
)
from git.cmd import Git
from git.compat import is_win
from git.exc import HookExecutionError, InvalidGitRepositoryError
from git.index.fun import hook_path
Expand All @@ -34,15 +39,22 @@
from git.util import HIDE_WINDOWS_KNOWN_ERRORS, hex_to_bin
from gitdb.base import IStream

import os.path as osp
from git.cmd import Git
HOOKS_SHEBANG = "#!/usr/bin/env sh\n"

from pathlib import Path

HOOKS_SHEBANG = "#!/usr/bin/env sh\n"
def _found_in(cmd, directory):
"""Check if a command is resolved in a directory (without following symlinks)."""
path = shutil.which(cmd)
return path and Path(path).parent == Path(directory)


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

is_win_with_wsl_bash = is_win and _found_in(
cmd="bash.exe",
directory=Path(os.getenv("WINDIR")) / "System32",
)


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

@skipIf(HIDE_WINDOWS_KNOWN_ERRORS, "TODO: fix hooks execution on Windows: #703")
@pytest.mark.xfail(
is_win_without_bash or is_win_with_wsl_bash,
reason="Specifically seems to fail on WSL bash (in spite of #1399)",
raises=AssertionError,
)
@with_rw_repo("HEAD", bare=True)
def test_commit_msg_hook_success(self, rw_repo):
commit_message = "commit default head by Frèderic Çaufl€"
Expand Down Expand Up @@ -946,11 +962,11 @@ def test_commit_msg_hook_fail(self, rw_repo):
else:
raise AssertionError("Should have caught a HookExecutionError")

@with_rw_repo('HEAD')
@with_rw_repo("HEAD")
def test_index_add_pathlike(self, rw_repo):
git_dir = Path(rw_repo.git_dir)

file = git_dir / "file.txt"
file.touch()

rw_repo.index.add(file)
rw_repo.index.add(file)

0 comments on commit b119473

Please sign in to comment.