From 6a11b801efbe061cbf9223b5687593503a82762d Mon Sep 17 00:00:00 2001 From: SitiSchu Date: Thu, 29 Sep 2022 00:36:01 +0200 Subject: [PATCH] Add error handling for relpath ValueError, fixes #2530 --- pre_commit/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pre_commit/main.py b/pre_commit/main.py index 3915993f..4ecee41b 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -165,7 +165,14 @@ def _adjust_args_and_chdir(args: argparse.Namespace) -> None: toplevel = git.get_root() os.chdir(toplevel) - args.config = os.path.relpath(args.config) + try: + args.config = os.path.relpath(args.config) + # https://github.com/pre-commit/pre-commit/issues/2530 + # os.relpath will fail with a ValueError if the two directories are on + # two different drives on Windows and since the path is made relative + # for display purposes only we can ignore the error + except ValueError: + pass if args.command in {'run', 'try-repo'}: args.files = [os.path.relpath(filename) for filename in args.files] if args.commit_msg_filename is not None: