]> git.ipfire.org Git - thirdparty/git.git/commitdiff
dir: check pathspecs before returning `path_excluded`
authorMartin Ågren <martin.agren@gmail.com>
Mon, 20 Jul 2020 18:45:29 +0000 (20:45 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Jul 2020 20:25:07 +0000 (13:25 -0700)
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>
dir.c
t/t7061-wtstatus-ignore.sh

diff --git a/dir.c b/dir.c
index 2de64910401540455217b1e5df6ffbdc9b31a295..bcd04b7cbfd33c0468f4eb5062662e812e849e2d 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -2117,13 +2117,13 @@ static enum path_treatment treat_path(struct dir_struct *dir,
                                       baselen, excluded, pathspec);
        case DT_REG:
        case DT_LNK:
-               if (excluded)
-                       return path_excluded;
                if (pathspec &&
                    !do_match_pathspec(istate, pathspec, path->buf, path->len,
                                       0 /* prefix */, NULL /* seen */,
                                       0 /* flags */))
                        return path_none;
+               if (excluded)
+                       return path_excluded;
                return path_untracked;
        }
 }
index e4cf5484f97a570da8225ca501d3b395e13604e3..2f9bea9793cec8b2900c35b3add315b67192a882 100755 (executable)
@@ -30,6 +30,31 @@ test_expect_success 'same with gitignore starting with BOM' '
        test_cmp expected actual
 '
 
+test_expect_success 'status untracked files --ignored with pathspec (no match)' '
+       git status --porcelain --ignored -- untracked/i >actual &&
+       test_must_be_empty actual &&
+       git status --porcelain --ignored -- untracked/u >actual &&
+       test_must_be_empty actual
+'
+
+test_expect_success 'status untracked files --ignored with pathspec (literal match)' '
+       git status --porcelain --ignored -- untracked/ignored >actual &&
+       echo "!! untracked/ignored" >expected &&
+       test_cmp expected actual &&
+       git status --porcelain --ignored -- untracked/uncommitted >actual &&
+       echo "?? untracked/uncommitted" >expected &&
+       test_cmp expected actual
+'
+
+test_expect_success 'status untracked files --ignored with pathspec (glob match)' '
+       git status --porcelain --ignored -- untracked/i\* >actual &&
+       echo "!! untracked/ignored" >expected &&
+       test_cmp expected actual &&
+       git status --porcelain --ignored -- untracked/u\* >actual &&
+       echo "?? untracked/uncommitted" >expected &&
+       test_cmp expected actual
+'
+
 cat >expected <<\EOF
 ?? .gitignore
 ?? actual