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 <vapier@google.com>
Reviewed-by: Jonathan Nieder <jrn@google.com>
diff --git a/repo b/repo
index 63cee03..1bc78b8 100755
--- a/repo
+++ b/repo
@@ -270,9 +270,9 @@
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 @@
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 1d16c85..ab0faff 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -32,9 +32,9 @@
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 @@
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 @@
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 @@
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)