diff options
author | Ed Bartosh <eduard.bartosh@intel.com> | 2012-06-06 14:45:44 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2014-12-05 15:45:00 +0100 |
commit | 76739f8000d0d1b66ace201e105e3c3c2cd6357f (patch) | |
tree | d97063f4f8472d970b5825a01163d5112ad974dc /gbp/git/repository.py | |
parent | 194b6b8652784ebbcb64dada2836f9983b9daefe (diff) |
GitRepository: Implement status method
Simple wrapper to the git-status command.
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/git/repository.py')
-rw-r--r-- | gbp/git/repository.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 96921b1..6559921 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -820,6 +820,39 @@ class GitRepository(object): if ret: raise GitRepositoryError("Can't execute repository clean: %s" % err) + 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 = GitArgs('--porcelain', '-z') + if pathlist: + for path in pathlist: + options.add(path) + + out, err, ret = self._git_inout('status', options.args, + extra_env={'LC_ALL': 'C'}) + if ret: + raise GitRepositoryError("Can't get repository status: %s" % err) + + elements = out.split('\x00') + result = defaultdict(list) + + while elements[0] != '': + element = elements.pop(0) + status = element[:2] + filepath = element[3:] + # Expect to have two filenames for renames and copies + if status[0] in ['R', 'C']: + filepath = elements.pop(0) + '\x00' + filepath + result[status].append(filepath) + + return result + def is_empty(self): """ Is the repository empty? |