Unverified Commit e2d4f09d by Edward Thomson Committed by GitHub

Merge pull request #5076 from libgit2/ethomson/ignore_spaces

Ignore files: don't ignore whitespace
parents ac070afe 4bcebe2c
......@@ -583,8 +583,11 @@ int git_attr_fnmatch__parse(
pattern = *base;
while (git__isspace(*pattern)) pattern++;
if (!*pattern || *pattern == '#') {
while (!allow_space && git__isspace(*pattern))
pattern++;
if (!*pattern || *pattern == '#' || *pattern == '\n' ||
(*pattern == '\r' && *(pattern + 1) == '\n')) {
*base = git__next_line(pattern);
return GIT_ENOTFOUND;
}
......@@ -606,8 +609,12 @@ int git_attr_fnmatch__parse(
slash_count = 0;
for (scan = pattern; *scan != '\0'; ++scan) {
/* scan until (non-escaped) white space */
if (git__isspace(*scan) && *(scan - 1) != '\\') {
/*
* Scan until a non-escaped whitespace: find a whitespace, then look
* one char backward to ensure that it's not prefixed by a `\`.
* Only look backward if we're not at the first position (`pattern`).
*/
if (git__isspace(*scan) && scan > pattern && *(scan - 1) != '\\') {
if (!allow_space || (*scan != ' ' && *scan != '\t' && *scan != '\r'))
break;
}
......
......@@ -181,16 +181,11 @@ void test_attr_file__assign_variants(void)
git_attr_file__free(file);
}
void test_attr_file__check_attr_examples(void)
static void assert_examples(git_attr_file *file)
{
git_attr_file *file;
git_attr_rule *rule;
git_attr_assignment *assign;
cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr3")));
cl_assert_equal_s(cl_fixture("attr/attr3"), file->entry->path);
cl_assert(file->rules.length == 3);
rule = get_rule(0);
cl_assert_equal_s("*.java", rule->match.pattern);
cl_assert(rule->assigns.length == 3);
......@@ -219,6 +214,30 @@ void test_attr_file__check_attr_examples(void)
assign = get_assign(rule, 0);
cl_assert_equal_s("caveat", assign->name);
cl_assert_equal_s("unspecified", assign->value);
}
void test_attr_file__check_attr_examples(void)
{
git_attr_file *file;
cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr3")));
cl_assert_equal_s(cl_fixture("attr/attr3"), file->entry->path);
cl_assert(file->rules.length == 3);
assert_examples(file);
git_attr_file__free(file);
}
void test_attr_file__whitespace(void)
{
git_attr_file *file;
cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr4")));
cl_assert_equal_s(cl_fixture("attr/attr4"), file->entry->path);
cl_assert(file->rules.length == 3);
assert_examples(file);
git_attr_file__free(file);
}
......@@ -100,7 +100,7 @@ static void workdir_iterator_test(
void test_iterator_workdir__0(void)
{
workdir_iterator_test("attr", NULL, NULL, 23, 5, NULL, "ign");
workdir_iterator_test("attr", NULL, NULL, 24, 5, NULL, "ign");
}
static const char *status_paths[] = {
......
# This is a comment
# This is also a comment
*.java diff=java -crlf myAttr
NoMyAttr.java !myAttr
README caveat=unspecified
......@@ -1236,3 +1236,33 @@ void test_status_ignore__skips_bom(void)
refute_is_ignored("foo.txt");
refute_is_ignored("bar.txt");
}
void test_status_ignore__leading_spaces_are_significant(void)
{
static const char *test_files[] = {
"empty_standard_repo/a.test",
"empty_standard_repo/b.test",
"empty_standard_repo/c.test",
"empty_standard_repo/d.test",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
" a.test\n"
"# this is a comment\n"
"b.test\n"
"\tc.test\n"
" # not a comment\n"
"d.test\n");
refute_is_ignored("a.test");
assert_is_ignored(" a.test");
refute_is_ignored("# this is a comment");
assert_is_ignored("b.test");
refute_is_ignored("c.test");
assert_is_ignored("\tc.test");
assert_is_ignored(" # not a comment");
assert_is_ignored("d.test");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment