Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre-commit install on subst drives #1814

Merged
merged 1 commit into from Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pre_commit/git.py
Expand Up @@ -52,10 +52,10 @@ def get_root() -> str:
# "rev-parse --show-cdup" to get the appropriate path, but must perform
# an extra check to see if we are in the .git directory.
try:
root = os.path.realpath(
root = os.path.abspath(
cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
)
git_dir = os.path.realpath(get_git_dir())
git_dir = os.path.abspath(get_git_dir())
except CalledProcessError:
raise FatalError(
'git failed. Is it installed, and are you in a Git repository '
Expand Down
13 changes: 13 additions & 0 deletions tests/main_test.py
Expand Up @@ -7,7 +7,9 @@
import pre_commit.constants as C
from pre_commit import main
from pre_commit.errors import FatalError
from pre_commit.util import cmd_output
from testing.auto_namedtuple import auto_namedtuple
from testing.util import cwd


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


@pytest.mark.skipif(os.name != 'nt', reason='windows feature')
def test_install_on_subst(in_git_dir, store): # pragma: posix no cover
assert not os.path.exists('Z:')
cmd_output('subst', 'Z:', str(in_git_dir))
try:
with cwd('Z:'):
test_adjust_args_and_chdir_noop('Z:\\')
finally:
cmd_output('subst', '/d', 'Z:')


def test_adjust_args_and_chdir_non_relative_config(in_git_dir):
in_git_dir.join('foo').ensure_dir().chdir()

Expand Down