1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-07-07 09:50:07 +02:00

Merge branch 'tag_sort_version' into 'master'

latesttags revert to git log and fix comma handling

See merge request fdroid/fdroidserver!960
This commit is contained in:
Jochen Sprickerhof 2021-06-15 06:53:58 +00:00
commit 188e163b1a
2 changed files with 35 additions and 4 deletions

View File

@ -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):

View File

@ -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__":