diff --git a/docs/format-changelog.rst b/docs/format-changelog.rst index 6386ca4..ecb0a61 100644 --- a/docs/format-changelog.rst +++ b/docs/format-changelog.rst @@ -75,3 +75,13 @@ Added - ``patches`` property to ``repos`` to be able to apply additional patches to the repo. + +Version 9 +--------- + +Added +~~~~~ + +- ``defaults`` key can now be used to set a default value for the repository + property ``refspec``. This default value will be used if the appropriate + property is not defined for a given repository. diff --git a/docs/userguide.rst b/docs/userguide.rst index 9bc5803..e67857f 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -310,6 +310,22 @@ Configuration reference * ``file``: string [required] The path to the file relative to the root of the repository. +* ``defaults``: dict [optional] + This key can be used to set default values for various properties. + This may help you to avoid repeating the same property assignment in + multiple places if, for example, you wish to use the same refspec for + all repositories. + + * ``repos``: dict [optional] + This key can contain default values for some repository properties. + If a default value is set for a repository property it may still be + overridden by setting the same property to a different value in a given + repository. + + * ``refspec``: string [optional] + Sets the default ``refspec`` property applied to all repositories that + do not override this. + * ``machine``: string [optional] Contains the value of the ``MACHINE`` variable that is written into the ``local.conf``. Can be overwritten by the ``KAS_MACHINE`` environment diff --git a/kas/__version__.py b/kas/__version__.py index f2ead14..684c085 100644 --- a/kas/__version__.py +++ b/kas/__version__.py @@ -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 diff --git a/kas/config.py b/kas/config.py index a0597d6..ba159f3 100644 --- a/kas/config.py +++ b/kas/config.py @@ -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 diff --git a/kas/configschema.py b/kas/configschema.py index bccfcb5..89522e8 100644 --- a/kas/configschema.py +++ b/kas/configschema.py @@ -72,6 +72,21 @@ CONFIGSCHEMA = { }, }, }, + 'defaults': { + 'type': 'object', + 'additionalProperties': False, + 'properties': { + 'repos': { + 'type': 'object', + 'additionalProperties': False, + 'properties': { + 'refspec': { + 'type': 'string', + }, + }, + }, + }, + }, 'machine': { 'type': 'string', }, diff --git a/kas/repos.py b/kas/repos.py index 0031814..a4dbb1c 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -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