From 8858e058b0c1563058f5b171643d14bd38cd321c Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Sat, 19 Sep 2020 21:35:04 -0400 Subject: [PATCH] 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 86479607..5bbd07a7 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -26,6 +26,7 @@ from pre_commit.error_handler import error_handler 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)