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>
diff --git a/main.py b/main.py
index 5c8ea85..253f311 100755
--- a/main.py
+++ b/main.py
@@ -185,9 +185,7 @@
print('\nRun `repo help <command>` for command-specific details.')
return 0
elif gopts.show_version:
- if name and name != 'help':
- print('fatal: invalid usage of --version', file=sys.stderr)
- return 1
+ # Always allow global --version regardless of subcommand validity.
name = 'version'
elif not name:
# No subcommand specified, so show the help/subcommand.