diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-09-14 13:40:14 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2014-12-05 15:35:14 +0100 |
commit | cb9271fe113bae56088c9c1d07870c408a518a52 (patch) | |
tree | c8b53e9859e7ea9cc412b171a4f1d04b01b2e812 | |
parent | 7a503e926669041847f568d1ee26ff948e261ffd (diff) |
GitRepository: add diff_status method
This is a method of getting the filename and status information of a
diff. That is, a list of files that changed and their status, "added",
"modified" etc.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r-- | gbp/git/repository.py | 27 | ||||
-rw-r--r-- | tests/test_GitRepository.py | 13 |
2 files changed, 40 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 23f9482..edb8e21 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -1639,6 +1639,33 @@ class GitRepository(object): if ret: raise GitRepositoryError("Git diff failed") return output + + def diff_status(self, obj1, obj2): + """ + Get file-status of two git repository objects + + @param obj1: first object + @type obj1: C{str} + @param obj2: second object + @type obj2: C{str} + @return: name-status + @rtype: C{defaultdict} of C{str} + """ + options = GitArgs('--name-status', '-z', obj1, obj2) + output, stderr, ret = self._git_inout('diff', options.args) + + elements = output.split('\x00') + result = defaultdict(list) + + while elements[0] != '': + status = elements.pop(0)[0] + filepath = elements.pop(0) + # Expect to have two filenames for renames and copies + if status in ['R', 'C']: + filepath = elements.pop(0) + '\x00' + filepath + result[status].append(filepath) + + return result #} def archive(self, format, prefix, output, treeish, **kwargs): diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py index 427370d..c5c5849 100644 --- a/tests/test_GitRepository.py +++ b/tests/test_GitRepository.py @@ -493,6 +493,19 @@ def test_diff(): True """ +def test_diff_status(): + """ + Methods tested: + - L{gbp.git.GitRepository.diff_status} + + >>> import gbp.git + >>> repo = gbp.git.GitRepository(repo_dir) + >>> repo.diff_status("HEAD", "HEAD") + defaultdict(<type 'list'>, {}) + >>> repo.diff_status("HEAD~1", "HEAD") + defaultdict(<type 'list'>, {'M': ['testfile']}) + """ + def test_mirror_clone(): """ Mirror a repository |