summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2018-09-23 16:55:08 +0200
committerTristan van Berkom <tristan.vanberkom@codethink.co.uk>2019-08-04 12:16:28 -0400
commit36e42c7dc6f027ada7bdd72f19ec87d031828e05 (patch)
tree0cad63915cd9773256f6ab165a0957fdcc376315
parent7fedcb4ae322d76e60584e9f0f07299ef805afb8 (diff)
downloadbuildstream-36e42c7dc6f027ada7bdd72f19ec87d031828e05.tar.gz
tests/sources/git.py: Add track and fetch test with and without tag
-rw-r--r--tests/sources/git.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py
index e7daa95a7..9b59e30fb 100644
--- a/tests/sources/git.py
+++ b/tests/sources/git.py
@@ -481,6 +481,53 @@ def test_ref_not_in_track_warn_error(cli, tmpdir, datafiles):
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
+@pytest.mark.parametrize("ref_format", ['sha1', 'git-describe'])
+@pytest.mark.parametrize("tag,extra_commit", [(False, False), (True, False), (True, True)])
+def test_track_fetch(cli, tmpdir, datafiles, ref_format, tag, extra_commit):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ # Create the repo from 'repofiles' subdir
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(os.path.join(project, 'repofiles'))
+ if tag:
+ repo.add_tag('tag')
+ if extra_commit:
+ repo.add_commit()
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config()
+ ]
+ }
+ element['sources'][0]['ref-format'] = ref_format
+ element_path = os.path.join(project, 'target.bst')
+ _yaml.dump(element, element_path)
+
+ # Track it
+ result = cli.run(project=project, args=['track', 'target.bst'])
+ result.assert_success()
+
+ element = _yaml.load(element_path)
+ new_ref = element['sources'][0]['ref']
+
+ if ref_format == 'git-describe' and tag:
+ # Check and strip prefix
+ prefix = 'tag-{}-g'.format(0 if not extra_commit else 1)
+ assert new_ref.startswith(prefix)
+ new_ref = new_ref[len(prefix):]
+
+ # 40 chars for SHA-1
+ assert len(new_ref) == 40
+
+ # Fetch it
+ result = cli.run(project=project, args=['fetch', 'target.bst'])
+ result.assert_success()
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
@pytest.mark.parametrize("fail", ['warn', 'error'])
def test_unlisted_submodule(cli, tmpdir, datafiles, fail):
project = os.path.join(datafiles.dirname, datafiles.basename)