diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-05-14 15:14:02 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-06-16 16:04:23 +0000 |
commit | a7748f9cdaaf4112c30d7c15cb17fb45cbded08a (patch) | |
tree | 00e44b102bf4449cb86d31ec667d5ff981b5091b | |
parent | 5477a3a9d785e2b853a68fd5a1b95ebaa38a30b5 (diff) | |
download | morph-a7748f9cdaaf4112c30d7c15cb17fb45cbded08a.tar.gz |
Improve error when local HEAD of definitions repo is not found in remote
Old error:
ERROR: Git directory
/build/cache/gits/git___git_baserock_org_baserock_baserock_definitions
has no commit at ref 5046c3a0e4fd587c23f7c6a9e0d0b50d1914dcca^{commit}.
New error:
ERROR: Commit 5046c3a0e4fd587c23f7c6a9e0d0b50d1914dcca wasn't found
in the "origin" remote
git://git.baserock.org/baserock/baserock/definitions. You either need
to push your local commits on branch xxx to "origin", or use the
--local-changes=include feature.
Change-Id: I0c3658e9cd27c23f40653662ba7e4ba58b7892de
-rw-r--r-- | morphlib/definitions_repo.py | 15 | ||||
-rw-r--r-- | morphlib/sourceresolver.py | 20 | ||||
-rw-r--r-- | tests.build/missing-ref.stderr | 2 |
3 files changed, 30 insertions, 7 deletions
diff --git a/morphlib/definitions_repo.py b/morphlib/definitions_repo.py index 66cdb31c..40aeecff 100644 --- a/morphlib/definitions_repo.py +++ b/morphlib/definitions_repo.py @@ -216,10 +216,17 @@ class DefinitionsRepo(gitdir.GitDirectory): if status_cb: status_cb(msg='Deciding on task order') - yield morphlib.sourceresolver.create_source_pool( - lrc, rrc, repo_url, commit, [system_filename], - cachedir=cachedir, original_ref=ref, update_repos=update_repos, - status_cb=status_cb) + try: + yield morphlib.sourceresolver.create_source_pool( + lrc, rrc, repo_url, commit, [system_filename], + cachedir=cachedir, original_ref=ref, + update_repos=update_repos, status_cb=status_cb) + except morphlib.sourceresolver.InvalidDefinitionsRefError as e: + raise cliapp.AppException( + 'Commit %s wasn\'t found in the "origin" remote %s. ' + 'You either need to push your local commits on branch %s ' + 'to "origin", or use the --local-changes=include feature ' + 'of Morph.' % (e.ref, e.repo_url, ref)) def load_all_morphologies(self, loader): mf = morphlib.morphologyfinder.MorphologyFinder(self) diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py index c1e68db7..47d9502e 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -122,6 +122,18 @@ class InvalidVersionFileError(SourceResolverError): #pragma: no cover SourceResolverError.__init__(self, "invalid VERSION file") +# Callers may want to give the user a special error message if we hit an +# InvalidRefError in the definitions.git repo. Currently a separate exception +# type seems the easiest way to do that, but adding enough detail to the +# gitdir.InvalidRefError class may make this class redundant in future. +class InvalidDefinitionsRefError(SourceResolverError): # pragma: no cover + def __init__(self, repo_url, ref): + self.repo_url = repo_url + self.ref = ref + super(InvalidDefinitionsRefError, self).__init__( + "Ref %s was not found in repo %s." % (ref, repo_url)) + + class SourceResolver(object): '''Provides a way of resolving the set of sources for a given system. @@ -580,8 +592,12 @@ class SourceResolver(object): self.buildsystem_cache_manager.open() as resolved_buildsystems: # Resolve the repo, ref pair for definitions repo, cache result - definitions_absref, definitions_tree = self._resolve_ref( - resolved_trees, definitions_repo, definitions_ref) + try: + definitions_absref, definitions_tree = self._resolve_ref( + resolved_trees, definitions_repo, definitions_ref) + except morphlib.gitdir.InvalidRefError as e: + raise InvalidDefinitionsRefError( + definitions_repo, definitions_ref) if definitions_original_ref: definitions_ref = definitions_original_ref diff --git a/tests.build/missing-ref.stderr b/tests.build/missing-ref.stderr index b5139e25..ac730554 100644 --- a/tests.build/missing-ref.stderr +++ b/tests.build/missing-ref.stderr @@ -1 +1 @@ -ERROR: Git directory TMP/morphs-repo has no commit at ref non-existent-branch^{commit}. +ERROR: Ref non-existent-branch was not found in repo test:morphs-repo. |