From 8858e058b0c1563058f5b171643d14bd38cd321c Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Sat, 19 Sep 2020 21:35:04 -0400 Subject: [PATCH 1/2] Fix WinError wrong toplevel path returned in msys2 --- pre_commit/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pre_commit/main.py b/pre_commit/main.py index 86479607c..5bbd07a74 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -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 @@ -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) From 88ccb3e75dc9937dda79bd8e81d368fc23b8bda8 Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Sat, 19 Sep 2020 22:16:19 -0400 Subject: [PATCH 2/2] Remove cygwin git mismatch message in MSYS2 --- pre_commit/git.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pre_commit/git.py b/pre_commit/git.py index 576bef8cc..76abb6fef 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -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)'}