wrap clone: be less noisy when doing automated code checkouts

There are two possible issues, both of which emit very long messages
from git:
- when shallow cloning via depth + a pinned commit we locally init
  rather than cloning; use an almost-certainly not conflicting dummy
  branch name
- any time a checkout of a revision is performed, it might not be a
  branch name, in which case it will be a detached HEAD. By default git
  is very noisy about this -- it wants you to know what happened and how
  not to mess up. But wraps aren't per default intended for user editing
  and development, it's just part of the internal transport which meson
  uses. So, temporarily squelch this advice. Do not permanently
  configure the repo like this though, because the user *might* cd in
  and start developing on the subproject; in this case, any additional
  git advice they trigger is their responsibility (and they probably do
  want it).

Fixes #9318
pull/9347/head
Eli Schwartz 3 years ago
parent 6b8f10cf6b
commit b57b1050a6
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 9
      mesonbuild/wrap/wrap.py

@ -401,6 +401,7 @@ class Resolver:
if not GIT:
raise WrapException(f'Git program not found, cannot download {self.packagename}.wrap via git.')
revno = self.wrap.get('revision')
checkout_cmd = ['-c', 'advice.detachedHead=false', 'checkout', revno, '--']
is_shallow = False
depth_option = [] # type: T.List[str]
if self.wrap.values.get('depth', '') != '':
@ -410,11 +411,11 @@ class Resolver:
if is_shallow and self.is_git_full_commit_id(revno):
# git doesn't support directly cloning shallowly for commits,
# so we follow https://stackoverflow.com/a/43136160
verbose_git(['init', self.directory], self.subdir_root, check=True)
verbose_git(['init', '-b', 'meson-dummy-branch', self.directory], self.subdir_root, check=True)
verbose_git(['remote', 'add', 'origin', self.wrap.get('url')], self.dirname, check=True)
revno = self.wrap.get('revision')
verbose_git(['fetch', *depth_option, 'origin', revno], self.dirname, check=True)
verbose_git(['checkout', revno, '--'], self.dirname, check=True)
verbose_git(checkout_cmd, self.dirname, check=True)
if self.wrap.values.get('clone-recursive', '').lower() == 'true':
verbose_git(['submodule', 'update', '--init', '--checkout',
'--recursive', *depth_option], self.dirname, check=True)
@ -425,9 +426,9 @@ class Resolver:
if not is_shallow:
verbose_git(['clone', self.wrap.get('url'), self.directory], self.subdir_root, check=True)
if revno.lower() != 'head':
if not verbose_git(['checkout', revno, '--'], self.dirname):
if not verbose_git(checkout_cmd, self.dirname):
verbose_git(['fetch', self.wrap.get('url'), revno], self.dirname, check=True)
verbose_git(['checkout', revno, '--'], self.dirname, check=True)
verbose_git(checkout_cmd, self.dirname, check=True)
else:
verbose_git(['clone', *depth_option, '--branch', revno, self.wrap.get('url'),
self.directory], self.subdir_root, check=True)

Loading…
Cancel
Save