aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2020-09-11 14:07:00 -0400
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2020-09-18 03:01:15 +0000
commitce347f2f8cfdf0999f37c5a48e6580dd597cb5bf (patch)
treedb9bee83d2e2430a9ecbc7712c30a8335572e673
parent49b61e476f418cc627cd40ca6aa5b8169ec48943 (diff)
downloadmeson-ce347f2f8cfdf0999f37c5a48e6580dd597cb5bf.zip
meson-ce347f2f8cfdf0999f37c5a48e6580dd597cb5bf.tar.gz
meson-ce347f2f8cfdf0999f37c5a48e6580dd597cb5bf.tar.bz2
msubprojects: Fix checkout of new tag/branch
If revision is a tag that does not exist locally, `git fetch origin <revision>` won't create it and checkout will fail. Using --refmap ensures that references exists locally.
-rwxr-xr-xmesonbuild/msubprojects.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py
index c06aa0b..9ae0061 100755
--- a/mesonbuild/msubprojects.py
+++ b/mesonbuild/msubprojects.py
@@ -127,11 +127,16 @@ def update_git(wrap, repo_dir, options):
mlog.log(mlog.red(e.output))
mlog.log(mlog.red(str(e)))
return False
- # Fetch only the revision we need, this avoids fetching useless branches and
- # is needed for http case were new remote branches wouldn't be discovered
- # otherwise. After this command, FETCH_HEAD is the revision we want.
try:
- git_output(['fetch', 'origin', revision], repo_dir)
+ # Fetch only the revision we need, this avoids fetching useless branches.
+ # revision can be either a branch, tag or commit id. In all cases we want
+ # FETCH_HEAD to be set to the desired commit and "git checkout <revision>"
+ # to to either switch to existing/new branch, or detach to tag/commit.
+ # It is more complicated than it first appear, see discussion there:
+ # https://github.com/mesonbuild/meson/pull/7723#discussion_r488816189.
+ heads_refmap = '+refs/heads/*:refs/remotes/origin/*'
+ tags_refmap = '+refs/tags/*:refs/tags/*'
+ git_output(['fetch', '--refmap', heads_refmap, '--refmap', tags_refmap, 'origin', revision], repo_dir)
except GitException as e:
mlog.log(' -> Could not fetch revision', mlog.bold(revision), 'in', mlog.bold(repo_dir))
mlog.log(mlog.red(e.output))