const struct pathspec *pathspec)
{
int i;
+ int matches_exclude_magic = 0;
+ int matches_pathspec_elem = 0;
if (!pathspec || !pathspec->nr)
return 0;
for (i = 0; i < pathspec->nr; i++) {
const struct pathspec_item *item = &pathspec->items[i];
int len = item->nowildcard_len;
+ int *matches;
+
+ if (item->magic & PATHSPEC_EXCLUDE)
+ matches = &matches_exclude_magic;
+ else
+ matches = &matches_pathspec_elem;
if (len == pathlen &&
!ps_strncmp(item, item->match, path, pathlen))
- return 1;
+ *matches = 1;
if (len > pathlen &&
item->match[pathlen] == '/' &&
!ps_strncmp(item, item->match, path, pathlen))
- return 1;
+ *matches = 1;
}
+ if (matches_pathspec_elem && !matches_exclude_magic)
+ return 1;
return 0;
}
'
done
+test_expect_success "exclude magic would not interfere with .gitignore" '
+ test_write_lines dir file sub ign err out "*.o" >.gitignore &&
+ >foo.o &&
+ >foo.c &&
+ test_must_fail git add foo.o 2>err &&
+ test_grep "are ignored by one" err &&
+ test_grep "hint: Use -f" err &&
+
+ git add ":(exclude)foo.o" &&
+ git ls-files >actual &&
+ cat >expect <<-\EOF &&
+ .gitignore
+ foo.c
+ EOF
+ test_cmp expect actual
+'
+
test_done