@@ -370,23 +370,33 @@ def _set_alternates(self, alts):
370370 alternates = property (_get_alternates , _set_alternates , doc = "Retrieve a list of alternates paths or set a list paths to be used as alternates" )
371371
372372 @property
373- def is_dirty (self ):
373+ def is_dirty (self , index = True , working_tree = True , untracked_files = False ):
374374 """
375- Return the status of the index.
376-
377375 Returns
378- ``True``, if the index has any uncommitted changes,
379- otherwise ``False``
380-
381- NOTE
382- Working tree changes that have not been staged will not be detected !
376+ ``True``, the repository is considered dirty. By default it will react
377+ like a git-status without untracked files, hence it is dirty if the
378+ index or the working copy have changes.
383379 """
384380 if self .bare :
385381 # Bare repositories with no associated working directory are
386382 # always consired to be clean.
387383 return False
388-
389- return len (self .git .diff ('HEAD' , '--' ).strip ()) > 0
384+
385+ # start from the one which is fastest to evaluate
386+ default_args = ('--abbrev=40' , '--full-index' , '--raw' )
387+ if index :
388+ if len (self .git .diff ('HEAD' , '--cached' , * default_args )):
389+ return True
390+ # END index handling
391+ if working_tree :
392+ if len (self .git .diff ('HEAD' , * default_args )):
393+ return True
394+ # END working tree handling
395+ if untracked_files :
396+ if len (self .untracked_files ):
397+ return True
398+ # END untracked files
399+ return False
390400
391401 @property
392402 def untracked_files (self ):
0 commit comments