Skip to content

Commit f9fbe18

Browse files
committed
Fix pre-commit install on subst drives
1 parent 0047fa3 commit f9fbe18

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pre_commit/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def get_root() -> str:
5252
# "rev-parse --show-cdup" to get the appropriate path, but must perform
5353
# an extra check to see if we are in the .git directory.
5454
try:
55-
root = os.path.realpath(
55+
root = os.path.abspath(
5656
cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
5757
)
58-
git_dir = os.path.realpath(get_git_dir())
58+
git_dir = os.path.abspath(get_git_dir())
5959
except CalledProcessError:
6060
raise FatalError(
6161
'git failed. Is it installed, and are you in a Git repository '

tests/main_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import pre_commit.constants as C
88
from pre_commit import main
99
from pre_commit.errors import FatalError
10+
from pre_commit.util import cmd_output
1011
from testing.auto_namedtuple import auto_namedtuple
12+
from testing.util import cwd
1113

1214

1315
@pytest.mark.parametrize(
@@ -54,6 +56,17 @@ def test_adjust_args_and_chdir_relative_things(in_git_dir):
5456
assert args.files == [os.path.join('foo', 'f1'), os.path.join('foo', 'f2')]
5557

5658

59+
@pytest.mark.skipif(os.name != 'nt', reason='windows feature')
60+
def test_install_on_subst(in_git_dir, store): # pragma: posix no cover
61+
assert not os.path.exists('Z:')
62+
cmd_output('subst', 'Z:', str(in_git_dir))
63+
try:
64+
with cwd('Z:'):
65+
test_adjust_args_and_chdir_noop('Z:\\')
66+
finally:
67+
cmd_output('subst', '/d', 'Z:')
68+
69+
5770
def test_adjust_args_and_chdir_non_relative_config(in_git_dir):
5871
in_git_dir.join('foo').ensure_dir().chdir()
5972

0 commit comments

Comments
 (0)