Merge branch 'ab/do-not-limit-stash-help-to-push'

"git stash" by default triggers its "push" action, but its
implementation also made "git stash -h" to show short help only for
"git stash push", which has been corrected.

* ab/do-not-limit-stash-help-to-push:
  stash: don't show "git stash push" usage on bad "git stash" usage
This commit is contained in:
Junio C Hamano 2022-01-10 11:52:52 -08:00
commit 8ab404ea04
2 changed files with 20 additions and 0 deletions

View File

@ -1683,6 +1683,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
if (argc) {
force_assume = !strcmp(argv[0], "-p");
argc = parse_options(argc, argv, prefix, options,
push_assumed ? git_stash_usage :
git_stash_push_usage,
PARSE_OPT_KEEP_DASHDASH);
}

View File

@ -10,6 +10,25 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
test_expect_success 'usage on cmd and subcommand invalid option' '
test_expect_code 129 git stash --invalid-option 2>usage &&
grep "or: git stash" usage &&
test_expect_code 129 git stash push --invalid-option 2>usage &&
! grep "or: git stash" usage
'
test_expect_success 'usage on main command -h emits a summary of subcommands' '
test_expect_code 129 git stash -h >usage &&
grep -F "usage: git stash list" usage &&
grep -F "or: git stash show" usage
'
test_expect_failure 'usage for subcommands should emit subcommand usage' '
test_expect_code 129 git stash push -h >usage &&
grep -F "usage: git stash [push" usage
'
diff_cmp () {
for i in "$1" "$2"
do