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

Re: [PATCH] stash: honor --no-overwrite-ignore when updating index

From
Karthik Nayak <karthik.188@gmail.com>
Date
Feb 2, 2026, 14:10 UTC
Message-ID
<CAOLa=ZQCuka+cSuCu=KnTHm=gk1iJ_QJhDjy1Ku8WLfSgkGorw@mail.gmail.com>
In-Reply-To
<20260202131921.15175-2-pushkarkumarsingh1970@gmail.com>
Pushkar Singh <pushkarkumarsingh1970@gmail.com> writes:
Show 44 quoted lines
> The stash code unconditionally cleared opts.preserve_ignored when
> updating the index, leaving a FIXME suggesting this should depend on
> an overwrite_ignore flag.
>
> Introduce overwrite_ignore plumbing for git stash push/save and use it
> to control preserve_ignored during reset_tree(). Add a test to verify
> that --no-overwrite-ignore preserves ignored files.
>
> This removes the long-standing FIXME and aligns stash behavior with
> checkout/reset/merge.
> ---
>  builtin/stash.c                    | 11 ++++++++++-
>  t/t3905-stash-include-untracked.sh | 13 +++++++++++++
>  2 files changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/stash.c b/builtin/stash.c
> index 193e3ea47a..82d10520fe 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -150,6 +150,7 @@ static int show_stat = 1;
>  static int show_patch;
>  static int show_include_untracked;
>  static int use_index;
> +static int overwrite_ignore = 1;
>
>  /*
>   * w_commit is set to the commit containing the working tree
> @@ -360,7 +361,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
>  	opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;
>  	opts.update = update;
>  	if (update)
> -		opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */
> +		opts.preserve_ignored = !overwrite_ignore;
>  	opts.fn = oneway_merge;
>
>  	if (unpack_trees(nr_trees, t, &opts))
> @@ -1856,6 +1857,10 @@ static int push_stash(int argc, const char **argv, const char *prefix,
>  			 N_("include untracked files in stash")),
>  		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")),
Adding an `OPT_BOOL` by default adds a [no] option.
from Documentation/technical/api-parse-options.adoc:
  `OPT_BOOL(short, long, &int_var, description)`::
  	Introduce a boolean option. `int_var` is set to one with
  	`--option` and set to zero with `--no-option`.

Apart from that, isn't this plain wrong?? The '--overwrite-ignore' and '--no-overwrite-ignore' do the same thing here?

Show 11 quoted lines
>  		OPT_STRING('m', "message", &stash_msg, N_("message"),
>  			   N_("stash message")),
>  		OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
> @@ -1959,6 +1964,10 @@ static int save_stash(int argc, const char **argv, const char *prefix,
>  			 N_("include untracked files in stash")),
>  		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")),
Here too.
Show 24 quoted lines
>  		OPT_STRING('m', "message", &stash_msg, "message",
>  			   N_("stash message")),
>  		OPT_END()
> diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
> index 7704709054..9c5421cd76 100755
> --- a/t/t3905-stash-include-untracked.sh
> +++ b/t/t3905-stash-include-untracked.sh
> @@ -427,4 +427,17 @@ test_expect_success 'stash -u ignores sub-repository' '
>  	git stash -u
>  '
>
> +test_expect_success 'stash push --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 &&
> +
> +	test_path_is_file ignored.txt &&
> +	grep after ignored.txt
> +'
> +
To confirm, changing the test
modified   t/t3905-stash-include-untracked.sh
@@ -434,7 +434,7 @@ test_expect_success 'stash push
--no-overwrite-ignore preserves ignored files' '
 	git commit -m "add ignore" &&

 	echo after >ignored.txt &&
-	git stash push --no-overwrite-ignore &&
+	git stash push --overwrite-ignore &&

 	test_path_is_file ignored.txt &&
 	grep after ignored.txt

still passes the test. We should be testing both scenarios.

>  test_done
> --
> 2.43.0
Previous: Pushkar SinghNext: D. Ben Knoble
Message 2 of 15 in “stash: honor --no-overwrite-ignore when updating index”
  1. stash: honor --no-overwrite-ignore when updating indexPushkar Singh, Feb 2, 2026
  2. Karthik NayakFeb 2, 2026
  3. D. Ben KnobleFeb 2, 2026
  4. Patrick SteinhardtFeb 2, 2026
  5. Kristoffer HaugsbakkFeb 2, 2026
  6. stash: honor --no-overwrite-ignore with --allPushkar Singh, Feb 2, 2026
  7. Kristoffer HaugsbakkFeb 2, 2026
  8. Pushkar SinghFeb 2, 2026
  9. D. Ben KnobleFeb 2, 2026
  10. Elijah NewrenFeb 2, 2026
  11. Pushkar SinghFeb 3, 2026
  12. Elijah NewrenFeb 3, 2026
  13. stash: honor --no-overwrite-ignore with --allPushkar Singh, Feb 3, 2026
  14. Elijah NewrenFeb 3, 2026
  15. Pushkar SinghFeb 3, 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.