diff --git a/fdroidserver/common.py b/fdroidserver/common.py index cc29fa27..32cb1859 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1171,11 +1171,33 @@ class vcs_git(vcs): p = FDroidPopen(['git', 'tag'], cwd=self.local, output=False) return p.output.splitlines() + tag_format = re.compile(r'tag: ([^) ]*)') + def latesttags(self): + """Returns a list of latest tags + the definition is a little blurry here, Android does not care for the + version name of an app as normally used as the tag name so versions do + not need to follow strverscmp() or similar. Also they can be rather + arbitrary so git tag --sort=-version:refname does not work. On the other side + sorting them by creation date, i.e. git tag --sort=-authordate does not + work either as there are a lot of repos where older tags were created + later. + + So git log preserves the graph order and only sorts by date afterwards. + This results in tags of beta versions being sorted earlier then the + latest tag as long as they are part of the graph below the latest tag + or are created earlier. + """ self.checkrepo() - p = FDroidPopen(['git', 'tag', '--sort=-authordate'], + p = FDroidPopen(['git', 'log', '--tags', + '--simplify-by-decoration', '--pretty=format:%d'], cwd=self.local, output=False) - return p.output.splitlines() + tags = [] + for line in p.output.splitlines(): + for entry in line.split(', '): + for tag in self.tag_format.findall(entry): + tags.append(tag) + return tags class vcs_gitsvn(vcs): diff --git a/tests/common.TestCase b/tests/common.TestCase index b9c70959..dbded144 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -2062,7 +2062,15 @@ class CommonTest(unittest.TestCase): def test_vcs_git_latesttags(self): vcs = fdroidserver.common.vcs_git(None, None) popenmock = mock.Mock() - popenmock.output = "8.9.5\n8.9.4\n8.6.3\n8,9,3" + popenmock.output = """ + (HEAD, tag: 8.9.5, origin/master, origin/HEAD, master) + (tag: 8.9.4) + (tag: 8.9.3, tag: 8,9,3) + (tag: 8.9.3b) + (tag: awesome_release) + (origin/feature/cast) + (tag: 8.6.3) +""" with mock.patch( 'fdroidserver.common.FDroidPopen', lambda a, **b: popenmock ) as _ignored, mock.patch( @@ -2070,7 +2078,8 @@ class CommonTest(unittest.TestCase): ) as _ignored: _ignored # silence the linters tags = vcs.latesttags() - self.assertEqual(tags, ['8.9.5', '8.9.4', '8.6.3', '8,9,3']) + self.assertEqual(tags, ['8.9.5', '8.9.4', '8.9.3', '8,9,3', + '8.9.3b', 'awesome_release', '8.6.3']) if __name__ == "__main__":