Skip to content

Commit 4aa4382

Browse files
committed
Add error handling for relpath ValueError, fixes #2530
1 parent 653d155 commit 4aa4382

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pre_commit/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,14 @@ def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
165165
toplevel = git.get_root()
166166
os.chdir(toplevel)
167167

168-
args.config = os.path.relpath(args.config)
168+
try:
169+
args.config = os.path.relpath(args.config)
170+
# https://github.com/pre-commit/pre-commit/issues/2530
171+
# os.relpath will fail with a ValueError if the two directories are on
172+
# two different drives on Windows and since the path is made relative
173+
# for display purposes only we can ignore the error
174+
except ValueError:
175+
pass
169176
if args.command in {'run', 'try-repo'}:
170177
args.files = [os.path.relpath(filename) for filename in args.files]
171178
if args.commit_msg_filename is not None:

0 commit comments

Comments
 (0)