From 42aa3999be823c2dbe0dd80cae784ff7d9052d31 Mon Sep 17 00:00:00 2001 From: William Salmon Date: Wed, 1 Aug 2018 16:34:40 +0100 Subject: Add warning to git track if track and ref are not present This is to address https://gitlab.com/BuildStream/buildstream/issues/471 that documented unhelpfull behavour when tracking git sources. --- buildstream/_pipeline.py | 20 +++++++++++++++--- buildstream/plugins/sources/git.py | 6 ++++++ tests/sources/git.py | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index f3db2838c..f1e51a05e 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -358,10 +358,24 @@ 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" + + missingTrack = 0 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(): + if hasattr(source, 'tracking') and source.tracking is None: + detail += ": Source {} is missing ref and track. ".format(source._get_full_name()) + \ + "Please specify a ref or branch/tag to track." + missingTrack = 1 + + detail += "\n" + + if missingTrack: + detail += "\nThen track these elements with `bst track`\n" + else: + detail += "\nTry tracking these elements first with `bst track`\n" raise PipelineError("Inconsistent pipeline", detail=detail, reason="inconsistent-pipeline") ############################################################# diff --git a/buildstream/plugins/sources/git.py b/buildstream/plugins/sources/git.py index 32cdcbb97..a7d3ad6e3 100644 --- a/buildstream/plugins/sources/git.py +++ b/buildstream/plugins/sources/git.py @@ -363,6 +363,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 {}" diff --git a/tests/sources/git.py b/tests/sources/git.py index 06888c311..ef18e3ce3 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -359,3 +359,45 @@ 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.STREAM, None) + result.assert_task_error(ErrorDomain.SOURCE, 'track-attempt-no-track') + + # Assert that we are just fine without it, and emit a warning to the user. + assert "FAILURE git source at" in result.stderr + assert "Without a tracking branch ref can not be updated. Please " + \ + "provide a ref or a 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.PIPELINE, 'inconsistent-pipeline') + result.assert_task_error(None, None) + + # Assert that we are just fine without it, and emit a warning to the user. + assert "Exact versions are missing for the following elements" in result.stderr + assert "is missing ref and track." in result.stderr + assert "Then track these elements with `bst track`" in result.stderr -- cgit v1.2.1