From 125b4875b5035dc4f6bad4351651a4236b82baeb Mon Sep 17 00:00:00 2001 From: Kai Lautaportti Date: Fri, 12 Sep 2008 22:03:56 +0300 Subject: Added a read-only property Repo.is_dirty which reflects the status of the working directory. A working directory is dirty if it has any uncommitted changes (in the working directory or in the index). Bare repositories are by nature always clean. --- lib/git/repo.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/git/repo.py') diff --git a/lib/git/repo.py b/lib/git/repo.py index 0e52fab7..ef440cd1 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -441,5 +441,21 @@ class Repo(object): alternates = property(_get_alternates, _set_alternates) + @property + def is_dirty(self): + """Returns 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 + def __repr__(self): return '' % self.path -- cgit v1.2.1 From d7781e1056c672d5212f1aaf4b81ba6f18e8dd8b Mon Sep 17 00:00:00 2001 From: Kai Lautaportti Date: Fri, 12 Sep 2008 22:44:31 +0300 Subject: Cosmetic fixes to be consistent with the overall coding style. --- lib/git/repo.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/git/repo.py') diff --git a/lib/git/repo.py b/lib/git/repo.py index ef440cd1..aaa7cecc 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -443,18 +443,19 @@ class Repo(object): @property def is_dirty(self): - """Returns the status of the working directory. - + """ + 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 def __repr__(self): -- cgit v1.2.1 From fa8fe4cad336a7bdd8fb315b1ce445669138830c Mon Sep 17 00:00:00 2001 From: Kai Lautaportti Date: Fri, 12 Sep 2008 22:45:43 +0300 Subject: Added a read-only Repo.active_branch property which returns the name of the currently active branch. --- lib/git/repo.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/git/repo.py') diff --git a/lib/git/repo.py b/lib/git/repo.py index aaa7cecc..55f73f66 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -458,5 +458,19 @@ class Repo(object): 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 '' % self.path -- cgit v1.2.1