From 23882b33feaa0104dcbe372a9fde496cffc2b246 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 23 Feb 2021 15:43:07 -0500 Subject: [PATCH] init: support -b HEAD as a shortcut to "the default" When people switch to non-default branches, they sometimes want to switch back to the default, but don't know the exact name for that branch. Add a -b HEAD shortcut for that. Change-Id: I090230da25f9f5a169608115d483f660f555624f Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297843 Reviewed-by: Michael Mortensen Tested-by: Mike Frysinger --- repo | 4 ++-- subcmds/init.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/repo b/repo index 1bc78b89..d32a84b9 100755 --- a/repo +++ b/repo @@ -289,8 +289,8 @@ def GetParser(gitc_init=False): group = parser.add_option_group('Manifest options') group.add_option('-u', '--manifest-url', help='manifest repository location', metavar='URL') - group.add_option('-b', '--manifest-branch', - help='manifest branch or revision', metavar='REVISION') + group.add_option('-b', '--manifest-branch', metavar='REVISION', + help='manifest branch or revision (use HEAD for default)') group.add_option('-m', '--manifest-name', help='initial manifest file', metavar='NAME.xml') cbr_opts = ['--current-branch'] diff --git a/subcmds/init.py b/subcmds/init.py index ab0faff3..fc446045 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -48,7 +48,7 @@ argument. The optional -b argument can be used to select the manifest branch to checkout and use. If no branch is specified, the remote's default -branch is used. +branch is used. This is equivalent to using -b HEAD. The optional -m argument can be used to specify an alternate manifest to be used. If no manifest is specified, the manifest default.xml @@ -94,9 +94,8 @@ to update the working directory files. g.add_option('-u', '--manifest-url', dest='manifest_url', help='manifest repository location', metavar='URL') - g.add_option('-b', '--manifest-branch', - dest='manifest_branch', - help='manifest branch or revision', metavar='REVISION') + g.add_option('-b', '--manifest-branch', metavar='REVISION', + help='manifest branch or revision (use HEAD for default)') cbr_opts = ['--current-branch'] # The gitc-init subcommand allocates -c itself, but a lot of init users # want -c, so try to satisfy both as best we can. @@ -232,6 +231,11 @@ to update the working directory files. r.Save() if opt.manifest_branch: + if opt.manifest_branch == 'HEAD': + opt.manifest_branch = m.ResolveRemoteHead() + if opt.manifest_branch is None: + print('fatal: unable to resolve HEAD', file=sys.stderr) + sys.exit(1) m.revisionExpr = opt.manifest_branch else: if is_new: