File tree 2 files changed +31
-3
lines changed
2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 1
1
"""Module with our own gitdb implementation - it uses the git command"""
2
- from exc import GitCommandError
2
+ from exc import (
3
+ GitCommandError ,
4
+ BadObject
5
+ )
3
6
4
7
from gitdb .base import (
5
8
OInfo ,
@@ -42,7 +45,7 @@ def stream(self, sha):
42
45
43
46
# { Interface
44
47
45
- def partial_to_complete_sha_hex (partial_hexsha ):
48
+ def partial_to_complete_sha_hex (self , partial_hexsha ):
46
49
""":return: Full binary 20 byte sha from the given partial hexsha
47
50
:raise AmbiguousObjectName:
48
51
:raise BadObject:
@@ -51,7 +54,7 @@ def partial_to_complete_sha_hex(partial_hexsha):
51
54
try :
52
55
hexsha , typename , size = self ._git .get_object_header (partial_hexsha )
53
56
return hex_to_bin (hexsha )
54
- except GitCommandError :
57
+ except ( GitCommandError , ValueError ) :
55
58
raise BadObject (partial_hexsha )
56
59
# END handle exceptions
57
60
Original file line number Diff line number Diff line change
1
+ # test_repo.py
2
+ # Copyright (C) 2008, 2009 Michael Trier ([email protected] ) and contributors
3
+ #
4
+ # This module is part of GitPython and is released under
5
+ # the BSD License: http://www.opensource.org/licenses/bsd-license.php
6
+ from test .testlib import *
7
+ from git .db import *
8
+ from gitdb .util import bin_to_hex
9
+ from git .exc import BadObject
10
+ import os
11
+
12
+ class TestDB (TestBase ):
13
+
14
+ def test_base (self ):
15
+ gdb = GitCmdObjectDB (os .path .join (self .rorepo .git_dir , 'objects' ), self .rorepo .git )
16
+
17
+ # partial to complete - works with everything
18
+ hexsha = bin_to_hex (gdb .partial_to_complete_sha_hex ("0.1.6" ))
19
+ assert len (hexsha ) == 40
20
+
21
+ assert bin_to_hex (gdb .partial_to_complete_sha_hex (hexsha [:20 ])) == hexsha
22
+
23
+ # fails with BadObject
24
+ for invalid_rev in ("0000" , "bad/ref" , "super bad" ):
25
+ self .failUnlessRaises (BadObject , gdb .partial_to_complete_sha_hex , invalid_rev )
You can’t perform that action at this time.
0 commit comments