Skip to content

Issue 1261 #1264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ Contributors are:
-Liam Beguin <liambeguin _at_ gmail.com>
-Ram Rachum <ram _at_ rachum.com>
-Alba Mendez <me _at_ alba.sh>
-Robert Westman <robert _at_ byteflux.io>
Portions derived from other open source works and are clearly marked.
3 changes: 2 additions & 1 deletion git/refs/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 11 additions & 1 deletion git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down