summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gbp/git/repository.py26
-rw-r--r--tests/test_GitRepository.py22
2 files changed, 48 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 4d8ad1f0..dd7384f8 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -16,6 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""A Git repository"""
+import os
import re
import subprocess
import os.path
@@ -602,6 +603,31 @@ class GitRepository(object):
break
return (ret, "".join(out))
+ def status(self, pathlist=None):
+ """
+ Check status of repository.
+
+ @param pathlist: List of paths to check status for
+ @type pathlist: C{list}
+ @return C{dict} of C{lists} of paths, where key is a git status flag.
+ @rtype C{dict}
+ """
+
+ options = ['--porcelain']
+ if pathlist:
+ options.extend(pathlist)
+
+ out, err, ret = self._git_inout('status', options,
+ extra_env={'LC_ALL': 'C'})
+ if ret:
+ raise GbpError("Can't get repository status: %s" % err)
+
+ result = defaultdict(list)
+
+ for line in out.splitlines():
+ result[line[:2]].append(line[3:])
+ return result
+
def is_empty(self):
"""
Is the repository empty?
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index 73bb9fd6..a950fc52 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -631,6 +631,28 @@ def test_update_submodules():
>>> repo.update_submodules()
"""
+def test_status():
+ """
+ Methods tested:
+ - L{gbp.git.GitRepository.status}
+
+ >>> import gbp.git, os, shutil
+ >>> repo = gbp.git.GitRepository(repo_dir)
+ >>> fname = os.path.join(repo.path, "test_status")
+ >>> shutil.copy(os.path.join(repo.path, ".git/HEAD"), fname)
+ >>> repo.status().items()
+ [('??', ['test_status'])]
+ >>> repo.status(['bla*']).items()
+ []
+ >>> repo.status(['te*']).items()
+ [('??', ['test_status'])]
+ >>> repo.add_files(repo.path, force=True)
+ >>> repo.commit_all(msg='added %s' % fname)
+ >>> _ = repo._git_inout('mv', [fname, fname + 'new'])
+ >>> repo.status().items()
+ [('R ', ['test_status -> test_statusnew'])]
+ """
+
def test_teardown():
"""
Perform the teardown