config: Allow a default refspec to be specified

Also update config file version to 9 due to this format change.

Signed-off-by: Paul Barker <pbarker@konsulko.com>
[Jan: style fix]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Paul Barker
2020-07-04 09:53:38 +02:00
committed by Jan Kiszka
parent f678b24611
commit 2260189fda
6 changed files with 47 additions and 3 deletions

View File

@@ -28,5 +28,5 @@ __copyright__ = 'Copyright (c) Siemens AG, 2017-2018'
__version__ = '2.1.1'
# Please update docs/format-changelog.rst when changing the file version.
__file_version__ = 8
__file_version__ = 9
__compatible_file_version__ = 1

View File

@@ -83,12 +83,14 @@ class Config:
and the `Repo` instances as values.
"""
repo_config_dict = self._config.get('repos', {})
repo_defaults = self._config.get('defaults', {}).get('repos', {})
repo_dict = {}
repo_fallback_path = os.path.dirname(self.filenames[0])
for repo in repo_config_dict:
repo_config_dict[repo] = repo_config_dict[repo] or {}
repo_dict[repo] = Repo.factory(repo,
repo_config_dict[repo],
repo_defaults,
repo_fallback_path)
return repo_dict

View File

@@ -72,6 +72,21 @@ CONFIGSCHEMA = {
},
},
},
'defaults': {
'type': 'object',
'additionalProperties': False,
'properties': {
'repos': {
'type': 'object',
'additionalProperties': False,
'properties': {
'refspec': {
'type': 'string',
},
},
},
},
},
'machine': {
'type': 'string',
},

View File

@@ -78,7 +78,7 @@ class Repo:
self.path, self._layers)
@staticmethod
def factory(name, repo_config, repo_fallback_path):
def factory(name, repo_config, repo_defaults, repo_fallback_path):
"""
Returns a Repo instance depending on params.
"""
@@ -99,7 +99,8 @@ class Repo:
url = repo_config.get('url', None)
name = repo_config.get('name', name)
typ = repo_config.get('type', 'git')
refspec = repo_config.get('refspec', None)
refspec = repo_config.get('refspec',
repo_defaults.get('refspec', None))
path = repo_config.get('path', None)
disable_operations = False