Repository: gitpython-developers/GitPython (python)

Issue:
repo.tag() only accepts 'ref/tags/tagname' instead of just 'tagname'
The param comment for `tag()` in `base.py` mentions `0.1.5` and `tags/0.1.5` as valid inputs, however the call to `TagReference` calls the inherited constructor (`Reference` in reference.py) with the default `check_path=True`, which returns a `ValueError`, if the tag/path given doesnt start with `self._common_path_default + '/'`.

Either the param comment needs to be adjusted or the tag parameter cleaned up so that it only returns the tag value to `Reference.__init__`.


![pycharm64_UlSdzGazov](https://user-images.githubusercontent.com/29196542/120461092-01f2c780-c39a-11eb-8ed4-6fed9370d428.png)
![pycharm64_nnw8DMULi2](https://user-images.githubusercontent.com/29196542/120461085-00290400-c39a-11eb-9a5e-1441919e8a1f.png)


Pull request:
Issue 1261
Fixes #1261 

Patch:
diff --git a/AUTHORS b/AUTHORS
index 7b21b2b2..606796d9 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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.
diff --git a/git/refs/tag.py b/git/refs/tag.py
index 8f88c522..4d84239e 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 e23ebb1a..55682411 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -402,7 +402,17 @@ class Repo(object):
     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


Test patch:
diff --git a/test/test_repo.py b/test/test_repo.py
index 8dc17833..04102b01 100644
--- a/test/test_repo.py
+++ b/test/test_repo.py
@@ -414,6 +414,16 @@ class TestRepo(TestBase):
     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: