Skip to content
Snippets Groups Projects
Commit b92a6789 authored by William Salmon's avatar William Salmon
Browse files

Add Error to git track if track and ref are not present

This is to address #471 that
documented unhelpfull behavour when tracking git sources.

It is a back port of
!580 and
!628
parent f5683244
No related branches found
No related tags found
No related merge requests found
Pipeline #27541227 passed
......@@ -358,10 +358,15 @@ class Pipeline():
inconsistent.append(element)
if inconsistent:
detail = "Exact versions are missing for the following elements\n" + \
"Try tracking these elements first with `bst track`\n\n"
detail = "Exact versions are missing for the following elements:\n\n"
for element in inconsistent:
detail += " " + element._get_full_name() + "\n"
detail += " " + element._get_full_name()
for source in element.sources():
if not source._get_consistency() and not source.get_ref():
detail += ": Source {} is missing ref\n".format(source)
detail += "\nTry tracking these elements first with `bst track`\n"
raise PipelineError("Inconsistent pipeline", detail=detail, reason="inconsistent-pipeline")
#############################################################
......
......@@ -80,6 +80,7 @@ from configparser import RawConfigParser
from buildstream import Source, SourceError, Consistency, SourceFetcher
from buildstream import utils
from buildstream._exceptions import LoadError, LoadErrorReason
GIT_MODULES = '.gitmodules'
......@@ -296,6 +297,12 @@ class GitSource(Source):
self.original_url = self.node_get_member(node, str, 'url')
self.mirror = GitMirror(self, '', self.original_url, ref)
self.tracking = self.node_get_member(node, str, 'track', None)
# At this point we now know if the source has a ref and/or a track.
# If it is missing both then we will be unable to track or build.
if self.mirror.ref is None and self.tracking is None:
raise LoadError(LoadErrorReason.INVALID_DATA, "{}: Git sources require a ref and/or track".format(self))
self.checkout_submodules = self.node_get_member(node, bool, 'checkout-submodules', True)
self.submodules = []
......@@ -359,6 +366,12 @@ class GitSource(Source):
# If self.tracking is not specified it's not an error, just silently return
if not self.tracking:
# Is there a better way to check if a ref is given.
if self.mirror.ref is None:
detail = 'Without a tracking branch ref can not be updated. Please ' + \
'provide a ref or a track.'
raise SourceError("{}: No track or ref".format(self),
detail=detail, reason="track-attempt-no-track")
return None
with self.timed_activity("Tracking {} from {}"
......
import os
import pytest
from buildstream._exceptions import ErrorDomain
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream import _yaml
from tests.testutils import cli, create_repo
......@@ -359,3 +359,41 @@ def test_submodule_track_ignore_inconsistent(cli, tmpdir, datafiles):
# Assert that we are just fine without it, and emit a warning to the user.
assert "Ignoring inconsistent submodule" in result.stderr
@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_no_ref_or_track(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
gitsource = repo.source_config(ref=None)
gitsource.pop('track')
element = {
'kind': 'import',
'sources': [
gitsource
]
}
_yaml.dump(element, os.path.join(project, 'target.bst'))
# Track will encounter an inconsistent submodule without any ref
result = cli.run(project=project, args=['track', 'target.bst'])
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
result.assert_task_error(None, None)
# Assert that we are just fine without it, and emit a warning to the user.
assert "Git sources require a ref and/or track" in result.stderr
# Track will encounter an inconsistent submodule without any ref
result = cli.run(project=project, args=['build', 'target.bst'])
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
result.assert_task_error(None, None)
# Assert that we are just fine without it, and emit a warning to the user.
assert "Git sources require a ref and/or track" in result.stderr
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment