From: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, karthiknayak@gmail.com, kh@pks.im,
peff@peff.net, ps@pks.im,
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Subject: [PATCH v3] stash: honor --no-overwrite-ignore with --all
Date: Tue, 3 Feb 2026 18:04:00 +0000 [thread overview]
Message-ID: <20260203180359.602905-2-pushkarkumarsingh1970@gmail.com> (raw)
In-Reply-To: <20260202162225.35206-3-pushkarkumarsingh1970@gmail.com>
Teach stash push/save to avoid -a cleanup when --no-overwrite-ignore
is given by downgrading INCLUDE_ALL_FILES to include-untracked.
This fixes ignored files being incorrectly removed despite
--no-overwrite-ignore.
Add regression tests covering both overwrite and no-overwrite cases.
Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
---
Changes since v2:
- Use test_grep instead of grep
- Use test_path_is_missing for overwrite-ignore test
- Rebase onto current master so patch applies cleanly
builtin/stash.c | 14 ++++++++------
t/t3905-stash-include-untracked.sh | 18 +++++++++++++++---
2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/builtin/stash.c b/builtin/stash.c
index 82d10520fe..c3ee33cce1 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1858,9 +1858,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
OPT_SET_INT('a', "all", &include_untracked,
N_("include ignore files"), 2),
OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore,
- N_("update ignored files (default)")),
- OPT_BOOL(0, "no-overwrite-ignore", &overwrite_ignore,
- N_("do not update ignored files")),
+ N_("update ignored files")),
OPT_STRING('m', "message", &stash_msg, N_("message"),
N_("stash message")),
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
@@ -1894,6 +1892,9 @@ static int push_stash(int argc, const char **argv, const char *prefix,
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN,
prefix, argv);
+ if (!overwrite_ignore && include_untracked == INCLUDE_ALL_FILES)
+ include_untracked = 1;
+
if (pathspec_from_file) {
if (patch_mode)
die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--patch");
@@ -1965,9 +1966,7 @@ static int save_stash(int argc, const char **argv, const char *prefix,
OPT_SET_INT('a', "all", &include_untracked,
N_("include ignore files"), 2),
OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore,
- N_("update ignored files (default)")),
- OPT_BOOL(0, "no-overwrite-ignore", &overwrite_ignore,
- N_("do not update ignored files")),
+ N_("update ignored files")),
OPT_STRING('m', "message", &stash_msg, "message",
N_("stash message")),
OPT_END()
@@ -1994,6 +1993,9 @@ static int save_stash(int argc, const char **argv, const char *prefix,
die(_("the option '%s' requires '%s'"), "--inter-hunk-context", "--patch");
}
+ if (!overwrite_ignore && include_untracked == INCLUDE_ALL_FILES)
+ include_untracked = 1;
+
ret = do_push_stash(&ps, stash_msg, quiet, keep_index,
patch_mode, &add_p_opt, include_untracked,
only_staged);
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index 9c5421cd76..63b59de47b 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -427,17 +427,29 @@ test_expect_success 'stash -u ignores sub-repository' '
git stash -u
'
-test_expect_success 'stash push --no-overwrite-ignore preserves ignored files' '
+test_expect_success 'stash push -a --no-overwrite-ignore preserves ignored files' '
echo ignored.txt >>.gitignore &&
echo before >ignored.txt &&
git add .gitignore &&
git commit -m "add ignore" &&
echo after >ignored.txt &&
- git stash push --no-overwrite-ignore &&
+ git stash push -a --no-overwrite-ignore &&
test_path_is_file ignored.txt &&
- grep after ignored.txt
+ test_grep after ignored.txt
+'
+
+test_expect_success 'stash push -a --overwrite-ignore overwrites ignored files' '
+ echo ignored.txt >>.gitignore &&
+ echo before >ignored.txt &&
+ git add .gitignore &&
+ git commit -m "add ignore" &&
+
+ echo after >ignored.txt &&
+ git stash push -a --overwrite-ignore &&
+
+ test_path_is_missing ignored.txt
'
test_done
--
2.43.0
next prev parent reply other threads:[~2026-02-03 18:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-02 13:19 [PATCH] stash: honor --no-overwrite-ignore when updating index Pushkar Singh
2026-02-02 14:10 ` Karthik Nayak
2026-02-02 19:37 ` D. Ben Knoble
2026-02-02 14:20 ` Patrick Steinhardt
2026-02-02 14:21 ` Kristoffer Haugsbakk
2026-02-02 16:22 ` [PATCH v2] stash: honor --no-overwrite-ignore with --all Pushkar Singh
2026-02-02 16:48 ` Kristoffer Haugsbakk
2026-02-02 17:09 ` Pushkar Singh
2026-02-02 20:00 ` D. Ben Knoble
2026-02-02 20:31 ` Elijah Newren
2026-02-03 18:18 ` Pushkar Singh
2026-02-03 19:22 ` Elijah Newren
2026-02-03 18:04 ` Pushkar Singh [this message]
2026-02-03 19:22 ` [PATCH v3] " Elijah Newren
2026-02-03 20:07 ` Pushkar Singh
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=20260203180359.602905-2-pushkarkumarsingh1970@gmail.com \
--to=pushkarkumarsingh1970@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthiknayak@gmail.com \
--cc=kh@pks.im \
--cc=peff@peff.net \
--cc=ps@pks.im \
/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