Skip to content

Commit 0ec61d4

Browse files
committed
Merge branch 'master' of git://gitorious.org/git-python/dokais-clone
2 parents eb8cec3 + fa8fe4c commit 0ec61d4

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

‎lib/git/repo.py

+31
Original file line numberDiff line numberDiff line change
@@ -435,5 +435,36 @@ def _set_alternates(self, alts):
435435

436436
alternates = property(_get_alternates, _set_alternates)
437437

438+
@property
439+
def is_dirty(self):
440+
"""
441+
Return the status of the working directory.
442+
443+
Returns
444+
``True``, if the working directory has any uncommitted changes,
445+
otherwise ``False``
446+
447+
"""
448+
if self.bare:
449+
# Bare repositories with no associated working directory are
450+
# always consired to be clean.
451+
return False
452+
453+
return len(self.git.diff('HEAD').strip()) > 0
454+
455+
@property
456+
def active_branch(self):
457+
"""
458+
The name of the currently active branch.
459+
460+
Returns
461+
str (the branch name)
462+
"""
463+
branch = self.git.symbolic_ref('HEAD').strip()
464+
if branch.startswith('refs/heads/'):
465+
branch = branch[len('refs/heads/'):]
466+
467+
return branch
468+
438469
def __repr__(self):
439470
return '<GitPython.Repo "%s">' % self.path

‎test/git/test_repo.py

+24
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,27 @@ def test_log_with_path_and_options(self, git):
300300
# # Commit.expects(:find_all).with(other_repo, ref, :max_count => 1).returns([stub()])
301301
# delta_commits = self.repo.commit_deltas_from(other_repo)
302302
# assert_equal(3, len(delta_commits))
303+
304+
def test_is_dirty_with_bare_repository(self):
305+
self.repo.bare = True
306+
assert_false(self.repo.is_dirty)
307+
308+
@patch(Git, '_call_process')
309+
def test_is_dirty_with_clean_working_dir(self, git):
310+
self.repo.bare = False
311+
git.return_value = ''
312+
assert_false(self.repo.is_dirty)
313+
assert_equal(git.call_args, (('diff', 'HEAD'), {}))
314+
315+
@patch(Git, '_call_process')
316+
def test_is_dirty_with_dirty_working_dir(self, git):
317+
self.repo.bare = False
318+
git.return_value = '''-aaa\n+bbb'''
319+
assert_true(self.repo.is_dirty)
320+
assert_equal(git.call_args, (('diff', 'HEAD'), {}))
321+
322+
@patch(Git, '_call_process')
323+
def test_active_branch(self, git):
324+
git.return_value = 'refs/heads/major-refactoring'
325+
assert_equal(self.repo.active_branch, 'major-refactoring')
326+
assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {}))

0 commit comments

Comments
 (0)