summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2012-09-14 17:38:55 +0300
committerGuido Günther <agx@sigxcpu.org>2012-11-07 21:07:21 +0100
commitba854d88c5455ff7b1abab92c1d685d50855991d (patch)
tree2ab1fd6151e3b2268febf2ddecb5920eb5dbfcd9
parent8bb62f570a35bd54eb04cb7bc13d3c2dcf385ffb (diff)
GitRepository/diff: add 'paths' argument
Makes the diff function more versatile. I.e. makes diffing only certain paths possible. Also, add basic unittests for the diff() method. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/git/repository.py6
-rw-r--r--tests/test_GitRepository.py17
2 files changed, 22 insertions, 1 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 100b6b2..dfe5cb2 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -1352,7 +1352,7 @@ class GitRepository(object):
args.append(patch)
self._git_command("apply", args)
- def diff(self, obj1, obj2):
+ def diff(self, obj1, obj2, paths=None):
"""
Diff two git repository objects
@@ -1360,10 +1360,14 @@ class GitRepository(object):
@type obj1: C{str}
@param obj2: second object
@type obj2: C{str}
+ @param paths: List of paths to diff
+ @type paths: C{list}
@return: diff
@rtype: C{str}
"""
options = GitArgs(obj1, obj2)
+ if paths:
+ options.add('--', paths)
output, ret = self._git_getoutput('diff', options.args)
return output
#}
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index 1b3f5b8..5b9fc92 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -410,6 +410,23 @@ def test_get_commit_info():
defaultdict(<type 'list'>, {'M': ['testfile']})
"""
+def test_diff():
+ """
+ Test git-diff
+
+ Methods tested:
+ - L{gbp.git.GitRepository.diff}
+
+ >>> import gbp.git
+ >>> repo = gbp.git.GitRepository(repo_dir)
+ >>> len(repo.diff('HEAD~1', 'HEAD')) > 3
+ True
+ >>> len(repo.diff('HEAD~1', 'HEAD', 'testfile')) > 3
+ True
+ >>> len(repo.diff('HEAD~1', 'HEAD', 'filenotexist')) == 0
+ True
+ """
+
def test_mirror_clone():
"""
Mirror a repository