mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-04 02:00:11 +02:00
Fix tag match with GitPython
This commit is contained in:
parent
737ad53d3c
commit
516a0c2ce8
@ -1238,34 +1238,15 @@ class vcs_git(vcs):
|
|||||||
p = FDroidPopen(['git', 'tag'], cwd=self.local, output=False)
|
p = FDroidPopen(['git', 'tag'], cwd=self.local, output=False)
|
||||||
return p.output.splitlines()
|
return p.output.splitlines()
|
||||||
|
|
||||||
tag_format = re.compile(r'tag: ([^) ]*)')
|
|
||||||
|
|
||||||
def latesttags(self):
|
def latesttags(self):
|
||||||
"""Return a list of latest tags.
|
"""Return 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()
|
self.checkrepo()
|
||||||
p = FDroidPopen(['git', 'log', '--tags',
|
# TODO: Python3.6: Should accept path-like
|
||||||
'--simplify-by-decoration', '--pretty=format:%d'],
|
return [tag.name for tag in sorted(
|
||||||
cwd=self.local, output=False)
|
git.Repo(self.local).tags,
|
||||||
tags = []
|
key=lambda t: t.commit.committed_date,
|
||||||
for line in p.output.splitlines():
|
reverse=True
|
||||||
for entry in line.split(', '):
|
)]
|
||||||
for tag in self.tag_format.findall(entry):
|
|
||||||
tags.append(tag)
|
|
||||||
return tags
|
|
||||||
|
|
||||||
def getref(self, revname='HEAD'):
|
def getref(self, revname='HEAD'):
|
||||||
self.checkrepo()
|
self.checkrepo()
|
||||||
|
@ -2357,26 +2357,29 @@ class CommonTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_vcs_git_latesttags(self):
|
def test_vcs_git_latesttags(self):
|
||||||
vcs = fdroidserver.common.vcs_git(None, None)
|
tags = [
|
||||||
popenmock = mock.Mock()
|
"1.1.1",
|
||||||
popenmock.output = """
|
"2.2.2",
|
||||||
(HEAD, tag: 8.9.5, origin/master, origin/HEAD, master)
|
"v3.0",
|
||||||
(tag: 8.9.4)
|
"0.0.4",
|
||||||
(tag: 8.9.3, tag: 8,9,3)
|
"0.5.0-beta",
|
||||||
(tag: 8.9.3b)
|
"666(6)",
|
||||||
(tag: awesome_release)
|
"seven",
|
||||||
(origin/feature/cast)
|
]
|
||||||
(tag: 8.6.3)
|
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
|
||||||
"""
|
# TODO: Python3.6: Should accept path-like
|
||||||
with mock.patch(
|
repo = git.Repo.init(str(Path.cwd()))
|
||||||
'fdroidserver.common.FDroidPopen', lambda a, **b: popenmock
|
f = Path("test")
|
||||||
) as _ignored, mock.patch(
|
date = 10**9
|
||||||
'fdroidserver.common.vcs_git.checkrepo'
|
for tag in tags:
|
||||||
) as _ignored:
|
date += 1
|
||||||
_ignored # silence the linters
|
f.write_text(tag)
|
||||||
tags = vcs.latesttags()
|
repo.index.add([str(f)])
|
||||||
self.assertEqual(tags, ['8.9.5', '8.9.4', '8.9.3', '8,9,3',
|
repo.index.commit(tag, commit_date=str(date) + " +0000")
|
||||||
'8.9.3b', 'awesome_release', '8.6.3'])
|
repo.create_tag(tag)
|
||||||
|
|
||||||
|
vcs = fdroidserver.common.vcs_git(None, Path.cwd())
|
||||||
|
self.assertEqual(vcs.latesttags(), tags[::-1])
|
||||||
|
|
||||||
def test_get_release_filename(self):
|
def test_get_release_filename(self):
|
||||||
app = fdroidserver.metadata.App()
|
app = fdroidserver.metadata.App()
|
||||||
|
Loading…
Reference in New Issue
Block a user