metadata: fix crash if .fdroid.yml but its not a git repo

This commit is contained in:
Hans-Christoph Steiner 2023-05-03 13:39:37 +02:00
parent c2bc52dd85
commit bb99986630
2 changed files with 18 additions and 2 deletions

View File

@ -672,7 +672,7 @@ def parse_metadata(metadatapath):
# pylint: disable-next=no-member
except git.exc.InvalidGitRepositoryError:
logging.debug(
_('Including metadata from {path}').format(metadata_in_repo)
_('Including metadata from {path}').format(path=metadata_in_repo)
)
app_in_repo = parse_metadata(metadata_in_repo)
for k, v in app_in_repo.items():

View File

@ -15,7 +15,7 @@ import textwrap
from collections import OrderedDict
from pathlib import Path
from testcommon import TmpCwd
from testcommon import TmpCwd, mkdtemp
localmodule = Path(__file__).resolve().parent.parent
print('localmodule: ' + str(localmodule))
@ -40,10 +40,13 @@ class MetadataTest(unittest.TestCase):
logging.basicConfig(level=logging.DEBUG)
self.basedir = localmodule / 'tests'
os.chdir(self.basedir)
self._td = mkdtemp()
self.testdir = self._td.name
fdroidserver.metadata.warnings_action = 'error'
def tearDown(self):
# auto-generated dirs by functions, not tests, so they are not always cleaned up
self._td.cleanup()
try:
os.rmdir("srclibs")
except OSError:
@ -228,6 +231,19 @@ class MetadataTest(unittest.TestCase):
# yaml.register_class(metadata.Build)
# yaml.dump(frommeta, fp)
def test_dot_fdroid_yml_works_without_git(self):
"""Parsing should work if .fdroid.yml is present and it is not a git repo."""
os.chdir(self.testdir)
yml = Path('metadata/test.yml')
yml.parent.mkdir()
with yml.open('w') as fp:
fp.write('Repo: https://example.com/not/git/or/anything')
fdroid_yml = Path('build/test/.fdroid.yml')
fdroid_yml.parent.mkdir(parents=True)
with fdroid_yml.open('w') as fp:
fp.write('OpenCollective: test')
metadata.parse_metadata(yml) # should not throw an exception
def test_rewrite_yaml_fakeotaupdate(self):
with tempfile.TemporaryDirectory() as testdir:
testdir = Path(testdir)