Skip to content

Commit dd55fc0

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa6e1b2 commit dd55fc0

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

dir.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,15 +1868,17 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
18681868

18691869
/*
18701870
* 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
18721872
* 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)
18751876
* - DIR_HIDE_EMPTY_DIRECTORIES (because we have to determine if
18761877
* the directory is empty)
18771878
*/
18781879
if (!excluded &&
1879-
!(dir->flags & (DIR_SHOW_IGNORED_TOO |
1880+
!(dir->flags & (DIR_SHOW_IGNORED |
1881+
DIR_SHOW_IGNORED_TOO |
18801882
DIR_HIDE_EMPTY_DIRECTORIES))) {
18811883
return path_untracked;
18821884
}

t/t3001-ls-files-others-exclude.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ EOF
292292
test_cmp expect actual
293293
'
294294

295-
test_expect_failure 'ls-files with "**" patterns and --directory' '
295+
test_expect_success 'ls-files with "**" patterns and --directory' '
296296
# Expectation same as previous test
297297
git ls-files --directory -o -i --exclude "**/a.1" >actual &&
298298
test_cmp expect actual

t/t7300-clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ test_expect_success 'avoid traversing into ignored directories' '
769769
test_cmp trace.expect trace.relevant
770770
'
771771

772-
test_expect_failure 'traverse into directories that may have ignored entries' '
772+
test_expect_success 'traverse into directories that may have ignored entries' '
773773
test_when_finished rm -f output &&
774774
test_create_repo need-to-traverse-into-hierarchy &&
775775
(

0 commit comments

Comments
 (0)