summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-03-21 22:04:44 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-03-22 00:58:40 +0900
commit54ba73241bb812a3b69e3da5cb8ed8c6d2cfbb38 (patch)
treed328fa2ae5d5a7eeb6ee56d58fbf142147a16995
parent0f62dd05c9aaf6cb7e055f6d3cde375aa5998f47 (diff)
downloadbuildstream-54ba73241bb812a3b69e3da5cb8ed8c6d2cfbb38.tar.gz
tests/sources/git.py: Test that we ignore inconsistent submodules.
Test this at `bst track` time, when encountering a new ref which adds a .gitmodules file but does not actually add the submodule, we check that the expected warning is in the stderr and that BuildStream does not error out for this.
-rw-r--r--tests/sources/git.py37
-rw-r--r--tests/sources/git/template/inconsistent-submodule/.gitmodules3
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py
index b2e336811..bc69d0579 100644
--- a/tests/sources/git.py
+++ b/tests/sources/git.py
@@ -322,3 +322,40 @@ def test_submodule_fetch_project_override(cli, tmpdir, datafiles):
# Assert we checked out both files at their expected location
assert os.path.exists(os.path.join(checkoutdir, 'file.txt'))
assert not os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt'))
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
+def test_submodule_track_ignore_inconsistent(cli, tmpdir, datafiles):
+ 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'))
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref)
+ ]
+ }
+ _yaml.dump(element, os.path.join(project, 'target.bst'))
+
+ # Now add a .gitmodules file with an inconsistent submodule,
+ # we are calling this inconsistent because the file was created
+ # but `git submodule add` was never called, so there is no reference
+ # associated to the submodule.
+ #
+ repo.add_file(os.path.join(project, 'inconsistent-submodule', '.gitmodules'))
+
+ # Fetch should work, we're not yet at the offending ref
+ result = cli.run(project=project, args=['fetch', 'target.bst'])
+ result.assert_success()
+
+ # Track will encounter an inconsistent submodule without any ref
+ result = cli.run(project=project, args=['track', 'target.bst'])
+ result.assert_success()
+
+ # Assert that we are just fine without it, and emit a warning to the user.
+ assert "Ignoring inconsistent submodule" in result.stderr
diff --git a/tests/sources/git/template/inconsistent-submodule/.gitmodules b/tests/sources/git/template/inconsistent-submodule/.gitmodules
new file mode 100644
index 000000000..67271b8a7
--- /dev/null
+++ b/tests/sources/git/template/inconsistent-submodule/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "farm/pony"]
+ path = farm/pony
+ url = git://pony.com