Skip to content

Commit d91410e

Browse files
committed
Merge branch 'jc/exclude-with-gitignore' into seen
"git add ':(exclude)foo.o'" is clearly a request not to add 'foo.o', but the command complained about listing an ignored path foo.o on the command line, which has been corrected. Comments? * jc/exclude-with-gitignore: dir.c: do not be fooled by :(exclude) pathspec elements
2 parents 2a7efd5 + 97660b2 commit d91410e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

dir.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,8 @@ static int exclude_matches_pathspec(const char *path, int pathlen,
22632263
const struct pathspec *pathspec)
22642264
{
22652265
int i;
2266+
int matches_exclude_magic = 0;
2267+
int matches_pathspec_elem = 0;
22662268

22672269
if (!pathspec || !pathspec->nr)
22682270
return 0;
@@ -2279,15 +2281,23 @@ static int exclude_matches_pathspec(const char *path, int pathlen,
22792281
for (i = 0; i < pathspec->nr; i++) {
22802282
const struct pathspec_item *item = &pathspec->items[i];
22812283
int len = item->nowildcard_len;
2284+
int *matches;
2285+
2286+
if (item->magic & PATHSPEC_EXCLUDE)
2287+
matches = &matches_exclude_magic;
2288+
else
2289+
matches = &matches_pathspec_elem;
22822290

22832291
if (len == pathlen &&
22842292
!ps_strncmp(item, item->match, path, pathlen))
2285-
return 1;
2293+
*matches = 1;
22862294
if (len > pathlen &&
22872295
item->match[pathlen] == '/' &&
22882296
!ps_strncmp(item, item->match, path, pathlen))
2289-
return 1;
2297+
*matches = 1;
22902298
}
2299+
if (matches_pathspec_elem && !matches_exclude_magic)
2300+
return 1;
22912301
return 0;
22922302
}
22932303

t/t2204-add-ignored.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,21 @@ do
8989
'
9090
done
9191

92+
test_expect_success "exclude magic would not interfere with .gitignore" '
93+
test_write_lines dir file sub ign err out "*.o" >.gitignore &&
94+
>foo.o &&
95+
>foo.c &&
96+
test_must_fail git add foo.o 2>err &&
97+
test_grep "are ignored by one" err &&
98+
test_grep "hint: Use -f" err &&
99+
100+
git add ":(exclude)foo.o" &&
101+
git ls-files >actual &&
102+
cat >expect <<-\EOF &&
103+
.gitignore
104+
foo.c
105+
EOF
106+
test_cmp expect actual
107+
'
108+
92109
test_done

0 commit comments

Comments
 (0)