Skip to content

Commit 2500767

Browse files
authored
Merge pull request #1259 from pre-commit/try_repo_bare
Allow try-repo to work on bare repositories
2 parents 3a72fb3 + 968b2fd commit 2500767

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pre_commit/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def has_diff(*args, **kwargs):
141141
repo = kwargs.pop('repo', '.')
142142
assert not kwargs, kwargs
143143
cmd = ('git', 'diff', '--quiet', '--no-ext-diff') + args
144-
return cmd_output_b(*cmd, cwd=repo, retcode=None)[0]
144+
return cmd_output_b(*cmd, cwd=repo, retcode=None)[0] == 1
145145

146146

147147
def has_core_hookpaths_set():

tests/commands/try_repo_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ def test_try_repo_relative_path(cap_out, tempdir_factory):
9898
assert not try_repo(try_repo_opts(relative_repo, hook='bash_hook'))
9999

100100

101+
def test_try_repo_bare_repo(cap_out, tempdir_factory):
102+
repo = make_repo(tempdir_factory, 'modified_file_returns_zero_repo')
103+
with cwd(git_dir(tempdir_factory)):
104+
_add_test_file()
105+
bare_repo = os.path.join(repo, '.git')
106+
# previously crashed attempting modification changes
107+
assert not try_repo(try_repo_opts(bare_repo, hook='bash_hook'))
108+
109+
101110
def test_try_repo_specific_revision(cap_out, tempdir_factory):
102111
repo = make_repo(tempdir_factory, 'script_hooks_repo')
103112
ref = git.head_rev(repo)

0 commit comments

Comments
 (0)