summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Trier <mtrier@gmail.com>2008-09-14 10:48:55 -0400
committerMichael Trier <mtrier@gmail.com>2008-09-14 10:48:55 -0400
commit0ec61d4f7208a2713adeafb947f65fdae0947067 (patch)
tree4b93d00ddd8b41b61977fa767dd7d1627915c763
parenteb8cec3cab142ef4f2773b6fc9d224461a6bf85d (diff)
parentfa8fe4cad336a7bdd8fb315b1ce445669138830c (diff)
downloadgitpython-0ec61d4f7208a2713adeafb947f65fdae0947067.tar.gz
Merge branch 'master' of git://gitorious.org/git-python/dokais-clone
-rw-r--r--lib/git/repo.py31
-rw-r--r--test/git/test_repo.py24
2 files changed, 55 insertions, 0 deletions
diff --git a/lib/git/repo.py b/lib/git/repo.py
index aff595f1..fdfb7928 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -435,5 +435,36 @@ class Repo(object):
alternates = property(_get_alternates, _set_alternates)
+ @property
+ def is_dirty(self):
+ """
+ Return the status of the working directory.
+
+ Returns
+ ``True``, if the working directory has any uncommitted changes,
+ otherwise ``False``
+
+ """
+ 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
+
+ @property
+ def active_branch(self):
+ """
+ The name of the currently active branch.
+
+ Returns
+ str (the branch name)
+ """
+ branch = self.git.symbolic_ref('HEAD').strip()
+ if branch.startswith('refs/heads/'):
+ branch = branch[len('refs/heads/'):]
+
+ return branch
+
def __repr__(self):
return '<GitPython.Repo "%s">' % self.path
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 29ba463b..989dd4fe 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -300,3 +300,27 @@ class TestRepo(object):
# # Commit.expects(:find_all).with(other_repo, ref, :max_count => 1).returns([stub()])
# delta_commits = self.repo.commit_deltas_from(other_repo)
# assert_equal(3, len(delta_commits))
+
+ def test_is_dirty_with_bare_repository(self):
+ self.repo.bare = True
+ assert_false(self.repo.is_dirty)
+
+ @patch(Git, '_call_process')
+ def test_is_dirty_with_clean_working_dir(self, git):
+ self.repo.bare = False
+ git.return_value = ''
+ assert_false(self.repo.is_dirty)
+ assert_equal(git.call_args, (('diff', 'HEAD'), {}))
+
+ @patch(Git, '_call_process')
+ def test_is_dirty_with_dirty_working_dir(self, git):
+ self.repo.bare = False
+ git.return_value = '''-aaa\n+bbb'''
+ assert_true(self.repo.is_dirty)
+ assert_equal(git.call_args, (('diff', 'HEAD'), {}))
+
+ @patch(Git, '_call_process')
+ def test_active_branch(self, git):
+ git.return_value = 'refs/heads/major-refactoring'
+ assert_equal(self.repo.active_branch, 'major-refactoring')
+ assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {}))