From a024bd33b808489acc909036b63697a819cc6ce7 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 23:31:06 -0400 Subject: [PATCH] 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 Tested-by: Mike Frysinger --- main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main.py b/main.py index 5c8ea85c..253f3112 100755 --- a/main.py +++ b/main.py @@ -185,9 +185,7 @@ class _Repo(object): print('\nRun `repo help ` 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.