|
7 | 7 | from git import *
|
8 | 8 | from git.util import join_path_native
|
9 | 9 | from git.exc import BadObject
|
10 |
| -from gitdb.util import hex_to_bin |
| 10 | +from gitdb.util import hex_to_bin, bin_to_hex |
11 | 11 |
|
12 | 12 | import os, sys
|
13 | 13 | import tempfile
|
@@ -57,7 +57,12 @@ def test_tree_from_revision(self):
|
57 | 57 | assert self.rorepo.tree(tree) == tree
|
58 | 58 |
|
59 | 59 | # try from invalid revision that does not exist
|
60 |
| - self.failUnlessRaises(ValueError, self.rorepo.tree, 'hello world') |
| 60 | + self.failUnlessRaises(BadObject, self.rorepo.tree, 'hello world') |
| 61 | + |
| 62 | + def test_commit_from_revision(self): |
| 63 | + commit = self.rorepo.commit('0.1.4') |
| 64 | + assert commit.type == 'commit' |
| 65 | + assert self.rorepo.commit(commit) == commit |
61 | 66 |
|
62 | 67 | def test_commits(self):
|
63 | 68 | mc = 10
|
@@ -445,7 +450,7 @@ def test_rev_parse(self):
|
445 | 450 | rev_parse = self.rorepo.rev_parse
|
446 | 451 |
|
447 | 452 | # try special case: This one failed beforehand
|
448 |
| - assert self.rorepo.odb.partial_to_complete_sha_hex("33ebe") == hex_to_bin("33ebe7acec14b25c5f84f35a664803fcab2f7781") |
| 453 | + assert rev_parse("33ebe").hexsha == "33ebe7acec14b25c5f84f35a664803fcab2f7781" |
449 | 454 |
|
450 | 455 | # start from reference
|
451 | 456 | num_resolved = 0
|
@@ -507,6 +512,16 @@ def test_rev_parse(self):
|
507 | 512 | assert tag.object == rev_parse('0.1.4%s' % token)
|
508 | 513 | # END handle multiple tokens
|
509 | 514 |
|
| 515 | + # try partial parsing |
| 516 | + max_items = 40 |
| 517 | + for i, binsha in enumerate(self.rorepo.odb.sha_iter()): |
| 518 | + assert rev_parse(bin_to_hex(binsha)[:8-(i%2)]).binsha == binsha |
| 519 | + if i > max_items: |
| 520 | + # this is rather slow currently, as rev_parse returns an object |
| 521 | + # which requires accessing packs, it has some additional overhead |
| 522 | + break |
| 523 | + # END for each binsha in repo |
| 524 | + |
510 | 525 | # missing closing brace commit^{tree
|
511 | 526 | self.failUnlessRaises(ValueError, rev_parse, '0.1.4^{tree')
|
512 | 527 |
|
|
0 commit comments