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

Tian Yuchen <a3205153416@gmail.com> writes:

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

One caveat.  The case without any positive pathspec entries needs
special consideration.  I suspect, but can be totally wrong as I
didn't think things through thoroughly, that

    git add "!$y"

would want to behave as if an implicit "everything matches" was
given, i.e.,

    git add "!$y" .

while a pathspec with one or more positive entries would not need
and want such an implicit "everything" treatment.

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

True.

  reply	other threads:[~2026-02-04 18:47 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
2026-02-04 18:47     ` Junio C Hamano [this message]
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=xmqq5x8cpcrd.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=a3205153416@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=one-d-wide@protonmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.