Skip to content

Commit 184d2a8

Browse files
kbleesgitster
authored andcommitted
dir.c: git-ls-files --directories: don't hide empty directories
'git-ls-files --ignored --directories' hides empty directories even though --no-empty-directory was not specified. Treat the DIR_HIDE_EMPTY_DIRECTORIES flag independently from DIR_SHOW_IGNORED to make all git-ls-files options work as expected. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0104c9e commit 184d2a8

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

dir.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,15 +1120,13 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
11201120
if ((dir->flags & DIR_SHOW_IGNORED) && !exclude) {
11211121
int ignored;
11221122
dir->flags &= ~DIR_SHOW_IGNORED;
1123-
dir->flags |= DIR_HIDE_EMPTY_DIRECTORIES;
11241123
ignored = read_directory_recursive(dir, dirname, len, 1, simplify);
1125-
dir->flags &= ~DIR_HIDE_EMPTY_DIRECTORIES;
11261124
dir->flags |= DIR_SHOW_IGNORED;
11271125

11281126
return ignored ? ignore_directory : show_directory;
11291127
}
1130-
if (!(dir->flags & DIR_SHOW_IGNORED) &&
1131-
!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
1128+
1129+
if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
11321130
return show_directory;
11331131
if (!read_directory_recursive(dir, dirname, len, 1, simplify))
11341132
return ignore_directory;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,29 @@ test_expect_success 'subdirectory ignore (l1)' '
214214
test_cmp expect actual
215215
'
216216

217+
test_expect_success 'show/hide empty ignored directory (setup)' '
218+
rm top/l1/l2/l1 &&
219+
rm top/l1/.gitignore
220+
'
221+
222+
test_expect_success 'show empty ignored directory with --directory' '
223+
(
224+
cd top &&
225+
git ls-files -o -i --exclude l1 --directory
226+
) >actual &&
227+
echo l1/ >expect &&
228+
test_cmp expect actual
229+
'
230+
231+
test_expect_success 'hide empty ignored directory with --no-empty-directory' '
232+
(
233+
cd top &&
234+
git ls-files -o -i --exclude l1 --directory --no-empty-directory
235+
) >actual &&
236+
>expect &&
237+
test_cmp expect actual
238+
'
239+
217240
test_expect_success 'pattern matches prefix completely' '
218241
: >expect &&
219242
git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
526526
dir.nr = 0;
527527
dir.flags = DIR_SHOW_IGNORED;
528528
if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
529-
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
529+
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
530530
fill_directory(&dir, s->pathspec);
531531
for (i = 0; i < dir.nr; i++) {
532532
struct dir_entry *ent = dir.entries[i];

0 commit comments

Comments
 (0)