| |
@@ -16,9 +16,10 @@
|
| |
import shutil
|
| |
import sys
|
| |
import os
|
| |
-
|
| |
+ import tempfile
|
| |
import pygit2
|
| |
from mock import patch
|
| |
+ from pagure.lib.repo import PagureRepo
|
| |
|
| |
sys.path.insert(0, os.path.join(os.path.dirname(
|
| |
os.path.abspath(__file__)), '..'))
|
| |
@@ -1253,17 +1254,64 @@
|
| |
output = pagure.lib.git.read_git_lines(
|
| |
['log', '-3', "--pretty='%H'"], gitrepo)
|
| |
self.assertEqual(len(output), 2)
|
| |
- to_hash = output[0].replace("'", '')
|
| |
from_hash = output[1].replace("'", '')
|
| |
|
| |
+ # Case 1, repo BASE is null and HEAD is equal to from_hash
|
| |
+ to_hash = '0'
|
| |
output1 = pagure.lib.git.get_revs_between(
|
| |
to_hash, from_hash, gitrepo)
|
| |
- self.assertEqual(output1, [to_hash])
|
| |
+ self.assertEqual(output1, [from_hash])
|
| |
|
| |
+ # Case 2, get revs between two commits (to_hash, from_hash)
|
| |
+ to_hash = output[0].replace("'", '')
|
| |
output2 = pagure.lib.git.get_revs_between(
|
| |
- from_hash, to_hash, gitrepo)
|
| |
+ to_hash, from_hash, gitrepo)
|
| |
self.assertEqual(output2, [to_hash])
|
| |
|
| |
+ # Case 3, get revs between two commits (from_hash, to_hash)
|
| |
+ output3 = pagure.lib.git.get_revs_between(
|
| |
+ from_hash, to_hash, gitrepo)
|
| |
+ self.assertEqual(output3, [to_hash])
|
| |
+
|
| |
+ # Case 4, get revs between two commits on two different branches
|
| |
+ newgitrepo = tempfile.mkdtemp(prefix='pagure-')
|
| |
+ newrepo = pygit2.clone_repository(gitrepo, newgitrepo)
|
| |
+ newrepo.create_branch('feature', newrepo.head.get_object())
|
| |
+
|
| |
+ with open(os.path.join(newgitrepo, 'sources'), 'w') as stream:
|
| |
+ stream.write('foo\n bar')
|
| |
+ newrepo.index.add('sources')
|
| |
+ newrepo.index.write()
|
| |
+
|
| |
+ # Commits the files added
|
| |
+ tree = newrepo.index.write_tree()
|
| |
+ author = pygit2.Signature(
|
| |
+ 'Alice Author', 'alice@authors.tld')
|
| |
+ committer = pygit2.Signature(
|
| |
+ 'Cecil Committer', 'cecil@committers.tld')
|
| |
+ newrepo.create_commit(
|
| |
+ 'refs/heads/feature', # the name of the reference to update
|
| |
+ author,
|
| |
+ committer,
|
| |
+ 'Add sources file for testing',
|
| |
+ # binary string representing the tree object ID
|
| |
+ tree,
|
| |
+ # list of binary strings representing parents of the new commit
|
| |
+ [to_hash]
|
| |
+ )
|
| |
+ branch_commit = newrepo.revparse_single('refs/heads/feature')
|
| |
+
|
| |
+ # Push to origin
|
| |
+ ori_remote = newrepo.remotes[0]
|
| |
+ PagureRepo.push(ori_remote, 'refs/heads/feature')
|
| |
+
|
| |
+ # Remove the clone
|
| |
+ shutil.rmtree(newgitrepo)
|
| |
+
|
| |
+ output4 = pagure.lib.git.get_revs_between(
|
| |
+ 'feature', '0', gitrepo)
|
| |
+ self.assertEqual(output4, [branch_commit.oid.hex])
|
| |
+
|
| |
def test_get_author(self):
|
| |
""" Test the get_author method of pagure.lib.git. """
|
| |
|
| |
get_revs_between method returns an empty list, when you want to get the revision between a commit and the base of the repo.