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>
This commit is contained in:
Mike Frysinger 2021-02-18 15:20:15 -05:00
parent 8c1e9e62a3
commit 401c6f0725
2 changed files with 23 additions and 8 deletions

7
repo
View File

@ -270,9 +270,9 @@ gpg_dir = os.path.join(home_dot_repo, 'gnupg')
def GetParser(gitc_init=False): def GetParser(gitc_init=False):
"""Setup the CLI parser.""" """Setup the CLI parser."""
if gitc_init: if gitc_init:
usage = 'repo gitc-init -u url -c client [options]' usage = 'repo gitc-init -c client [options] [-u] url'
else: else:
usage = 'repo init -u url [options]' usage = 'repo init [options] [-u] url'
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
@ -521,6 +521,9 @@ def _Init(args, gitc_init=False):
""" """
parser = GetParser(gitc_init=gitc_init) parser = GetParser(gitc_init=gitc_init)
opt, args = parser.parse_args(args) opt, args = parser.parse_args(args)
if args:
if not opt.manifest_url:
opt.manifest_url = args.pop(0)
if args: if args:
parser.print_usage() parser.print_usage()
sys.exit(1) sys.exit(1)

View File

@ -32,9 +32,9 @@ from wrapper import Wrapper
class Init(InteractiveCommand, MirrorSafeCommand): class Init(InteractiveCommand, MirrorSafeCommand):
common = True common = True
helpSummary = "Initialize repo in the current directory" helpSummary = "Initialize a repo client checkout in the current directory"
helpUsage = """ helpUsage = """
%prog [options] %prog [options] [manifest url]
""" """
helpDescription = """ helpDescription = """
The '%prog' command is run once to install and initialize repo. 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 from the server and is installed in the .repo/ directory in the
current working directory. 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 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 to checkout and use. If no branch is specified, the remote's default
branch is used. branch is used.
@ -196,7 +200,7 @@ to update the working directory files.
if is_new: if is_new:
if not opt.manifest_url: 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) sys.exit(1)
if not opt.quiet: if not opt.quiet:
@ -498,7 +502,15 @@ to update the working directory files.
self.OptionParser.error('--mirror and --archive cannot be used together.') self.OptionParser.error('--mirror and --archive cannot be used together.')
if args: 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): def Execute(self, opt, args):
git_require(MIN_GIT_VERSION_HARD, fail=True) git_require(MIN_GIT_VERSION_HARD, fail=True)