]> git.ipfire.org Git - thirdparty/git.git/commitdiff
dir: exit before wildcard fall-through if there is no wildcard
authorElijah Newren <newren@gmail.com>
Tue, 10 Dec 2019 20:00:23 +0000 (20:00 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Dec 2019 20:23:23 +0000 (12:23 -0800)
The DO_MATCH_LEADING_PATHSPEC had a fall-through case for if there was a
wildcard, noting that we don't yet have enough information to determine
if a further paths under the current directory might match due to the
presence of wildcards.  But if we have no wildcards in our pathspec,
then we shouldn't get to that fall-through case.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
t/t3011-common-prefixes-and-directory-traversal.sh

diff --git a/dir.c b/dir.c
index 5dacacd469494215fa14fa0d07ca5f5dc7d6b6af..517a569e1042c41ded1410e37bcfa989970f9fc6 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -379,6 +379,13 @@ static int match_pathspec_item(const struct index_state *istate,
                               item->nowildcard_len - prefix))
                        return 0;
 
+               /*
+                * name has no wildcard, and it didn't match as a leading
+                * pathspec so return.
+                */
+               if (item->nowildcard_len == item->len)
+                       return 0;
+
                /*
                 * Here is where we would perform a wildmatch to check if
                 * "name" can be matched as a directory (or a prefix) against
index 54f80c62b86fcf81a6d00672557b3ff515f170f6..d6e161ddd877ff59085d59e01f33e1f1f1f18b40 100755 (executable)
@@ -92,7 +92,7 @@ test_expect_failure 'git ls-files -o untracked_repo/ does not recurse' '
        test_cmp expect actual
 '
 
-test_expect_failure 'git ls-files -o untracked_dir untracked_repo recurses into untracked_dir only' '
+test_expect_success 'git ls-files -o untracked_dir untracked_repo recurses into untracked_dir only' '
        cat <<-EOF >expect &&
        untracked_dir/empty
        untracked_repo/
@@ -110,7 +110,7 @@ test_expect_success 'git ls-files -o untracked_dir/ untracked_repo/ recurses int
        test_cmp expect actual
 '
 
-test_expect_failure 'git ls-files -o --directory untracked_dir untracked_repo does not recurse' '
+test_expect_success 'git ls-files -o --directory untracked_dir untracked_repo does not recurse' '
        cat <<-EOF >expect &&
        untracked_dir/
        untracked_repo/