project.py: --initial-branch=placeholder to silence verbose warning

Silences the following, verbose and repetive warning quoted below when
using git >= 2.28

As this warning is 10 lines long and there are 40 projects in zephyr
right now, this cuts stderr for `west init` almost in half, from ~950
lines down to ~550 lines.

The non @static-ness of the git methods explained in PR #494 has to
"leak" to ensure_cloned(), at least for now. A single Update object
downloads all projects so this does not cause git --version to be
invoked many times.

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2021-04-05 14:42:58 -07:00 committed by Marti Bolivar
parent aba4164ca9
commit c5617a0315
1 changed files with 11 additions and 1 deletions

View File

@ -1117,7 +1117,17 @@ class Update(_ProjectCommand):
if cache_dir is None:
log.small_banner(f'{project.name}: initializing')
project.git(['init', project.abspath], cwd=self.topdir)
init_cmd = ['init', project.abspath]
# Silence the very verbose and repetitive init.defaultBranch
# warning (10 lines per new git clone). The branch
# 'placeholder' will never have any commit so it will never
# actually exist.
if self.git_version_info >= (2, 28, 0):
init_cmd.insert(1, '--initial-branch=init_placeholder')
project.git(init_cmd, cwd=self.topdir)
# This remote is added as a convenience for the user.
# However, west always fetches project data by URL, not name.
# The user is therefore free to change the URL of this remote.