From 401c6f072564966437a74dc2f33280a85d79dc84 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 18 Feb 2021 15:20:15 -0500 Subject: [PATCH] init: make --manifest-url flag optional Since the --manifest-url flag is always required when creating a new checkout, allow the url to be specified via a positional argument. This brings it a little closer to the `git clone` UI. Change-Id: Iaf18e794ae2fa38b20579243d067205cae5fae2f Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297322 Tested-by: Mike Frysinger Reviewed-by: Jonathan Nieder --- repo | 11 +++++++---- subcmds/init.py | 20 ++++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/repo b/repo index 63cee031..1bc78b89 100755 --- a/repo +++ b/repo @@ -270,9 +270,9 @@ gpg_dir = os.path.join(home_dot_repo, 'gnupg') def GetParser(gitc_init=False): """Setup the CLI parser.""" if gitc_init: - usage = 'repo gitc-init -u url -c client [options]' + usage = 'repo gitc-init -c client [options] [-u] url' else: - usage = 'repo init -u url [options]' + usage = 'repo init [options] [-u] url' parser = optparse.OptionParser(usage=usage) @@ -522,8 +522,11 @@ def _Init(args, gitc_init=False): parser = GetParser(gitc_init=gitc_init) opt, args = parser.parse_args(args) if args: - parser.print_usage() - sys.exit(1) + if not opt.manifest_url: + opt.manifest_url = args.pop(0) + if args: + parser.print_usage() + sys.exit(1) opt.quiet = opt.output_mode is False opt.verbose = opt.output_mode is True diff --git a/subcmds/init.py b/subcmds/init.py index 1d16c856..ab0faff3 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -32,9 +32,9 @@ from wrapper import Wrapper class Init(InteractiveCommand, MirrorSafeCommand): common = True - helpSummary = "Initialize repo in the current directory" + helpSummary = "Initialize a repo client checkout in the current directory" helpUsage = """ -%prog [options] +%prog [options] [manifest url] """ helpDescription = """ The '%prog' command is run once to install and initialize repo. @@ -42,6 +42,10 @@ The latest repo source code and manifest collection is downloaded from the server and is installed in the .repo/ directory in the current working directory. +When creating a new checkout, the manifest URL is the only required setting. +It may be specified using the --manifest-url option, or as the first optional +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. @@ -196,7 +200,7 @@ to update the working directory files. if is_new: if not opt.manifest_url: - print('fatal: manifest url (-u) is required.', file=sys.stderr) + print('fatal: manifest url is required.', file=sys.stderr) sys.exit(1) if not opt.quiet: @@ -498,7 +502,15 @@ to update the working directory files. self.OptionParser.error('--mirror and --archive cannot be used together.') if args: - self.OptionParser.error('init takes no arguments') + if opt.manifest_url: + self.OptionParser.error( + '--manifest-url option and URL argument both specified: only use ' + 'one to select the manifest URL.') + + opt.manifest_url = args.pop(0) + + if args: + self.OptionParser.error('too many arguments to init') def Execute(self, opt, args): git_require(MIN_GIT_VERSION_HARD, fail=True)