There was an error while loading. Please reload this page.
1 parent e94df6a commit 916c45dCopy full SHA for 916c45d
2 files changed
git/refs/reference.py
@@ -22,15 +22,17 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
22
_resolve_ref_on_create = True
23
_common_path_default = "refs"
24
25
- def __init__(self, repo, path):
+ def __init__(self, repo, path, check_path = True):
26
"""Initialize this instance
27
:param repo: Our parent repository
28
29
:param path:
30
Path relative to the .git/ directory pointing to the ref in question, i.e.
31
- refs/heads/master"""
32
- if not path.startswith(self._common_path_default+'/'):
33
- raise ValueError("Cannot instantiate %r from path %s" % ( self.__class__.__name__, path ))
+ refs/heads/master
+ :param check_path: if False, you can provide any path. Otherwise the path must start with the
+ default path prefix of this type."""
34
+ if check_path and not path.startswith(self._common_path_default+'/'):
35
+ raise ValueError("Cannot instantiate %r from path %s" % (self.__class__.__name__, path))
36
super(Reference, self).__init__(repo, path)
37
38
git/test/test_refs.py
@@ -24,6 +24,11 @@ def test_from_path(self):
assert isinstance(instance, ref_type)
# END for each name
# END for each type
+
+ # invalid path
+ self.failUnlessRaises(ValueError, TagReference, self.rorepo, "refs/invalid/tag")
+ # works without path check
+ TagReference(self.rorepo, "refs/invalid/tag", check_path=False)
def test_tag_base(self):
tag_object_refs = list()
0 commit comments