aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2012-11-08 08:22:26 +0200
committerGuido Günther <agx@sigxcpu.org>2012-11-23 19:25:10 +0100
commit8bc79214f5e8dc4dfe8307a1caf8464464727493 (patch)
treebd41ed3ec68f40714f59e58a2ba14c6fbe722d3d
parent3678906db10415e1ff690c0fc9baba1fe1af1d97 (diff)
GitRepository/get_commits: more flexible revision ranges
Support getting the complete history of an arbitrary commit-ish (since=None, until=COMMIT-ISH). Formerly this was only possible for the current git HEAD. Now, get_commits(since=None, until='COMMIT') translates to 'git log COMMIT'. Also, for consistency, add support for getting the history from an arbitrary commit until the current HEAD (since=COMMIT-ISH, until=None). Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/git/repository.py5
-rw-r--r--tests/test_GitRepository.py10
2 files changed, 14 insertions, 1 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 77b60ec5..a855ac72 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -1257,7 +1257,10 @@ class GitRepository(object):
args = GitArgs('--pretty=format:%H')
args.add_true(num, '-%d' % num)
args.add_true(first_parent, '--first-parent')
- args.add_true(since and until, '%s..%s' % (since, until))
+ if since:
+ args.add("%s..%s" % (since, until or 'HEAD'))
+ elif until:
+ args.add(until)
args.add_cond(options, options)
args.add("--")
if isinstance(paths, basestring):
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index 5b9fc925..0e833b50 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -373,6 +373,16 @@ def test_get_commits():
True
>>> len(repo.get_commits(num=1)) == 1
True
+ >>> commits2 = repo.get_commits(since='HEAD~1')
+ >>> len(commits2) == 1
+ True
+ >>> commits2[0] == commits[0]
+ True
+ >>> commits2 = repo.get_commits(until='HEAD~1')
+ >>> len(commits2) == 1
+ True
+ >>> commits2[0] == commits[-1]
+ True
>>> repo.get_commits(paths=['foo', 'bar'])
[]
>>> repo.get_commits(paths=['testfile']) == commits