From: Deveshi Dwivedi <deveshigurgaon@gmail.com>
To: git@vger.kernel.org
Cc: ben.knoble@gmail.com, mroik@delayed.space,
quentin.bernet@bluewin.ch, gitster@pobox.com,
Deveshi Dwivedi <deveshigurgaon@gmail.com>
Subject: [PATCH v3] stash: infer "push" when push-specific options are given
Date: Sun, 5 Apr 2026 11:09:53 +0000 [thread overview]
Message-ID: <20260405110953.3316-1-deveshigurgaon@gmail.com> (raw)
In-Reply-To: <20260404143640.6679-1-deveshigurgaon@gmail.com>
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. The only exception is "-p", which sets
force_assume and allows pathspecs to follow.
This means "git stash -m foo file" is rejected even though "-m" is
unambiguously a "push" option, and the user's intent is clear. The
same applies to other push-specific options like "--staged",
"--keep-index", "--include-untracked", and "--pathspec-from-file".
Expand the set of options that force the "push" assumption to
include all push-specific options, so that pathspec arguments are
accepted without requiring "--" or the explicit "push" subcommand
when the command line already contains a push-only option.
This was marked as #leftoverbits in [1].
[1] https://lore.kernel.org/git/xmqqtsu1jipp.fsf@gitster.g/
Signed-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>
---
Changes since v2:
- Clean up staged file with git reset --hard at end of test
- Update documentation to reflect new push inference behavior
Documentation/git-stash.adoc | 7 ++++---
builtin/stash.c | 4 +++-
t/t3903-stash.sh | 23 +++++++++++++++++++++++
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-stash.adoc b/Documentation/git-stash.adoc
index 235d57ddd8..e4e77c2f07 100644
--- a/Documentation/git-stash.adoc
+++ b/Documentation/git-stash.adoc
@@ -61,9 +61,10 @@ COMMANDS
+
For quickly making a snapshot, you can omit "push". In this mode,
non-option arguments are not allowed to prevent a misspelled
-subcommand from making an unwanted stash entry. The two exceptions to this
-are `stash -p` which acts as alias for `stash push -p` and pathspec elements,
-which are allowed after a double hyphen `--` for disambiguation.
+subcommand from making an unwanted stash entry. Pathspec elements
+are allowed after a double hyphen `--` for disambiguation. When
+any push-specific option is given, the "push" subcommand is inferred
+and pathspec arguments are also accepted without `--`.
`save [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-u | --include-untracked] [-a | --all] [-q | --quiet] [<message>]`::
diff --git a/builtin/stash.c b/builtin/stash.c
index 95c5005b0b..197814241c 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1877,7 +1877,9 @@ static int push_stash(int argc, const char **argv, const char *prefix,
argc = parse_options(argc, argv, prefix, options,
push_assumed ? git_stash_usage :
git_stash_push_usage, flags);
- force_assume |= patch_mode;
+ force_assume |= patch_mode || stash_msg ||
+ keep_index != -1 || only_staged ||
+ include_untracked || pathspec_from_file;
}
if (argc) {
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 70879941c2..f021dc9068 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -414,6 +414,29 @@ test_expect_success 'dont assume push with non-option args' '
test_grep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err
'
+test_expect_success 'assume push when options imply push' '
+ git reset --hard &&
+ echo changed >file &&
+ git add file &&
+ git stash -m "implied push" file &&
+ git stash pop &&
+
+ git add file &&
+ git stash --staged file &&
+ git stash pop &&
+
+ git add file &&
+ git stash --keep-index file &&
+ git stash pop &&
+
+ echo untracked >untracked-file &&
+ git stash --include-untracked untracked-file &&
+ test_path_is_missing untracked-file &&
+ git stash pop &&
+ rm -f untracked-file &&
+ git reset --hard
+'
+
test_expect_success 'stash --invalid-option' '
echo bar5 >file &&
echo bar6 >file2 &&
base-commit: 2855562ca6a9c6b0e7bc780b050c1e83c9fcfbd0
--
2.52.0.230.gd8af7cadaa
next prev parent reply other threads:[~2026-04-05 11:10 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-04 14:36 [PATCH] stash: infer "push" when push-specific options are given Deveshi Dwivedi
2026-04-04 15:19 ` Mirko Faina
2026-04-04 16:03 ` [PATCH v2] " Deveshi Dwivedi
2026-04-04 23:40 ` Mirko Faina
2026-04-05 7:02 ` Deveshi Dwivedi
2026-04-05 11:09 ` Deveshi Dwivedi [this message]
2026-04-06 18:15 ` [PATCH v3] " Mirko Faina
2026-04-07 9:36 ` Phillip Wood
2026-04-09 19:22 ` Deveshi Dwivedi
2026-04-09 19:37 ` Mirko Faina
2026-04-09 20:31 ` Junio C Hamano
2026-04-09 20:22 ` Junio C Hamano
2026-04-12 19:52 ` [PATCH v4] stash: infer "push" when command line starts with an option Deveshi Dwivedi
2026-04-13 9:08 ` Phillip Wood
2026-04-13 15:09 ` Junio C Hamano
2026-04-19 16:54 ` [PATCH v5] stash: assume " Deveshi Dwivedi
2026-04-21 15:28 ` Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260405110953.3316-1-deveshigurgaon@gmail.com \
--to=deveshigurgaon@gmail.com \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mroik@delayed.space \
--cc=quentin.bernet@bluewin.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox