Skip to content

Commit af93bec

Browse files
committed
Fix regression: try-repo from relative path
1 parent fbebd84 commit af93bec

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pre_commit/store.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ def clone(self, repo, ref, deps=()):
143143
def clone_strategy(directory):
144144
env = no_git_env()
145145

146+
cmd = ('git', 'clone', '--no-checkout', repo, directory)
147+
cmd_output(*cmd, env=env)
148+
146149
def _git_cmd(*args):
147150
return cmd_output('git', *args, cwd=directory, env=env)
148151

149-
_git_cmd('clone', '--no-checkout', repo, '.')
150152
_git_cmd('reset', ref, '--hard')
151153
_git_cmd('submodule', 'update', '--init', '--recursive')
152154

tests/commands/try_repo_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22
from __future__ import unicode_literals
33

4+
import os.path
45
import re
56

67
from pre_commit.commands.try_repo import try_repo
@@ -69,3 +70,13 @@ def test_try_repo_with_specific_hook(cap_out, tempdir_factory):
6970
config,
7071
)
7172
assert rest == '[bash_hook] Bash hook................................(no files to check)Skipped\n' # noqa
73+
74+
75+
def test_try_repo_relative_path(cap_out, tempdir_factory):
76+
repo = make_repo(tempdir_factory, 'modified_file_returns_zero_repo')
77+
with cwd(git_dir(tempdir_factory)):
78+
open('test-file', 'a').close()
79+
cmd_output('git', 'add', '.')
80+
relative_repo = os.path.relpath(repo, '.')
81+
# previously crashed on cloning a relative path
82+
assert not try_repo(try_repo_opts(relative_repo, hook='bash_hook'))

0 commit comments

Comments
 (0)