summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-02-18 15:20:15 -0500
committerMike Frysinger <vapier@google.com>2021-02-18 20:38:47 +0000
commit401c6f072564966437a74dc2f33280a85d79dc84 (patch)
tree0b90116d29056d8cd6e1d492cbe37b516e633b6c
parent8c1e9e62a3214a7ab5feeb7ce194ca153cc8afb1 (diff)
downloadgit-repo-401c6f072564966437a74dc2f33280a85d79dc84.tar.gz
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>
-rwxr-xr-xrepo11
-rw-r--r--subcmds/init.py20
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')
270def GetParser(gitc_init=False): 270def GetParser(gitc_init=False):
271 """Setup the CLI parser.""" 271 """Setup the CLI parser."""
272 if gitc_init: 272 if gitc_init:
273 usage = 'repo gitc-init -u url -c client [options]' 273 usage = 'repo gitc-init -c client [options] [-u] url'
274 else: 274 else:
275 usage = 'repo init -u url [options]' 275 usage = 'repo init [options] [-u] url'
276 276
277 parser = optparse.OptionParser(usage=usage) 277 parser = optparse.OptionParser(usage=usage)
278 278
@@ -522,8 +522,11 @@ def _Init(args, gitc_init=False):
522 parser = GetParser(gitc_init=gitc_init) 522 parser = GetParser(gitc_init=gitc_init)
523 opt, args = parser.parse_args(args) 523 opt, args = parser.parse_args(args)
524 if args: 524 if args:
525 parser.print_usage() 525 if not opt.manifest_url:
526 sys.exit(1) 526 opt.manifest_url = args.pop(0)
527 if args:
528 parser.print_usage()
529 sys.exit(1)
527 opt.quiet = opt.output_mode is False 530 opt.quiet = opt.output_mode is False
528 opt.verbose = opt.output_mode is True 531 opt.verbose = opt.output_mode is True
529 532
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
32 32
33class Init(InteractiveCommand, MirrorSafeCommand): 33class Init(InteractiveCommand, MirrorSafeCommand):
34 common = True 34 common = True
35 helpSummary = "Initialize repo in the current directory" 35 helpSummary = "Initialize a repo client checkout in the current directory"
36 helpUsage = """ 36 helpUsage = """
37%prog [options] 37%prog [options] [manifest url]
38""" 38"""
39 helpDescription = """ 39 helpDescription = """
40The '%prog' command is run once to install and initialize repo. 40The '%prog' command is run once to install and initialize repo.
@@ -42,6 +42,10 @@ The latest repo source code and manifest collection is downloaded
42from the server and is installed in the .repo/ directory in the 42from the server and is installed in the .repo/ directory in the
43current working directory. 43current working directory.
44 44
45When creating a new checkout, the manifest URL is the only required setting.
46It may be specified using the --manifest-url option, or as the first optional
47argument.
48
45The optional -b argument can be used to select the manifest branch 49The optional -b argument can be used to select the manifest branch
46to checkout and use. If no branch is specified, the remote's default 50to checkout and use. If no branch is specified, the remote's default
47branch is used. 51branch is used.
@@ -196,7 +200,7 @@ to update the working directory files.
196 200
197 if is_new: 201 if is_new:
198 if not opt.manifest_url: 202 if not opt.manifest_url:
199 print('fatal: manifest url (-u) is required.', file=sys.stderr) 203 print('fatal: manifest url is required.', file=sys.stderr)
200 sys.exit(1) 204 sys.exit(1)
201 205
202 if not opt.quiet: 206 if not opt.quiet:
@@ -498,7 +502,15 @@ to update the working directory files.
498 self.OptionParser.error('--mirror and --archive cannot be used together.') 502 self.OptionParser.error('--mirror and --archive cannot be used together.')
499 503
500 if args: 504 if args:
501 self.OptionParser.error('init takes no arguments') 505 if opt.manifest_url:
506 self.OptionParser.error(
507 '--manifest-url option and URL argument both specified: only use '
508 'one to select the manifest URL.')
509
510 opt.manifest_url = args.pop(0)
511
512 if args:
513 self.OptionParser.error('too many arguments to init')
502 514
503 def Execute(self, opt, args): 515 def Execute(self, opt, args):
504 git_require(MIN_GIT_VERSION_HARD, fail=True) 516 git_require(MIN_GIT_VERSION_HARD, fail=True)