From: Junio C Hamano Date: Wed, 04 Feb 2026 18:47:02 GMT Subject: Re: [PATCH] fix git add :!x exiting with error when x is in .gitignore Message-ID: In-Reply-To: <9c5be231-f340-4a97-850e-d43c78b2c889@gmail.com> Tian Yuchen 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.