Skip to content

Commit 8b1bd02

Browse files
trastgitster
authored andcommitted
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: [email protected] Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d38c69 commit 8b1bd02

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

attr.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,11 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
255255
&res->u.pat.patternlen,
256256
&res->u.pat.flags,
257257
&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+
}
261263
}
262264
res->is_macro = is_macro;
263265
res->num_attr = num_attr;

t/t0003-attributes.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ test_expect_success 'root subdir attribute test' '
198198

199199
test_expect_success 'negative patterns' '
200200
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
202203
'
203204

204205
test_expect_success 'patterns starting with exclamation' '

0 commit comments

Comments
 (0)