diff --git a/AUTHORS b/AUTHORS index 7b21b2b26..606796d98 100644 --- a/AUTHORS +++ b/AUTHORS @@ -43,4 +43,5 @@ Contributors are: -Liam Beguin -Ram Rachum -Alba Mendez +-Robert Westman Portions derived from other open source works and are clearly marked. diff --git a/git/refs/tag.py b/git/refs/tag.py index 8f88c5225..4d84239e7 100644 --- a/git/refs/tag.py +++ b/git/refs/tag.py @@ -18,7 +18,8 @@ class TagReference(Reference): print(tagref.tag.message)""" __slots__ = () - _common_path_default = "refs/tags" + _common_default = "tags" + _common_path_default = Reference._common_path_default + "/" + _common_default @property def commit(self): diff --git a/git/repo/base.py b/git/repo/base.py index e23ebb1ac..55682411a 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -402,7 +402,17 @@ def tags(self) -> 'IterableList': def tag(self, path: PathLike) -> TagReference: """:return: TagReference Object, reference pointing to a Commit or Tag :param path: path to the tag reference, i.e. 0.1.5 or tags/0.1.5 """ - return TagReference(self, path) + full_path = self._to_full_tag_path(path) + return TagReference(self, full_path) + + @staticmethod + def _to_full_tag_path(path): + if path.startswith(TagReference._common_path_default + '/'): + return path + if path.startswith(TagReference._common_default + '/'): + return Reference._common_path_default + '/' + path + else: + return TagReference._common_path_default + '/' + path def create_head(self, path: PathLike, commit: str = 'HEAD', force: bool = False, logmsg: Optional[str] = None diff --git a/test/test_repo.py b/test/test_repo.py index 8dc178337..04102b013 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -414,6 +414,16 @@ def test_index(self): def test_tag(self): assert self.rorepo.tag('refs/tags/0.1.5').commit + def test_tag_to_full_tag_path(self): + tags = ['0.1.5', 'tags/0.1.5', 'refs/tags/0.1.5'] + value_errors = [] + for tag in tags: + try: + self.rorepo.tag(tag) + except ValueError as valueError: + value_errors.append(valueError.args[0]) + self.assertEqual(value_errors, []) + def test_archive(self): tmpfile = tempfile.mktemp(suffix='archive-test') with open(tmpfile, 'wb') as stream: