Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb08651e

Browse files
committed
Improved handling of name-resolution, which will not mangle names anymore.
Previously, an unresolvable ref name like HEAD would end up as HEX andwas presented as BadObject error, even though that exception is forinvalid shas only.Now BadName is thrown, which converts into a more useful error message.Improvesgitpython-developers#105
1 parentfc94b89 commitb08651e

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

‎git/repo/fun.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
importos
33
fromstringimportdigits
44

5-
fromgitdb.excimportBadObject
5+
fromgitdb.excimport (
6+
BadObject,
7+
BadName
8+
)
69
fromgit.refsimportSymbolicReference
710
fromgit.objectsimportObject
811
fromgitdb.utilimport (
@@ -83,7 +86,7 @@ def name_to_object(repo, name, return_ref=False):
8386
:return: object specified by the given name, hexshas ( short and long )
8487
as well as references are supported
8588
:param return_ref: if name specifies a reference, we will return the reference
86-
instead of the object. Otherwise it will raise BadObject
89+
instead of the object. Otherwise it will raise BadObject or BadName
8790
"""
8891
hexsha=None
8992

@@ -119,7 +122,7 @@ def name_to_object(repo, name, return_ref=False):
119122

120123
# tried everything ? fail
121124
ifhexshaisNone:
122-
raiseBadObject(name)
125+
raiseBadName(name)
123126
# END assert hexsha was found
124127

125128
returnObject.new_from_sha(repo,hex_to_bin(hexsha))

‎git/test/test_repo.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@
2626
GitDB,
2727
Submodule,
2828
GitCmdObjectDB,
29-
Remote
29+
Remote,
30+
BadName
3031
)
32+
fromgit.repo.funimporttouch
3133
fromgit.utilimportjoin_path_native
3234
fromgit.excimportBadObject
3335
fromgitdb.utilimportbin_to_hex
3436
fromgit.compatimport (
3537
string_types,
3638
defenc
3739
)
40+
fromgitdb.test.libimportwith_rw_directory
3841

3942
importos
4043
importsys
@@ -682,3 +685,25 @@ def last_commit(repo, rev, path):
682685
deftest_remote_method(self):
683686
self.failUnlessRaises(ValueError,self.rorepo.remote,'foo-blue')
684687
assertisinstance(self.rorepo.remote(name='origin'),Remote)
688+
689+
@with_rw_directory
690+
deftest_empty_repo(self,rw_dir):
691+
"""Assure we can handle empty repositories"""
692+
r=Repo.init(rw_dir,mkdir=False)
693+
# It's ok not to be able to iterate a commit, as there is none
694+
self.failUnlessRaises(ValueError,r.iter_commits)
695+
assertr.active_branch.name=='master'
696+
assertnotr.active_branch.is_valid(),"Branch is yet to be born"
697+
698+
# actually, when trying to create a new branch without a commit, git itself fails
699+
# We should, however, not fail ungracefully
700+
self.failUnlessRaises(BadName,r.create_head,'foo')
701+
702+
new_file_path=os.path.join(rw_dir,"new_file.ext")
703+
touch(new_file_path)
704+
r.index.add([new_file_path])
705+
r.index.commit("initial commit")
706+
707+
# Now a branch should be creatable
708+
nb=r.create_head('foo')
709+
assertnb.is_valid()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp