@matheusbsbs / matheus-bagliano / commits / cada7308ad
Fork 0

dir: check pathspecs before returning `path_excluded`

In 95c11ecc73 ("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 <schwab@linux-m68k.org> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Jul 20, 2020 at 20:45 UTC cada7308ade0b9a018f9c54ea3f226e2e9c39ee5
2 files changed +27 -2
dir.c
+2 -2
@@ -2117,13 +2117,13 @@ static enum path_treatment treat_path(struct dir_struct *dir,
2117 baselen, excluded, pathspec);
2118 case DT_REG:
2119 case DT_LNK:
2120 - if (excluded)
2121 - return path_excluded;
2120 if (pathspec &&
2121 !do_match_pathspec(istate, pathspec, path->buf, path->len,
2122 0 /* prefix */, NULL /* seen */,
2123 0 /* flags */))
2124 return path_none;
2125 + if (excluded)
2126 + return path_excluded;
2127 return path_untracked;
2128 }
2129 }
t/t7061-wtstatus-ignore.sh
+25
@@ -30,6 +30,31 @@ test_expect_success 'same with gitignore starting with BOM' '
30 test_cmp expected actual
31 '
32
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 +
58 cat >expected <<\EOF
59 ?? .gitignore
60 ?? actual