]> git.ipfire.org Git - thirdparty/git.git/commitdiff
dir: traverse into untracked directories if they may have ignored subfiles
authorElijah Newren <newren@gmail.com>
Wed, 12 May 2021 17:28:20 +0000 (17:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 May 2021 23:45:03 +0000 (08:45 +0900)
A directory that is untracked does not imply that all files under it
should be categorized as untracked; in particular, if the caller is
interested in ignored files, many files or directories underneath the
untracked directory may be ignored.  We previously partially handled
this right with DIR_SHOW_IGNORED_TOO, but missed DIR_SHOW_IGNORED.  It
was not obvious, though, because the logic for untracked and excluded
files had been fused together making it harder to reason about.  The
previous commit split that logic out, making it easier to notice that
DIR_SHOW_IGNORED was missing.  Add it.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
t/t3001-ls-files-others-exclude.sh
t/t7300-clean.sh

diff --git a/dir.c b/dir.c
index 66261cf98b8321e28c8dd9162dea72067fa245e4..ed68b7e6412cd695db18e16031e8da510da4c3a0 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -1868,15 +1868,17 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
 
        /*
         * Other than the path_recurse case above, we only need to
-        * recurse into untracked directories if either of the following
+        * recurse into untracked directories if any of the following
         * bits is set:
-        *   - DIR_SHOW_IGNORED_TOO (because then we need to determine if
-        *                           there are ignored entries below)
+        *   - DIR_SHOW_IGNORED (because then we need to determine if
+        *                       there are ignored entries below)
+        *   - DIR_SHOW_IGNORED_TOO (same as above)
         *   - DIR_HIDE_EMPTY_DIRECTORIES (because we have to determine if
         *                                 the directory is empty)
         */
        if (!excluded &&
-           !(dir->flags & (DIR_SHOW_IGNORED_TOO |
+           !(dir->flags & (DIR_SHOW_IGNORED |
+                           DIR_SHOW_IGNORED_TOO |
                            DIR_HIDE_EMPTY_DIRECTORIES))) {
                return path_untracked;
        }
index ac05d1a1793190dbd9a86a3db0994cebff09098c..516c95ea0e82e6d65b913cbddd647c939fbaea93 100755 (executable)
@@ -292,7 +292,7 @@ EOF
        test_cmp expect actual
 '
 
-test_expect_failure 'ls-files with "**" patterns and --directory' '
+test_expect_success 'ls-files with "**" patterns and --directory' '
        # Expectation same as previous test
        git ls-files --directory -o -i --exclude "**/a.1" >actual &&
        test_cmp expect actual
index 21e48b3ba5919211c5f5bca9027fda4a8b482a01..0399701e6276d67ac8736128f24e8f8bf94a6b12 100755 (executable)
@@ -769,7 +769,7 @@ test_expect_success 'avoid traversing into ignored directories' '
        test_cmp trace.expect trace.relevant
 '
 
-test_expect_failure 'traverse into directories that may have ignored entries' '
+test_expect_success 'traverse into directories that may have ignored entries' '
        test_when_finished rm -f output &&
        test_create_repo need-to-traverse-into-hierarchy &&
        (