Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MSYS2 Compatibility #1607

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion pre_commit/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def check_for_cygwin_mismatch() -> None:
if sys.platform in ('cygwin', 'win32'): # pragma: no cover (windows)
is_cygwin_python = sys.platform == 'cygwin'
toplevel = cmd_output('git', 'rev-parse', '--show-toplevel')[1]
is_cygwin_git = toplevel.startswith('/')
git_exec_path = cmd_output('git', '--exec-path')[1].strip()
is_msys2_git = git_exec_path == '/usr/lib/git-core'
is_cygwin_git = toplevel.startswith('/') and not is_msys2_git

if is_cygwin_python ^ is_cygwin_git:
exe_type = {True: '(cygwin)', False: '(windows)'}
Expand Down
4 changes: 4 additions & 0 deletions pre_commit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pre_commit.error_handler import FatalError
from pre_commit.logging_handler import logging_handler
from pre_commit.store import Store
from pre_commit.util import cmd_output
from pre_commit.util import CalledProcessError


Expand Down Expand Up @@ -159,6 +160,9 @@ def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
'git toplevel unexpectedly empty! make sure you are not '
'inside the `.git` directory of your repository.',
)
elif os.name == 'nt' and toplevel.startswith('/'):
full_win_path = cmd_output("cygpath", "-w", toplevel)[1].strip()
os.chdir(full_win_path)
else:
os.chdir(toplevel)

Expand Down