public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, peff@peff.net
Subject: Re: [PATCH] stash: honor --no-overwrite-ignore when updating index
Date: Mon, 2 Feb 2026 15:20:03 +0100	[thread overview]
Message-ID: <aYCyk02vG8ObH02j@pks.im> (raw)
In-Reply-To: <20260202131921.15175-2-pushkarkumarsingh1970@gmail.com>

On Mon, Feb 02, 2026 at 01:19:22PM +0000, Pushkar Singh wrote:
> 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.

It's somewhat surprising that this requires so little code changes. Do
the mailing list archives yield any justification for why specifically
this feature wasn't implemented?

> This removes the long-standing FIXME and aligns stash behavior with
> checkout/reset/merge.

Missing signoff.

> diff --git a/builtin/stash.c b/builtin/stash.c
> index 193e3ea47a..82d10520fe 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -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")),
>  		OPT_STRING('m', "message", &stash_msg, N_("message"),
>  			   N_("stash message")),
>  		OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),

`OPT_BOOL()` already handles both the positive and negative case, so
there's no need to specify both here. Furthermore, both of your options
actually do the exact same thing.

> @@ -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")),
>  		OPT_STRING('m', "message", &stash_msg, "message",
>  			   N_("stash message")),
>  		OPT_END()

Same here.

> 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 &&

Is there any specific reason why we append instead of overwriting the
gitignore file? Overwriting would probably be preferred so that it's
easier to reason about the test without requiring context around what
the current contents of this file are.

> +	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

I think another good step would be to verify that `git stash push
--overwrite-ignore` _would_ cause us to overwrite the file.

I guess this test only happens to work because the first option
takes precedence over the ambiguous second one?

Patrick

  parent reply	other threads:[~2026-02-02 14:20 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 [this message]
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   ` [PATCH v3] " Pushkar Singh
2026-02-03 19:22     ` 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=aYCyk02vG8ObH02j@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=pushkarkumarsingh1970@gmail.com \
    /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