Make !pattern in .gitattributes non-fatal
Before82dce99
(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. So82dce99
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: before82dce99
'!' matched that literal character, so it is conceivable that users have .gitattributes with such lines in them. After82dce99
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>
This commit is contained in:
parent
1d38c6971d
commit
8b1bd02415
8
attr.c
8
attr.c
@ -255,9 +255,11 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
&res->u.pat.patternlen,
|
&res->u.pat.patternlen,
|
||||||
&res->u.pat.flags,
|
&res->u.pat.flags,
|
||||||
&res->u.pat.nowildcardlen);
|
&res->u.pat.nowildcardlen);
|
||||||
if (res->u.pat.flags & EXC_FLAG_NEGATIVE)
|
if (res->u.pat.flags & EXC_FLAG_NEGATIVE) {
|
||||||
die(_("Negative patterns are forbidden in git attributes\n"
|
warning(_("Negative patterns are ignored in git attributes\n"
|
||||||
"Use '\\!' for literal leading exclamation."));
|
"Use '\\!' for literal leading exclamation."));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
res->is_macro = is_macro;
|
res->is_macro = is_macro;
|
||||||
res->num_attr = num_attr;
|
res->num_attr = num_attr;
|
||||||
|
@ -198,7 +198,8 @@ test_expect_success 'root subdir attribute test' '
|
|||||||
|
|
||||||
test_expect_success 'negative patterns' '
|
test_expect_success 'negative patterns' '
|
||||||
echo "!f test=bar" >.gitattributes &&
|
echo "!f test=bar" >.gitattributes &&
|
||||||
test_must_fail git check-attr test -- f
|
git check-attr test -- '"'"'!f'"'"' 2>errors &&
|
||||||
|
test_i18ngrep "Negative patterns are ignored" errors
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'patterns starting with exclamation' '
|
test_expect_success 'patterns starting with exclamation' '
|
||||||
|
Loading…
Reference in New Issue
Block a user