2020-06-15 22:03:32 +02:00
|
|
|
# kas - setup tool for bitbake based projects
|
|
|
|
#
|
|
|
|
# Copyright (c) Siemens AG, 2019
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
|
|
|
import os
|
2022-02-21 09:25:37 +01:00
|
|
|
import pytest
|
2020-06-15 22:03:32 +02:00
|
|
|
import shutil
|
|
|
|
from kas import kas
|
|
|
|
from kas.libkas import run_cmd
|
2023-05-30 16:13:23 +02:00
|
|
|
from kas.repos import RepoRefError, Repo
|
2020-06-15 22:03:32 +02:00
|
|
|
|
2020-07-02 10:35:31 +02:00
|
|
|
|
|
|
|
def test_refspec_switch(changedir, tmpdir):
|
2020-06-15 22:03:32 +02:00
|
|
|
"""
|
|
|
|
Test that the local git clone is correctly updated when switching
|
|
|
|
between a commit hash refspec and a branch refspec.
|
|
|
|
"""
|
2023-02-12 13:46:35 +01:00
|
|
|
tdir = str(tmpdir / 'test_refspec_switch')
|
2020-06-15 22:03:32 +02:00
|
|
|
shutil.copytree('tests/test_refspec', tdir)
|
|
|
|
os.chdir(tdir)
|
|
|
|
|
|
|
|
kas.kas(['shell', 'test.yml', '-c', 'true'])
|
|
|
|
(rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas',
|
|
|
|
fail=False, liveupdate=False)
|
|
|
|
assert rc != 0
|
|
|
|
assert output.strip() == ''
|
2020-11-06 19:45:14 +01:00
|
|
|
(rc, output) = run_cmd(['git', 'rev-parse', 'HEAD'], cwd='kas',
|
2020-06-15 22:03:32 +02:00
|
|
|
fail=False, liveupdate=False)
|
|
|
|
assert rc == 0
|
|
|
|
assert output.strip() == '907816a5c4094b59a36aec12226e71c461c05b77'
|
|
|
|
(rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas2',
|
|
|
|
fail=False, liveupdate=False)
|
|
|
|
assert rc == 0
|
|
|
|
assert output.strip() == 'refs/heads/master'
|
|
|
|
|
|
|
|
kas.kas(['shell', 'test2.yml', '-c', 'true'])
|
|
|
|
(rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas',
|
|
|
|
fail=False, liveupdate=False)
|
|
|
|
assert rc == 0
|
|
|
|
assert output.strip() == 'refs/heads/master'
|
|
|
|
(rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas2',
|
|
|
|
fail=False, liveupdate=False)
|
|
|
|
assert rc != 0
|
|
|
|
assert output.strip() == ''
|
2020-11-06 19:45:14 +01:00
|
|
|
(rc, output) = run_cmd(['git', 'rev-parse', 'HEAD'], cwd='kas2',
|
2020-06-15 22:03:32 +02:00
|
|
|
fail=False, liveupdate=False)
|
|
|
|
assert rc == 0
|
|
|
|
assert output.strip() == '907816a5c4094b59a36aec12226e71c461c05b77'
|
2021-07-06 15:12:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_refspec_absolute(changedir, tmpdir):
|
|
|
|
"""
|
|
|
|
Test that the local git clone works when a absolute refspec
|
2022-02-21 09:25:37 +01:00
|
|
|
is given.
|
2021-07-06 15:12:51 +02:00
|
|
|
"""
|
2023-02-12 13:46:35 +01:00
|
|
|
tdir = str(tmpdir / 'test_refspec_absolute')
|
2021-07-06 15:12:51 +02:00
|
|
|
shutil.copytree('tests/test_refspec', tdir)
|
|
|
|
os.chdir(tdir)
|
|
|
|
|
|
|
|
kas.kas(['shell', 'test3.yml', '-c', 'true'])
|
|
|
|
(rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'],
|
|
|
|
cwd='kas_abs', fail=False, liveupdate=False)
|
2023-05-28 21:25:38 +02:00
|
|
|
assert rc == 0
|
|
|
|
assert output.strip() == 'refs/heads/master'
|
2021-07-06 15:12:51 +02:00
|
|
|
(rc, output_kas_abs) = run_cmd(['git', 'rev-parse', 'HEAD'],
|
|
|
|
cwd='kas_abs', fail=False, liveupdate=False)
|
|
|
|
assert rc == 0
|
|
|
|
(rc, output_kas_rel) = run_cmd(['git', 'rev-parse', 'HEAD'],
|
|
|
|
cwd='kas_rel', fail=False, liveupdate=False)
|
|
|
|
assert rc == 0
|
|
|
|
assert output_kas_abs.strip() == output_kas_rel.strip()
|
2022-02-21 09:25:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_url_no_refspec(changedir, tmpdir):
|
|
|
|
"""
|
|
|
|
Test that a repository with url but no refspec raises an error.
|
|
|
|
"""
|
2023-02-12 13:46:35 +01:00
|
|
|
tdir = str(tmpdir / 'test_url_no_refspec')
|
2022-02-21 09:25:37 +01:00
|
|
|
shutil.copytree('tests/test_refspec', tdir)
|
|
|
|
os.chdir(tdir)
|
2023-05-04 04:50:18 +02:00
|
|
|
with pytest.raises(RepoRefError):
|
2022-02-21 09:25:37 +01:00
|
|
|
kas.kas(['shell', 'test4.yml', '-c', 'true'])
|
2023-05-30 16:13:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_commit_refspec_mix(changedir, tmpdir):
|
|
|
|
"""
|
|
|
|
Test that mixing legacy refspec with commit/branch raises errors.
|
|
|
|
"""
|
|
|
|
tdir = str(tmpdir / 'test_commit_refspec_mix')
|
|
|
|
shutil.copytree('tests/test_refspec', tdir)
|
|
|
|
os.chdir(tdir)
|
|
|
|
with pytest.raises(RepoRefError):
|
|
|
|
kas.kas(['shell', 'test5.yml', '-c', 'true'])
|
|
|
|
with pytest.raises(RepoRefError):
|
|
|
|
kas.kas(['shell', 'test6.yml', '-c', 'true'])
|
|
|
|
|
|
|
|
|
|
|
|
def test_refspec_warning(capsys, changedir, tmpdir):
|
|
|
|
"""
|
|
|
|
Test that using legacy refspec issues a warning, but only once.
|
|
|
|
"""
|
|
|
|
tdir = str(tmpdir / 'test_refspec_warning')
|
|
|
|
shutil.copytree('tests/test_refspec', tdir)
|
|
|
|
os.chdir(tdir)
|
|
|
|
# needs to be reset in case other tests ran before
|
|
|
|
Repo.__legacy_refspec_warned__ = []
|
|
|
|
kas.kas(['shell', 'test2.yml', '-c', 'true'])
|
|
|
|
assert capsys.readouterr().err.count(
|
|
|
|
'Using deprecated refspec for repository "kas2".') == 1
|