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

Allow submodules to be ignored in is_dirty #294

Merged
merged 1 commit into from
Jun 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ def _set_alternates(self, alts):
alternates = property(_get_alternates, _set_alternates,
doc="Retrieve a list of alternates paths or set a list paths to be used as alternates")

def is_dirty(self, index=True, working_tree=True, untracked_files=False):
def is_dirty(self, index=True, working_tree=True, untracked_files=False,
consider_submodules=True):
"""
:return:
``True``, the repository is considered dirty. By default it will react
Expand All @@ -575,7 +576,9 @@ def is_dirty(self, index=True, working_tree=True, untracked_files=False):
return False

# start from the one which is fastest to evaluate
default_args = ('--abbrev=40', '--full-index', '--raw')
default_args = ['--abbrev=40', '--full-index', '--raw']
if not consider_submodules:
default_args.append('--ignore-submodules')
if index:
# diff index against HEAD
if isfile(self.index.path) and \
Expand All @@ -588,7 +591,10 @@ def is_dirty(self, index=True, working_tree=True, untracked_files=False):
return True
# END working tree handling
if untracked_files:
if len(self.untracked_files):
kwargs = {}
if not consider_submodules:
kwargs['ignore_submodules'] = True
if len(self._get_untracked_files(**kwargs)):
return True
# END untracked files
return False
Expand All @@ -604,10 +610,14 @@ def untracked_files(self):

:note:
ignored files will not appear here, i.e. files mentioned in .gitignore"""
return self._get_untracked_files()

def _get_untracked_files(self, **kwargs):
# make sure we get all files, no only untracked directores
proc = self.git.status(porcelain=True,
untracked_files=True,
as_process=True)
as_process=True,
**kwargs)
# Untracked files preffix in porcelain mode
prefix = "?? "
untracked_files = list()
Expand Down