dir: traverse into untracked directories if they may have ignored subfiles
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>
Elijah Newren committed
May 12, 2021 at 17:28 UTC
dd55fc0df15c338a8dbec6dec6ca6b58edc8acef
3 files changed
+8
-6
dir.c
+6
-4
@@ -1868,15 +1868,17 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
1868
1869
/*
1870
* Other than the path_recurse case above, we only need to
1871
- * recurse into untracked directories if either of the following
1871
+ * recurse into untracked directories if any of the following
1872
* bits is set:
1873
- * - DIR_SHOW_IGNORED_TOO (because then we need to determine if
1874
- * there are ignored entries below)
1873
+ * - DIR_SHOW_IGNORED (because then we need to determine if
1874
+ * there are ignored entries below)
1875
+ * - DIR_SHOW_IGNORED_TOO (same as above)
1876
* - DIR_HIDE_EMPTY_DIRECTORIES (because we have to determine if
1877
* the directory is empty)
1878
*/
1879
if (!excluded &&
1879
- !(dir->flags & (DIR_SHOW_IGNORED_TOO |
1880
+ !(dir->flags & (DIR_SHOW_IGNORED |
1881
+ DIR_SHOW_IGNORED_TOO |
1882
DIR_HIDE_EMPTY_DIRECTORIES))) {
1883
return path_untracked;
1884
}
t/t3001-ls-files-others-exclude.sh
+1
-1
@@ -292,7 +292,7 @@ EOF
292
test_cmp expect actual
293
'
294
295
-test_expect_failure 'ls-files with "**" patterns and --directory' '
295
+test_expect_success 'ls-files with "**" patterns and --directory' '
296
# Expectation same as previous test
297
git ls-files --directory -o -i --exclude "**/a.1" >actual &&
298
test_cmp expect actual
t/t7300-clean.sh
+1
-1
@@ -769,7 +769,7 @@ test_expect_success 'avoid traversing into ignored directories' '
769
test_cmp trace.expect trace.relevant
770
'
771
772
-test_expect_failure 'traverse into directories that may have ignored entries' '
772
+test_expect_success 'traverse into directories that may have ignored entries' '
773
test_when_finished rm -f output &&
774
test_create_repo need-to-traverse-into-hierarchy &&
775
(