| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3131d1a commit 125b487
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -441,5 +441,21 @@ def _set_alternates(self, alts): | |||
| 441 | 441 | ||
| 442 | 442 | alternates = property(_get_alternates, _set_alternates) | |
| 443 | 443 | ||
| 444 | + @property | ||
| 445 | + def is_dirty(self): | ||
| 446 | + """Returns the status of the working directory. | ||
| 447 | + | ||
| 448 | + Returns | ||
| 449 | + ``True``, if the working directory has any uncommitted changes, | ||
| 450 | + otherwise ``False`` | ||
| 451 | + | ||
| 452 | + """ | ||
| 453 | + if self.bare: | ||
| 454 | + # Bare repositories with no associated working directory are | ||
| 455 | + # always consired to be clean. | ||
| 456 | + return False | ||
| 457 | + | ||
| 458 | + return len(self.git.diff('HEAD').strip()) > 0 | ||
| 459 | + | ||
| 444 | 460 | def __repr__(self): | |
| 445 | 461 | return '<GitPython.Repo "%s">' % self.path | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -296,3 +296,21 @@ def test_log_with_path_and_options(self, git): | |||
| 296 | 296 | # # Commit.expects(:find_all).with(other_repo, ref, :max_count => 1).returns([stub()]) | |
| 297 | 297 | # delta_commits = self.repo.commit_deltas_from(other_repo) | |
| 298 | 298 | # assert_equal(3, len(delta_commits)) | |
| 299 | + | ||
| 300 | + def test_is_dirty_with_bare_repository(self): | ||
| 301 | + self.repo.bare = True | ||
| 302 | + assert_false(self.repo.is_dirty) | ||
| 303 | + | ||
| 304 | + @patch(Git, '_call_process') | ||
| 305 | + def test_is_dirty_with_clean_working_dir(self, git): | ||
| 306 | + self.repo.bare = False | ||
| 307 | + git.return_value = '' | ||
| 308 | + assert_false(self.repo.is_dirty) | ||
| 309 | + assert_equal(git.call_args, (('diff', 'HEAD'), {})) | ||
| 310 | + | ||
| 311 | + @patch(Git, '_call_process') | ||
| 312 | + def test_is_dirty_with_dirty_working_dir(self, git): | ||
| 313 | + self.repo.bare = False | ||
| 314 | + git.return_value = '''-aaa\n+bbb''' | ||
| 315 | + assert_true(self.repo.is_dirty) | ||
| 316 | + assert_equal(git.call_args, (('diff', 'HEAD'), {})) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments