Subject: Re: Bug: git add :!x . exits with error when x is in .gitignore

From: Tian Yuchen <[email-masked]>
Date: Tue, 3 Feb 2026 02:04:45 +0800

On 2/1/26 03:43, Remy D. Farley wrote:

Thanks for the report and the patch! I also agree that the behavior you 
described seems like a bug.

However, though I'm new to git community, I still have concerns about 
the fix in 'dir.c':
   > -	if (!pathspec || !pathspec->nr)
> +	if (!pathspec || !pathspec->nr || pathspec->magic & PATHSPEC_EXCLUDE)
>   		return 0;

I tried to analyze the logic and I believe this patch breaks the basic 
functionality of the negative pathspec (:!):

(I didn't check the caller of exclude_matches_pathspec and I only focus 
on the function itself. Tell me if I'm wrong :)

By returning 0 whenever PATHSPEC_EXCLUDE is set globally, 
exclude_matches_pathspec will report "no match" for all files, 
effectively disabling the exclusion mechanism entirely.

Instead of fixing the issue with ignored files, this patch causes valid 
exclusions to be ignored.

We must check if the specific path matches the exclude pattern, not 
short-circuit based on the global flag.

It will be great if we set a test script for this. I will be working on 
it in the next few days.

Regards,

Yuchen