Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite866c4a

Browse files
authored
Merge pull request#496 from haizaar/master
is_dirty supports path.Fixes#482.
2 parents83ebc65 +c3c70da commite866c4a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

‎git/repo/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ def _set_alternates(self, alts):
585585
doc="Retrieve a list of alternates paths or set a list paths to be used as alternates")
586586

587587
defis_dirty(self,index=True,working_tree=True,untracked_files=False,
588-
submodules=True):
588+
submodules=True,path=None):
589589
"""
590590
:return:
591591
``True``, the repository is considered dirty. By default it will react
@@ -600,6 +600,8 @@ def is_dirty(self, index=True, working_tree=True, untracked_files=False,
600600
default_args= ['--abbrev=40','--full-index','--raw']
601601
ifnotsubmodules:
602602
default_args.append('--ignore-submodules')
603+
ifpath:
604+
default_args.append(path)
603605
ifindex:
604606
# diff index against HEAD
605607
ifisfile(self.index.path)and \
@@ -612,7 +614,7 @@ def is_dirty(self, index=True, working_tree=True, untracked_files=False,
612614
returnTrue
613615
# END working tree handling
614616
ifuntracked_files:
615-
iflen(self._get_untracked_files(ignore_submodules=notsubmodules)):
617+
iflen(self._get_untracked_files(path,ignore_submodules=notsubmodules)):
616618
returnTrue
617619
# END untracked files
618620
returnFalse
@@ -633,9 +635,10 @@ def untracked_files(self):
633635
consider caching it yourself."""
634636
returnself._get_untracked_files()
635637

636-
def_get_untracked_files(self,**kwargs):
638+
def_get_untracked_files(self,*args,**kwargs):
637639
# make sure we get all files, no only untracked directores
638-
proc=self.git.status(porcelain=True,
640+
proc=self.git.status(*args,
641+
porcelain=True,
639642
untracked_files=True,
640643
as_process=True,
641644
**kwargs)

‎git/test/test_repo.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,24 @@ def test_is_dirty(self):
271271
assertself.rorepo.is_dirty()isFalse
272272
self.rorepo._bare=orig_val
273273

274+
@with_rw_repo('HEAD')
275+
deftest_is_dirty_with_path(self,rwrepo):
276+
assertrwrepo.is_dirty(path="git")isFalse
277+
278+
withopen(os.path.join(rwrepo.working_dir,"git","util.py"),"at")asf:
279+
f.write("junk")
280+
assertrwrepo.is_dirty(path="git")isTrue
281+
assertrwrepo.is_dirty(path="doc")isFalse
282+
283+
rwrepo.git.add(os.path.join("git","util.py"))
284+
assertrwrepo.is_dirty(index=False,path="git")isFalse
285+
assertrwrepo.is_dirty(path="git")isTrue
286+
287+
withopen(os.path.join(rwrepo.working_dir,"doc","no-such-file.txt"),"wt")asf:
288+
f.write("junk")
289+
assertrwrepo.is_dirty(path="doc")isFalse
290+
assertrwrepo.is_dirty(untracked_files=True,path="doc")isTrue
291+
274292
deftest_head(self):
275293
assertself.rorepo.head.reference.object==self.rorepo.active_branch.object
276294

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp