summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Bartosh <eduard.bartosh@intel.com>2012-06-06 14:45:44 +0300
committerEd Bartosh <eduard.bartosh@intel.com>2012-06-12 15:27:26 +0300
commit321ee6b7b60bbfcb45ea46edde43a64a7d42c11b (patch)
tree03fed29a75329bc053099e861e237b9c68bf9a8b
parentdc48b21793c6a3c8bc36acd9942474f97a2b2b63 (diff)
downloadgit-buildpackage-321ee6b7b60bbfcb45ea46edde43a64a7d42c11b.tar.gz
git-buildpackage-321ee6b7b60bbfcb45ea46edde43a64a7d42c11b.tar.bz2
git-buildpackage-321ee6b7b60bbfcb45ea46edde43a64a7d42c11b.zip
GitRepository: Implemented status method
Change-Id: I2fef97a40f8cb04cc5a354df8211469e6d9f6eff
-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