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, 16:48 UTC
Message-ID
<xmqqo6m4pi84.fsf@gitster.g>
In-Reply-To
<20260204132747.1564157-1-one-d-wide@protonmail.com>
"Remy D. Farley" <one-d-wide@protonmail.com> writes:
Show 14 quoted lines
> diff --git a/dir.c b/dir.c
> index b00821f294..ed6b99e337 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -2280,6 +2280,9 @@ static int exclude_matches_pathspec(const char *path, int pathlen,
>  		const struct pathspec_item *item = &pathspec->items[i];
>  		int len = item->nowildcard_len;
>  
> +		if (item->magic & PATHSPEC_EXCLUDE)
> +			continue;
> +
>  		if (len == pathlen &&
>  		    !ps_strncmp(item, item->match, path, pathlen))
>  			return 1;

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).

What should
	git add "$x" ":!$y"

do when a path <matches, does not match> $X and <matches, does not match> $Y? We have four combinations to consider in such a case. The code in the patch says it should behave identically to

	git add "$x"

and negated ":!$y" should not make any difference. Is that what we want?

Thanks.
Previous: Remy D. FarleyNext: Tian Yuchen
Message 2 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.