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

Re: [PATCH v4] stash: infer "push" when command line starts with an option

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 13, 2026, 15:09 UTC
Message-ID
<xmqqeckilwwz.fsf@gitster.g>
In-Reply-To
<20260412195204.4636-1-deveshigurgaon@gmail.com>
Deveshi Dwivedi <deveshigurgaon@gmail.com> writes:
> When "git stash" is run without the "push" subcommand, the command
> tries to assume "push" but rejects any non-option arguments (i.e.,
> pathspecs without "--") to avoid treating a misspelled subcommand
> name as a pathspec.

I think "run without the 'push' subcommand" above should be "run without any subcommand (on the command line)". "git stash pop -- paths" is run without the "push" subcommand, and obviously we do not want it to assume "push".

Show 6 quoted lines
> A command line that begins with an option cannot be naming a "git
> stash" subcommand, so unconditionally assume "push" in that case and
> allow pathspec arguments to follow without requiring "--".  This is
> simpler and more robust than checking a specific list of options,
> and remains correct even if push or other subcommands gain new
> options in the future.
Good.
> Note that this does not check for negated options, so "git stash
> --no-staged [<pathspec>]" is still rejected.  Handling negated
> options would require teaching the inference logic about them
> explicitly.

That is unexpected, and unfortunate. I would have expected, since we are now sending any thing that is not unrecognised to "push", it would largely be the matter of removing special casing code about push_assumed from push_stash() and adding some to its caller, which is cmd_stash(). It would first look at its table of subcommands and if it finds a hit, calls the handler. If not, and if there is no argument or if the first argument begins with a dash "if (argv[1] && argv[1][0] == '-')", then unshift "push" into the argv[] array, and call push_stash(), which would complain if the command line (with "push" prepended) does not make sense to it. If the above two conditions were not met, cmd_stash() would not call push_stash() but complain that it did not get a valid command. Or something like that.

That way, there is nothing that makes "--no-something" any more special than "--something", no?

Previous: Phillip WoodNext: Deveshi Dwivedi
Message 15 of 17 in “stash: infer "push" when push-specific options are given”
  1. stash: infer "push" when push-specific options are givenDeveshi Dwivedi, Apr 4, 2026
  2. Mirko FainaApr 4, 2026
  3. stash: infer "push" when push-specific options are givenDeveshi Dwivedi, Apr 4, 2026
  4. Mirko FainaApr 4, 2026
  5. Deveshi DwivediApr 5, 2026
  6. stash: infer "push" when push-specific options are givenDeveshi Dwivedi, Apr 5, 2026
  7. Mirko FainaApr 6, 2026
  8. Phillip WoodApr 7, 2026
  9. Deveshi DwivediApr 9, 2026
  10. Mirko FainaApr 9, 2026
  11. Junio C HamanoApr 9, 2026
  12. Junio C HamanoApr 9, 2026
  13. stash: infer "push" when command line starts with an optionDeveshi Dwivedi, Apr 12, 2026
  14. Phillip WoodApr 13, 2026
  15. Junio C HamanoApr 13, 2026
  16. stash: assume "push" when command line starts with an optionDeveshi Dwivedi, Apr 19, 2026
  17. Phillip WoodApr 21, 2026

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.