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

Commit87aa78c

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

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
@@ -20,15 +20,17 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
2020
_resolve_ref_on_create=True
2121
_common_path_default="refs"
2222

23-
def__init__(self,repo,path):
23+
def__init__(self,repo,path,check_path=True):
2424
"""Initialize this instance
2525
:param repo: Our parent repository
2626
2727
:param path:
2828
Path relative to the .git/ directory pointing to the ref in question, i.e.
29-
refs/heads/master"""
30-
ifnotpath.startswith(self._common_path_default+'/'):
31-
raiseValueError("Cannot instantiate %r from path %s, maybe use %s.to_full_path(name) to safely generate a valid full path from a name"% (self.__class__.__name__,path,type(self).__name__))
29+
refs/heads/master
30+
:param check_path: if False, you can provide any path. Otherwise the path must start with the
31+
default path prefix of this type."""
32+
ifcheck_pathandnotpath.startswith(self._common_path_default+'/'):
33+
raiseValueError("Cannot instantiate %r from path %s"% (self.__class__.__name__,path))
3234
super(Reference,self).__init__(repo,path)
3335

3436

‎git/test/refs/test_refs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ def test_from_path(self):
2929
assertisinstance(instance,ref_type)
3030
# END for each name
3131
# END for each type
32+
33+
# invalid path
34+
self.failUnlessRaises(ValueError,TagReference,self.rorepo,"refs/invalid/tag")
35+
# works without path check
36+
TagReference(self.rorepo,"refs/invalid/tag",check_path=False)
3237

3338
deftest_tag_base(self):
3439
tag_object_refs=list()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp