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

Re: [PATCH] fix git add :!x exiting with error when x is in .gitignore

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2026, 18:47 UTC
Message-ID
<xmqq5x8cpcrd.fsf@gitster.g>
In-Reply-To
<9c5be231-f340-4a97-850e-d43c78b2c889@gmail.com>
Tian Yuchen <a3205153416@gmail.com> writes:
Show 18 quoted lines
> 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.
Previous: Tian YuchenNext: Remy D. Farley
Message 4 of 6 in “fix git add :!x exiting with error when x is in .gitignore”
  1. fix git add :!x exiting with error when x is in .gitignoreRemy D. Farley, Feb 4, 2026
  2. Junio C HamanoFeb 4, 2026
  3. Tian YuchenFeb 4, 2026
  4. Junio C HamanoFeb 4, 2026
  5. fix git add :!x exiting with error when x is in .gitignoreRemy D. Farley, Feb 4, 2026
  6. Junio C HamanoFeb 4, 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.