From 4568482316f63c48559b97c9a4771740ed61eca6 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 19 Sep 2021 11:28:20 -0400 Subject: [PATCH] msubprojects: if fetching the remote fails, gracefully fallback to local copy This command is useful to e.g. update a cloned subproject which does not have its packagefiles merged, or which has updated packagefiles. This does not strictly require internet, so if we can satisfy the ref, simply log a warning and continue. This enables a workflow where for network-isolated builds, the subproject is cloned and moved into place and later on the build orchestrator runs `meson subprojects update` without a network interface to initialize the subproject. --- mesonbuild/msubprojects.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py index b058f5bb7..c9081ba5b 100755 --- a/mesonbuild/msubprojects.py +++ b/mesonbuild/msubprojects.py @@ -261,9 +261,14 @@ class Runner: self.git_output(['fetch', '--refmap', heads_refmap, '--refmap', tags_refmap, 'origin', revision]) except GitException as e: self.log(' -> Could not fetch revision', mlog.bold(revision), 'in', mlog.bold(self.repo_dir)) - self.log(mlog.red(e.output)) - self.log(mlog.red(str(e))) - return False + if quiet_git(['rev-parse', revision + '^{commit}'], self.repo_dir)[0]: + self.log(mlog.yellow('WARNING:'), 'Proceeding with locally available copy') + # Trick git into setting FETCH_HEAD from the local revision. + quiet_git(['fetch', '.', revision], self.repo_dir) + else: + self.log(mlog.red(e.output)) + self.log(mlog.red(str(e))) + return False if branch == '': # We are currently in detached mode