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 <tobias.schaffner@siemens.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
parent
d7af4dc678
commit
1c53b817b5
@ -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
|
||||
|
||||
|
@ -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'])
|
||||
|
8
tests/test_refspec/test4.yml
Normal file
8
tests/test_refspec/test4.yml
Normal file
@ -0,0 +1,8 @@
|
||||
header:
|
||||
version: 8
|
||||
|
||||
repos:
|
||||
this:
|
||||
|
||||
kas:
|
||||
url: https://github.com/siemens/kas.git
|
Loading…
Reference in New Issue
Block a user