public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Tian Yuchen <a3205153416@gmail•com>
To: Junio C Hamano <gitster@pobox•com>,
	"Remy D. Farley" <one-d-wide@protonmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH] fix git add :!x exiting with error when x is in .gitignore
Date: Thu, 5 Feb 2026 01:53:05 +0800	[thread overview]
Message-ID: <9c5be231-f340-4a97-850e-d43c78b2c889@gmail.com> (raw)
In-Reply-To: <xmqqo6m4pi84.fsf@gitster.g>

On 2/5/26 00:48, Junio C Hamano wrote:
> "Remy D. Farley" <one-d-wide@protonmail•com> writes:

> A question that immediately comes to mind is if it is appropriate
> for a negated pathspec element to recuse itself like this from the
> decision process and let other pathspec elements decide the fate of
> the path, or if a negated pathspec element should take a more active
> role of saying "no" (no, not by immediately returning 0, but this
> loop may have to become a two step process if we wanted to implement
> e.g., for the function to yield "yes", it has to match at least one
> positive pathspec element and zero negated one, or something like
> that).

You are right. To illustrate, if we run:

git add ignored_file ":!ignored_file"

Then following things might happen with the patch:
-> For the first item,
	- Does it match 'exclude'? No.
	- Does it match 'path'? Yes.
	- Return 1.
-> For the second item,
	- Is never reached
-> Git complain,
	'The following paths are ignored: ignored_file.'

In other word, it's not the expected silent no-op (returning 0).

As you suggested, The loop needs to verify that the path matches at 
least one positive item AND matches none of the negative items. A 
possible way to acheive it is:
(Notice that we no longer return 1 in the half way)


 >bool matched_positive = false;
 >
 >for (item in pathspec) {
 >	if (item matches patch) {
 >		if (item is exclude) {
 >			return 0;
 >		} else {
 >			matched_positive = true;
 >		}
 >	}
 >}
 >
 >return matched_positive ? 1 : 0;

By the way, I think extreme cases like 'git add x :!x' should be added 
into the test scripts.

Regards,

Yuchen





  reply	other threads:[~2026-02-04 17:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04 13:30 [PATCH] fix git add :!x exiting with error when x is in .gitignore Remy D. Farley
2026-02-04 16:48 ` Junio C Hamano
2026-02-04 17:53   ` Tian Yuchen [this message]
2026-02-04 18:47     ` Junio C Hamano
2026-02-04 20:11       ` Remy D. Farley
2026-02-04 20:47         ` Junio C Hamano

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=9c5be231-f340-4a97-850e-d43c78b2c889@gmail.com \
    --to=a3205153416@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=one-d-wide@protonmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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