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

Commit916c45d

Browse files
committed
refs: added constructor flag to allow refs to be instatiated from any path, including simple test
1 parente94df6a commit916c45d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

‎git/refs/reference.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
2222
_resolve_ref_on_create=True
2323
_common_path_default="refs"
2424

25-
def__init__(self,repo,path):
25+
def__init__(self,repo,path,check_path=True):
2626
"""Initialize this instance
2727
:param repo: Our parent repository
2828
2929
:param path:
3030
Path relative to the .git/ directory pointing to the ref in question, i.e.
31-
refs/heads/master"""
32-
ifnotpath.startswith(self._common_path_default+'/'):
33-
raiseValueError("Cannot instantiate %r from path %s"% (self.__class__.__name__,path ))
31+
refs/heads/master
32+
:param check_path: if False, you can provide any path. Otherwise the path must start with the
33+
default path prefix of this type."""
34+
ifcheck_pathandnotpath.startswith(self._common_path_default+'/'):
35+
raiseValueError("Cannot instantiate %r from path %s"% (self.__class__.__name__,path))
3436
super(Reference,self).__init__(repo,path)
3537

3638

‎git/test/test_refs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def test_from_path(self):
2424
assertisinstance(instance,ref_type)
2525
# END for each name
2626
# END for each type
27+
28+
# invalid path
29+
self.failUnlessRaises(ValueError,TagReference,self.rorepo,"refs/invalid/tag")
30+
# works without path check
31+
TagReference(self.rorepo,"refs/invalid/tag",check_path=False)
2732

2833
deftest_tag_base(self):
2934
tag_object_refs=list()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp