File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -165,14 +165,14 @@ def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
165165 toplevel = git .get_root ()
166166 os .chdir (toplevel )
167167
168+ # https://github.com/pre-commit/pre-commit/issues/2530
169+ # `os.relpath` raises a ValueError on Windows when the paths given are on
170+ # separate drives.
168171 try :
169172 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
174173 except ValueError :
175174 pass
175+
176176 if args .command in {'run' , 'try-repo' }:
177177 args .files = [os .path .relpath (filename ) for filename in args .files ]
178178 if args .commit_msg_filename is not None :
Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ def test_adjust_args_and_chdir_not_in_git_dir(in_tmpdir):
2727 main ._adjust_args_and_chdir (_args ())
2828
2929
30+ def test_adjust_args_and_chdir_relpath_to_different_drive ():
31+ args = _args (command = 'run' , files = ['f1' , 'f2' ])
32+ with mock .patch .object (os .path , 'relpath' , side_effect = ValueError ):
33+ with pytest .raises (ValueError ):
34+ main ._adjust_args_and_chdir (args )
35+
36+
3037def test_adjust_args_and_chdir_noop (in_git_dir ):
3138 args = _args (command = 'run' , files = ['f1' , 'f2' ])
3239 main ._adjust_args_and_chdir (args )
You can’t perform that action at this time.
0 commit comments