From: Jan Kiszka <
jan.k...@siemens.com>
So far, we assumed that a branch-only repo would be accompanied by a
lock file to pin its commit. But users may forget the latter step or
even do not know about it.
Signed-off-by: Jan Kiszka <
jan.k...@siemens.com>
---
kas/repos.py | 13 +++++++++----
tests/test_refspec.py | 2 +-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/kas/repos.py b/kas/repos.py
index 2ea8a7d..6d7586c 100644
--- a/kas/repos.py
+++ b/kas/repos.py
@@ -239,7 +239,7 @@ class Repo:
f'{self.path} {self.layers}'
__legacy_refspec_warned__ = []
- __no_commit_tag_warned__ = []
+ __no_commit_warned__ = []
@staticmethod
def factory(name, repo_config, repo_defaults, repo_fallback_path,
@@ -296,11 +296,16 @@ class Repo:
'Unsupported mixture of legacy refspec and '
f'commit/tag/branch for repository "{name}"')
refspec = repo_overrides.get('commit', refspec)
- if tag and not commit:
- if name not in Repo.__no_commit_tag_warned__:
+ if not commit and name not in Repo.__no_commit_warned__:
+ if tag:
logging.warning('Using tag without commit for repository '
'"%s" is unsafe as tags are mutable.', name)
- Repo.__no_commit_tag_warned__.append(name)
+ Repo.__no_commit_warned__.append(name)
+ elif branch:
+ logging.warning('Using branch without commit for repository '
+ '"%s" is unsafe. Either add a commit or use '
+ 'a lock file.', name)
+ Repo.__no_commit_warned__.append(name)
path = repo_config.get('path', None)
signed = repo_config.get('signed', False)
signers = repo_config.get('allowed_signers', None) if signed else None
diff --git a/tests/test_refspec.py b/tests/test_refspec.py
index f6365bf..0abf0ba 100644
--- a/tests/test_refspec.py
+++ b/tests/test_refspec.py
@@ -175,7 +175,7 @@ def test_unsafe_tag_warning(capsys, monkeykas, tmpdir):
shutil.copytree('tests/test_refspec', tdir)
monkeykas.chdir(tdir)
# needs to be reset in case other tests ran before
- Repo.__no_commit_tag_warned__ = []
+ Repo.__no_commit_warned__ = []
kas.kas(['shell', 'test2.yml', '-c', 'true'])
assert capsys.readouterr().err.count(
'Using tag without commit for repository "kas4" is unsafe as tags '
--
2.47.3