From 50a81de2bc9f2074d56c368f651cf9f50c8d8a87 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 6 Sep 2020 15:51:21 -0400 Subject: init: use the remote default manifest branch Instead of hardcoding "master" as our default, use the remote server's default branch instead. For most people, this should be the same as "master" already. For projects moving to "main", it means we'll use the new name automatically rather than forcing people to use -b main. For repositories that never set up a default HEAD, we should still use the historical "master" default. Bug: https://crbug.com/gerrit/13339 Change-Id: I4117c81a760c9495f98dbb1111a3e6c127f45eba Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/280799 Reviewed-by: Michael Mortensen Tested-by: Mike Frysinger --- subcmds/init.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'subcmds/init.py') diff --git a/subcmds/init.py b/subcmds/init.py index 41578076..5ba0d074 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -54,7 +54,8 @@ from the server and is installed in the .repo/ directory in the current working directory. The optional -b argument can be used to select the manifest branch -to checkout and use. If no branch is specified, master is assumed. +to checkout and use. If no branch is specified, the remote's default +branch is used. The optional -m argument can be used to specify an alternate manifest to be used. If no manifest is specified, the manifest default.xml @@ -215,24 +216,27 @@ to update the working directory files. m._InitGitDir(mirror_git=mirrored_manifest_git) - if opt.manifest_branch: - m.revisionExpr = opt.manifest_branch - else: - m.revisionExpr = 'refs/heads/master' - else: - if opt.manifest_branch: - m.revisionExpr = opt.manifest_branch - else: - m.PreSync() - self._ConfigureDepth(opt) + # Set the remote URL before the remote branch as we might need it below. if opt.manifest_url: r = m.GetRemote(m.remote.name) r.url = opt.manifest_url r.ResetFetch() r.Save() + if opt.manifest_branch: + m.revisionExpr = opt.manifest_branch + else: + if is_new: + default_branch = m.ResolveRemoteHead() + if default_branch is None: + # If the remote doesn't have HEAD configured, default to master. + default_branch = 'refs/heads/master' + m.revisionExpr = default_branch + else: + m.PreSync() + groups = re.split(r'[,\s]+', opt.groups) all_platforms = ['linux', 'darwin', 'windows'] platformize = lambda x: 'platform-' + x -- cgit v1.2.3-54-g00ecf