repo: make --version always work

We don't really care what the subcommand is set to when --version
output is requested, so stop enforcing it.  This fixes some weird
behavior like `repo --version version` fails, but `repo --version
help` works.

The new logic skips subcommand validation, so `repo --version asdf`
will still display the version output.  This matches git behavior,
and makes a bit of sense when we consider that the user really wants
to see the tool version, and probably doesn't care about anything
else on the command line.

Change-Id: I87454d473c2c8869344b3888a7affaa2e03f5b0f
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312907
Reviewed-by: Xin Li <delphij@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2021-07-26 23:31:06 -04:00
parent 968d646f04
commit a024bd33b8

View File

@ -185,9 +185,7 @@ class _Repo(object):
print('\nRun `repo help <command>` for command-specific details.') print('\nRun `repo help <command>` for command-specific details.')
return 0 return 0
elif gopts.show_version: elif gopts.show_version:
if name and name != 'help': # Always allow global --version regardless of subcommand validity.
print('fatal: invalid usage of --version', file=sys.stderr)
return 1
name = 'version' name = 'version'
elif not name: elif not name:
# No subcommand specified, so show the help/subcommand. # No subcommand specified, so show the help/subcommand.