# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""A Git repository"""
+import os
import re
import subprocess
import os.path
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?
>>> 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