From 1c53b817b509533a41444f34e428fde83d1d91ac Mon Sep 17 00:00:00 2001 From: Tobias Schaffner Date: Mon, 21 Feb 2022 09:25:37 +0100 Subject: [PATCH] fix: Raise an error if no refspec is provided Only local repositories may be configured without refspec. Raise an error if a repository url is given but refspec is not. Signed-off-by: Tobias Schaffner Signed-off-by: Jan Kiszka --- kas/repos.py | 4 ++++ tests/test_refspec.py | 15 ++++++++++++++- tests/test_refspec/test4.yml | 8 ++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/test_refspec/test4.yml diff --git a/kas/repos.py b/kas/repos.py index 1eb2e5c..b614374 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -111,6 +111,10 @@ class Repo: typ = repo_config.get('type', 'git') refspec = repo_config.get('refspec', repo_defaults.get('refspec', None)) + if refspec is None and url is not None: + logging.error('No refspec specified for repository "%s". This is ' + 'only allowed for local repositories.', name) + sys.exit(1) path = repo_config.get('path', None) disable_operations = False diff --git a/tests/test_refspec.py b/tests/test_refspec.py index edb798e..b942969 100644 --- a/tests/test_refspec.py +++ b/tests/test_refspec.py @@ -21,6 +21,7 @@ # SOFTWARE. import os +import pytest import shutil from kas import kas from kas.libkas import run_cmd @@ -68,7 +69,7 @@ def test_refspec_switch(changedir, tmpdir): def test_refspec_absolute(changedir, tmpdir): """ Test that the local git clone works when a absolute refspec - is givvn. + is given. """ tdir = str(tmpdir.mkdir('test_refspec_absolute')) shutil.rmtree(tdir, ignore_errors=True) @@ -87,3 +88,15 @@ def test_refspec_absolute(changedir, tmpdir): cwd='kas_rel', fail=False, liveupdate=False) assert rc == 0 assert output_kas_abs.strip() == output_kas_rel.strip() + + +def test_url_no_refspec(changedir, tmpdir): + """ + Test that a repository with url but no refspec raises an error. + """ + tdir = str(tmpdir.mkdir('test_url_no_refspec')) + shutil.rmtree(tdir, ignore_errors=True) + shutil.copytree('tests/test_refspec', tdir) + os.chdir(tdir) + with pytest.raises(SystemExit): + kas.kas(['shell', 'test4.yml', '-c', 'true']) diff --git a/tests/test_refspec/test4.yml b/tests/test_refspec/test4.yml new file mode 100644 index 0000000..96cbf10 --- /dev/null +++ b/tests/test_refspec/test4.yml @@ -0,0 +1,8 @@ +header: + version: 8 + +repos: + this: + + kas: + url: https://github.com/siemens/kas.git