File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -165,14 +165,15 @@ def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
165165 toplevel = git .get_root ()
166166 os .chdir (toplevel )
167167
168- try :
169- args .config = os .path .relpath (args .config )
170168 # https://github.com/pre-commit/pre-commit/issues/2530
171169 # os.relpath will fail with a ValueError if the two directories are on
172170 # two different drives on Windows and since the path is made relative
173- # for display purposes only we can ignore the error
171+ # for display purposes only, we can ignore the error
172+ try :
173+ args .config = os .path .relpath (args .config )
174174 except ValueError :
175175 pass
176+
176177 if args .command in {'run' , 'try-repo' }:
177178 args .files = [os .path .relpath (filename ) for filename in args .files ]
178179 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