From e64957d8e52d7542310535bad1e77a9bbd7b4857 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 00:04:10 +0200 Subject: Improved is_dirty including test --- lib/git/repo.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'lib/git/repo.py') diff --git a/lib/git/repo.py b/lib/git/repo.py index 0f4be1b1..8126bff4 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -370,23 +370,33 @@ class Repo(object): alternates = property(_get_alternates, _set_alternates, doc="Retrieve a list of alternates paths or set a list paths to be used as alternates") @property - def is_dirty(self): + def is_dirty(self, index=True, working_tree=True, untracked_files=False): """ - Return the status of the index. - Returns - ``True``, if the index has any uncommitted changes, - otherwise ``False`` - - NOTE - Working tree changes that have not been staged will not be detected ! + ``True``, the repository is considered dirty. By default it will react + like a git-status without untracked files, hence it is dirty if the + index or the working copy have changes. """ if self.bare: # Bare repositories with no associated working directory are # always consired to be clean. return False - - return len(self.git.diff('HEAD', '--').strip()) > 0 + + # start from the one which is fastest to evaluate + default_args = ('--abbrev=40', '--full-index', '--raw') + if index: + if len(self.git.diff('HEAD', '--cached', *default_args)): + return True + # END index handling + if working_tree: + if len(self.git.diff('HEAD', *default_args)): + return True + # END working tree handling + if untracked_files: + if len(self.untracked_files): + return True + # END untracked files + return False @property def untracked_files(self): -- cgit v1.2.1