Skip to content

Commit 624eb28

Browse files
apatardByron
authored andcommitted
git/repo/base.py: is_dirty(): Fix pathspec handling
It's possible to specify a pathspec (eg :!foo) to git diff/status/... but it currently fails with: git.exc.GitCommandError: Cmd('/usr/bin/git') failed due to: exit code(128) cmdline: /usr/bin/git diff --abbrev=40 --full-index --raw :!foo stderr: 'fatal: ambiguous argument ':!foo': unknown revision or path not in the working tree. Add missing '--' to the arguments to fix this ambiguity Signed-off-by: Arnaud Patard <[email protected]>
1 parent 135e775 commit 624eb28

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

git/repo/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def is_dirty(self, index=True, working_tree=True, untracked_files=False,
639639
if not submodules:
640640
default_args.append('--ignore-submodules')
641641
if path:
642-
default_args.append(path)
642+
default_args.extend(["--", path])
643643
if index:
644644
# diff index against HEAD
645645
if osp.isfile(self.index.path) and \

test/test_repo.py

+14
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,20 @@ def test_is_dirty(self):
357357
assert self.rorepo.is_dirty() is False
358358
self.rorepo._bare = orig_val
359359

360+
def test_is_dirty_pathspec(self):
361+
self.rorepo._bare = False
362+
for index in (0, 1):
363+
for working_tree in (0, 1):
364+
for untracked_files in (0, 1):
365+
assert self.rorepo.is_dirty(index, working_tree, untracked_files, path=':!foo') in (True, False)
366+
# END untracked files
367+
# END working tree
368+
# END index
369+
orig_val = self.rorepo._bare
370+
self.rorepo._bare = True
371+
assert self.rorepo.is_dirty() is False
372+
self.rorepo._bare = orig_val
373+
360374
@with_rw_repo('HEAD')
361375
def test_is_dirty_with_path(self, rwrepo):
362376
assert rwrepo.is_dirty(path="git") is False

0 commit comments

Comments
 (0)