diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-20 00:04:10 +0200 | 
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-20 00:04:10 +0200 | 
| commit | e64957d8e52d7542310535bad1e77a9bbd7b4857 (patch) | |
| tree | 2bb93792907aa5119b2c9c8d665388f744c3e663 /lib/git/repo.py | |
| parent | 989671780551b7587d57e1d7cb5eb1002ade75b4 (diff) | |
| download | gitpython-e64957d8e52d7542310535bad1e77a9bbd7b4857.tar.gz | |
Improved is_dirty including test
Diffstat (limited to 'lib/git/repo.py')
| -rw-r--r-- | lib/git/repo.py | 30 | 
1 files changed, 20 insertions, 10 deletions
| 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): | 
