Skip to content

Commit 0104c9e

Browse files
kbleesgitster
authored andcommitted
dir.c: git-status --ignored: don't list empty ignored directories
'git-status --ignored' lists ignored tracked directories without any ignored files if a tracked file happens to match an exclude pattern. Always exclude tracked files. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 289ff55 commit 0104c9e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

dir.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,16 +1153,13 @@ static int treat_file(struct dir_struct *dir, struct strbuf *path, int exclude,
11531153
struct path_exclude_check check;
11541154
int exclude_file = 0;
11551155

1156+
/* Always exclude indexed files */
1157+
if (index_name_exists(&the_index, path->buf, path->len, ignore_case))
1158+
return 1;
1159+
11561160
if (exclude)
11571161
exclude_file = !(dir->flags & DIR_SHOW_IGNORED);
11581162
else if (dir->flags & DIR_SHOW_IGNORED) {
1159-
/* Always exclude indexed files */
1160-
struct cache_entry *ce = index_name_exists(&the_index,
1161-
path->buf, path->len, ignore_case);
1162-
1163-
if (ce)
1164-
return 1;
1165-
11661163
path_exclude_check_init(&check, dir);
11671164

11681165
if (!is_path_excluded(&check, path->buf, path->len, dtype))

t/t7061-wtstatus-ignore.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ test_expect_success 'status ignored tracked directory with --ignore -u' '
118118
test_cmp expected actual
119119
'
120120

121+
cat >expected <<\EOF
122+
?? .gitignore
123+
?? actual
124+
?? expected
125+
EOF
126+
127+
test_expect_success 'status ignored tracked directory and ignored file with --ignore' '
128+
echo "committed" >>.gitignore &&
129+
git status --porcelain --ignored >actual &&
130+
test_cmp expected actual
131+
'
132+
133+
cat >expected <<\EOF
134+
?? .gitignore
135+
?? actual
136+
?? expected
137+
EOF
138+
139+
test_expect_success 'status ignored tracked directory and ignored file with --ignore -u' '
140+
git status --porcelain --ignored -u >actual &&
141+
test_cmp expected actual
142+
'
143+
121144
cat >expected <<\EOF
122145
?? .gitignore
123146
?? actual
@@ -126,6 +149,7 @@ cat >expected <<\EOF
126149
EOF
127150

128151
test_expect_success 'status ignored tracked directory and uncommitted file with --ignore' '
152+
echo "tracked" >.gitignore &&
129153
: >tracked/uncommitted &&
130154
git status --porcelain --ignored >actual &&
131155
test_cmp expected actual

0 commit comments

Comments
 (0)