From ce347f2f8cfdf0999f37c5a48e6580dd597cb5bf Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 11 Sep 2020 14:07:00 -0400 Subject: msubprojects: Fix checkout of new tag/branch If revision is a tag that does not exist locally, `git fetch origin ` won't create it and checkout will fail. Using --refmap ensures that references exists locally. --- mesonbuild/msubprojects.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'mesonbuild/msubprojects.py') 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 " + # 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)) -- cgit v1.1