Fix WinError wrong toplevel path returned in msys2

This commit is contained in:
Dan Yeaw 2020-09-19 21:35:04 -04:00
parent 3e2b9dc91a
commit 8858e058b0

View file

@ -26,6 +26,7 @@ from pre_commit.error_handler import error_handler
from pre_commit.error_handler import FatalError from pre_commit.error_handler import FatalError
from pre_commit.logging_handler import logging_handler from pre_commit.logging_handler import logging_handler
from pre_commit.store import Store from pre_commit.store import Store
from pre_commit.util import cmd_output
from pre_commit.util import CalledProcessError 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 ' 'git toplevel unexpectedly empty! make sure you are not '
'inside the `.git` directory of your repository.', '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: else:
os.chdir(toplevel) os.chdir(toplevel)