Thread (2 messages) flat view 2 messages, 2 authors, 2026-02-04

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

From: Junio C Hamano <hidden>
Date: 2026-02-04 18:47:04

Tian Yuchen [off-list ref] 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help