From 3f6b03b93b8d39665771f02cff1579714b884a00 Mon Sep 17 00:00:00 2001 From: anatoly techtonik Date: Thu, 23 Nov 2017 10:51:52 +0300 Subject: [PATCH 1/2] Fix Edit links if version is referenced by annotated tag Fixes Edit links when pointed tag is annotated. GitHub is unable to find commit corresponding to tag hash, because annotated tags are pointing to tag meta data and need be dereferenced first. https://public-inbox.org/git/CAPkN8x+MELCnttE+xptKzYXsYPWqbiE59LABrwNBhFroayc+wQ@mail.gmail.com/ --- readthedocs/vcs_support/backends/git.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/readthedocs/vcs_support/backends/git.py b/readthedocs/vcs_support/backends/git.py index 321a2b1a1cf..b9098ebf9c3 100644 --- a/readthedocs/vcs_support/backends/git.py +++ b/readthedocs/vcs_support/backends/git.py @@ -92,7 +92,14 @@ def clone(self): @property def tags(self): - retcode, stdout, _ = self.run('git', 'show-ref', '--tags') + # Hash for non-annotated tag is its commit hash, but for annotated tag it + # points to tag itself, so we need to dereference annotated tags. + # The output format is the same as `git show-ref --tags`, but with hashes + # of annotated tags pointing to tagged commits. + retcode, stdout, _ = self.run( + 'git', 'for-each-ref', + '--format="%(if)%(*objectname)%(then)%(*objectname)%(else)%(objectname)%(end) %(refname)"', + 'refs/tags') # error (or no tags found) if retcode != 0: return [] @@ -100,7 +107,7 @@ def tags(self): def parse_tags(self, data): """ - Parses output of show-ref --tags, eg: + Parses output of `git show-ref --tags`, eg: 3b32886c8d3cb815df3793b3937b2e91d0fb00f1 refs/tags/2.0.0 bd533a768ff661991a689d3758fcfe72f455435d refs/tags/2.0.1 From 4dd5605e86aba37aa86f8fbe84abb759cb1ee93e Mon Sep 17 00:00:00 2001 From: anatoly techtonik Date: Thu, 23 Nov 2017 11:52:23 +0300 Subject: [PATCH 2/2] Fix lint line too long https://travis-ci.org/rtfd/readthedocs.org/jobs/306192026#L821 --- readthedocs/vcs_support/backends/git.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readthedocs/vcs_support/backends/git.py b/readthedocs/vcs_support/backends/git.py index b9098ebf9c3..d3ac9ab643c 100644 --- a/readthedocs/vcs_support/backends/git.py +++ b/readthedocs/vcs_support/backends/git.py @@ -98,7 +98,8 @@ def tags(self): # of annotated tags pointing to tagged commits. retcode, stdout, _ = self.run( 'git', 'for-each-ref', - '--format="%(if)%(*objectname)%(then)%(*objectname)%(else)%(objectname)%(end) %(refname)"', + '--format="%(if)%(*objectname)%(then)%(*objectname)' + '%(else)%(objectname)%(end) %(refname)"', 'refs/tags') # error (or no tags found) if retcode != 0: