| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,8 @@ Repo | |||
| 87 | 87 | of the active branch. | |
| 88 | 88 | * tree method now requires a Ref instance as input and defaults to the active_branche | |
| 89 | 89 | instead of master | |
| 90 | + * is_dirty now takes additional arguments allowing fine-grained control about what is | ||
| 91 | + considered dirty | ||
| 90 | 92 | * Removed the following methods: | |
| 91 | 93 | - 'log' method as it as effectively the same as the 'commits' method | |
| 92 | 94 | - 'commits_since' as it is just a flag given to rev-list in Commit.iter_items | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,8 +32,6 @@ Index | |||
| 32 | 32 | Repo | |
| 33 | 33 | ---- | |
| 34 | 34 | * Nice fetch/pull handling, at least supported/wired throuhg to the git command | |
| 35 | - * is_dirty should be improved to allow options what to diff with: | ||
| 36 | - working tree|index|head - also it should use raw mode to prevent patch generation | ||
| 37 | 35 | * repo.bare is set according to the path it is initialized with, although it | |
| 38 | 36 | should be read from the configuration in fact. Check uses of repo.bare. | |
| 39 | 37 | * Blame: Read the blame format making assumptions about its structure, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -370,23 +370,33 @@ def _set_alternates(self, alts): | |||
| 370 | 370 | alternates = property(_get_alternates, _set_alternates, doc="Retrieve a list of alternates paths or set a list paths to be used as alternates") | |
| 371 | 371 | ||
| 372 | 372 | @property | |
| 373 | - def is_dirty(self): | ||
| 373 | + def is_dirty(self, index=True, working_tree=True, untracked_files=False): | ||
| 374 | 374 | """ | |
| 375 | - Return the status of the index. | ||
| 376 | - | ||
| 377 | 375 | 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. | ||
| 383 | 379 | """ | |
| 384 | 380 | if self.bare: | |
| 385 | 381 | # Bare repositories with no associated working directory are | |
| 386 | 382 | # always consired to be clean. | |
| 387 | 383 | 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 | ||
| 390 | 400 | ||
| 391 | 401 | @property | |
| 392 | 402 | def untracked_files(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,19 +160,17 @@ def test_is_dirty_with_bare_repository(self): | |||
| 160 | 160 | self.repo.bare = True | |
| 161 | 161 | assert_false(self.repo.is_dirty) | |
| 162 | 162 | ||
| 163 | - @patch_object(Git, '_call_process') | ||
| 164 | - def test_is_dirty_with_clean_working_dir(self, git): | ||
| 165 | - self.repo.bare = False | ||
| 166 | - git.return_value = '' | ||
| 167 | - assert_false(self.repo.is_dirty) | ||
| 168 | - assert_equal(git.call_args, (('diff', 'HEAD', '--'), {})) | ||
| 169 | - | ||
| 170 | - @patch_object(Git, '_call_process') | ||
| 171 | - def test_is_dirty_with_dirty_working_dir(self, git): | ||
| 163 | + def test_is_dirty(self): | ||
| 172 | 164 | self.repo.bare = False | |
| 173 | - git.return_value = '''-aaa\n+bbb''' | ||
| 174 | - assert_true(self.repo.is_dirty) | ||
| 175 | - assert_equal(git.call_args, (('diff', 'HEAD', '--'), {})) | ||
| 165 | + for index in (0,1): | ||
| 166 | + for working_tree in (0,1): | ||
| 167 | + for untracked_files in (0,1): | ||
| 168 | + assert self.repo.is_dirty in (True, False) | ||
| 169 | + # END untracked files | ||
| 170 | + # END working tree | ||
| 171 | + # END index | ||
| 172 | + self.repo.bare = True | ||
| 173 | + assert self.repo.is_dirty == False | ||
| 176 | 174 | ||
| 177 | 175 | @patch_object(Git, '_call_process') | |
| 178 | 176 | def test_active_branch(self, git): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments