File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 11"""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+ )
36
47from gitdb .base import (
58 OInfo ,
@@ -42,7 +45,7 @@ def stream(self, sha):
4245
4346 # { Interface
4447
45- def partial_to_complete_sha_hex (partial_hexsha ):
48+ def partial_to_complete_sha_hex (self , partial_hexsha ):
4649 """:return: Full binary 20 byte sha from the given partial hexsha
4750 :raise AmbiguousObjectName:
4851 :raise BadObject:
@@ -51,7 +54,7 @@ def partial_to_complete_sha_hex(partial_hexsha):
5154 try :
5255 hexsha , typename , size = self ._git .get_object_header (partial_hexsha )
5356 return hex_to_bin (hexsha )
54- except GitCommandError :
57+ except ( GitCommandError , ValueError ) :
5558 raise BadObject (partial_hexsha )
5659 # END handle exceptions
5760
Original file line number Diff line number Diff line change 1+ # test_repo.py
2+ # Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) 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