Git fork

Make !pattern in .gitattributes non-fatal

Before 82dce99 (attr: more matching optimizations from .gitignore,
2012-10-15), .gitattributes did not have any special treatment of a
leading '!'. The docs, however, always said

The rules how the pattern matches paths are the same as in
`.gitignore` files; see linkgit:gitignore[5].

By those rules, leading '!' means pattern negation. So 82dce99
correctly determined that this kind of line makes no sense and should
be disallowed.

However, users who actually had a rule for files starting with a '!'
are in a bad position: before 82dce99 '!' matched that literal
character, so it is conceivable that users have .gitattributes with
such lines in them. After 82dce99 the unescaped version was
disallowed in such a way that git outright refuses to run(!) most
commands in the presence of such a .gitattributes. It therefore
becomes very hard to fix, let alone work with, such repositories.

Let's at least allow the users to fix their repos: change the fatal
error into a warning.

Reported-by: mathstuf@gmail.com
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Thomas Rast and committed by
Junio C Hamano
8b1bd024 1d38c697

+7 -4
+5 -3
attr.c
··· 255 255 &res->u.pat.patternlen, 256 256 &res->u.pat.flags, 257 257 &res->u.pat.nowildcardlen); 258 - if (res->u.pat.flags & EXC_FLAG_NEGATIVE) 259 - die(_("Negative patterns are forbidden in git attributes\n" 260 - "Use '\\!' for literal leading exclamation.")); 258 + if (res->u.pat.flags & EXC_FLAG_NEGATIVE) { 259 + warning(_("Negative patterns are ignored in git attributes\n" 260 + "Use '\\!' for literal leading exclamation.")); 261 + return NULL; 262 + } 261 263 } 262 264 res->is_macro = is_macro; 263 265 res->num_attr = num_attr;
+2 -1
t/t0003-attributes.sh
··· 198 198 199 199 test_expect_success 'negative patterns' ' 200 200 echo "!f test=bar" >.gitattributes && 201 - test_must_fail git check-attr test -- f 201 + git check-attr test -- '"'"'!f'"'"' 2>errors && 202 + test_i18ngrep "Negative patterns are ignored" errors 202 203 ' 203 204 204 205 test_expect_success 'patterns starting with exclamation' '