Skip to content

Commit cada730

Browse files
Martin Ågrengitster
authored andcommitted
dir: check pathspecs before returning path_excluded
In 95c11ec ("Fix error-prone fill_directory() API; make it only return matches", 2020-04-01), we taught `fill_directory()`, or more specifically `treat_path()`, to check against any pathspecs so that we could simplify the callers. But in doing so, we added a slightly-too-early return for the "excluded" case. We end up not checking the pathspecs, meaning we return `path_excluded` when maybe we should return `path_none`. As a result, `git status --ignored -- pathspec` might show paths that don't actually match "pathspec". Move the "excluded" check down to after we've checked any pathspecs. Reported-by: Andreas Schwab <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0af173 commit cada730

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,13 +2117,13 @@ static enum path_treatment treat_path(struct dir_struct *dir,
21172117
baselen, excluded, pathspec);
21182118
case DT_REG:
21192119
case DT_LNK:
2120-
if (excluded)
2121-
return path_excluded;
21222120
if (pathspec &&
21232121
!do_match_pathspec(istate, pathspec, path->buf, path->len,
21242122
0 /* prefix */, NULL /* seen */,
21252123
0 /* flags */))
21262124
return path_none;
2125+
if (excluded)
2126+
return path_excluded;
21272127
return path_untracked;
21282128
}
21292129
}

t/t7061-wtstatus-ignore.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ test_expect_success 'same with gitignore starting with BOM' '
3030
test_cmp expected actual
3131
'
3232

33+
test_expect_success 'status untracked files --ignored with pathspec (no match)' '
34+
git status --porcelain --ignored -- untracked/i >actual &&
35+
test_must_be_empty actual &&
36+
git status --porcelain --ignored -- untracked/u >actual &&
37+
test_must_be_empty actual
38+
'
39+
40+
test_expect_success 'status untracked files --ignored with pathspec (literal match)' '
41+
git status --porcelain --ignored -- untracked/ignored >actual &&
42+
echo "!! untracked/ignored" >expected &&
43+
test_cmp expected actual &&
44+
git status --porcelain --ignored -- untracked/uncommitted >actual &&
45+
echo "?? untracked/uncommitted" >expected &&
46+
test_cmp expected actual
47+
'
48+
49+
test_expect_success 'status untracked files --ignored with pathspec (glob match)' '
50+
git status --porcelain --ignored -- untracked/i\* >actual &&
51+
echo "!! untracked/ignored" >expected &&
52+
test_cmp expected actual &&
53+
git status --porcelain --ignored -- untracked/u\* >actual &&
54+
echo "?? untracked/uncommitted" >expected &&
55+
test_cmp expected actual
56+
'
57+
3358
cat >expected <<\EOF
3459
?? .gitignore
3560
?? actual

0 commit comments

Comments
 (0)