Skip to content

Commit 1b3404b

Browse files
authored
Merge pull request #3302 from techtonik/patch-2
Fix Edit links if version is referenced by annotated tag
2 parents 26102e0 + 4dd5605 commit 1b3404b

File tree

1 file changed

+10
-2
lines changed
  • readthedocs/vcs_support/backends

1 file changed

+10
-2
lines changed

readthedocs/vcs_support/backends/git.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,23 @@ def clone(self):
8080

8181
@property
8282
def tags(self):
83-
retcode, stdout, _ = self.run('git', 'show-ref', '--tags')
83+
# Hash for non-annotated tag is its commit hash, but for annotated tag it
84+
# points to tag itself, so we need to dereference annotated tags.
85+
# The output format is the same as `git show-ref --tags`, but with hashes
86+
# of annotated tags pointing to tagged commits.
87+
retcode, stdout, _ = self.run(
88+
'git', 'for-each-ref',
89+
'--format="%(if)%(*objectname)%(then)%(*objectname)'
90+
'%(else)%(objectname)%(end) %(refname)"',
91+
'refs/tags')
8492
# error (or no tags found)
8593
if retcode != 0:
8694
return []
8795
return self.parse_tags(stdout)
8896

8997
def parse_tags(self, data):
9098
"""
91-
Parses output of show-ref --tags, eg:
99+
Parses output of `git show-ref --tags`, eg:
92100
93101
3b32886c8d3cb815df3793b3937b2e91d0fb00f1 refs/tags/2.0.0
94102
bd533a768ff661991a689d3758fcfe72f455435d refs/tags/2.0.1

0 commit comments

Comments
 (0)