git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] stash: don't show "git stash push" usage on bad "git stash" usage

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 16, 2021, 22:03 UTC
Message-ID
<xmqqczlw8axt.fsf@gitster.g>
In-Reply-To
<patch-v3-1.1-6b33b104c84-20211216T125317Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 12 quoted lines
> diff --git a/builtin/stash.c b/builtin/stash.c
> index 18c812bbe03..5462840a073 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -1681,6 +1681,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);
>  	}

Yeah, "git stash" having the implicit default to "push" may have been convenient for its original intended use case (i.e. clear the working area with as little typing and effort as possible), but without a care like this one, it would result in surprises.

Looks good, will queue.
Show 30 quoted lines
> diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
> index 2c66cfbc3b7..b17c52d8807 100755
> --- a/t/t3903-stash.sh
> +++ b/t/t3903-stash.sh
> @@ -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
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 4 of 5 in “stash: print the correct usage on "git stash [push] --invalid-option"”
  1. stash: print the correct usage on "git stash [push] --invalid-option"Ævar Arnfjörð Bjarmason, Sep 1, 2021
  2. stash: print the correct usage on "git stash [push] --invalid-option"Ævar Arnfjörð Bjarmason, Sep 21, 2021
  3. stash: don't show "git stash push" usage on bad "git stash" usageÆvar Arnfjörð Bjarmason, Dec 16, 2021
  4. Junio C HamanoDec 16, 2021
  5. Junio C HamanoDec 16, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.