Skip to content

Commit 5bd8e2d

Browse files
kbleesgitster
authored andcommitted
dir.c: git-clean -d -X: don't delete tracked directories
The notion of "ignored tracked" directories introduced in 721ac4e "dir.c: Make git-status --ignored more consistent" has a few unwanted side effects: - git-clean -d -X: deletes ignored tracked directories. git-clean should never delete tracked content. - git-ls-files --ignored --other --directory: lists ignored tracked directories instead of "other" directories. - git-status --ignored: lists ignored tracked directories while contained files may be listed as modified. Paths listed by git-status should be disjoint (except in long format where a path may be listed in both the staged and unstaged section). Additionally, the current behaviour violates documentation in gitignore(5) ("Specifies intentionally *untracked* files to ignore") and Documentation/ technical/api-directory-listing.txt ("DIR_SHOW_OTHER_DIRECTORIES: Include a directory that is *not tracked*."). In dir.c::treat_directory, remove the special handling of ignored tracked directories, so that the DIR_SHOW_OTHER_DIRECTORIES flag only affects "other" (i.e. untracked) directories. In dir.c::dir_add_name, check that added paths are untracked even if DIR_SHOW_IGNORED is set. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent be8a84c commit 5bd8e2d

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

dir.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
941941

942942
static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
943943
{
944-
if (!(dir->flags & DIR_SHOW_IGNORED) &&
945-
cache_name_exists(pathname, len, ignore_case))
944+
if (cache_name_exists(pathname, len, ignore_case))
946945
return NULL;
947946

948947
ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
@@ -1044,9 +1043,8 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
10441043
* traversal routine.
10451044
*
10461045
* Case 1: If we *already* have entries in the index under that
1047-
* directory name, we recurse into the directory to see all the files,
1048-
* unless the directory is excluded and we want to show ignored
1049-
* directories
1046+
* directory name, we always recurse into the directory to see
1047+
* all the files.
10501048
*
10511049
* Case 2: If we *already* have that directory name as a gitlink,
10521050
* we always continue to see it as a gitlink, regardless of whether
@@ -1081,9 +1079,6 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
10811079
/* The "len-1" is to strip the final '/' */
10821080
switch (directory_exists_in_index(dirname, len-1)) {
10831081
case index_directory:
1084-
if ((dir->flags & DIR_SHOW_OTHER_DIRECTORIES) && exclude)
1085-
break;
1086-
10871082
return recurse_into_directory;
10881083

10891084
case index_gitdir:

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,32 @@ test_expect_success 'hide empty ignored directory with --no-empty-directory' '
237237
test_cmp expect actual
238238
'
239239

240+
test_expect_success 'show/hide empty ignored sub-directory (setup)' '
241+
> top/l1/tracked &&
242+
(
243+
cd top &&
244+
git add -f l1/tracked
245+
)
246+
'
247+
248+
test_expect_success 'show empty ignored sub-directory with --directory' '
249+
(
250+
cd top &&
251+
git ls-files -o -i --exclude l1 --directory
252+
) >actual &&
253+
echo l1/l2/ >expect &&
254+
test_cmp expect actual
255+
'
256+
257+
test_expect_success 'hide empty ignored sub-directory with --no-empty-directory' '
258+
(
259+
cd top &&
260+
git ls-files -o -i --exclude l1 --directory --no-empty-directory
261+
) >actual &&
262+
>expect &&
263+
test_cmp expect actual
264+
'
265+
240266
test_expect_success 'pattern matches prefix completely' '
241267
: >expect &&
242268
git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&

t/t7061-wtstatus-ignore.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ cat >expected <<\EOF
186186
?? .gitignore
187187
?? actual
188188
?? expected
189-
!! tracked/
189+
!! tracked/uncommitted
190190
EOF
191191

192192
test_expect_success 'status ignored tracked directory and uncommitted file with --ignore' '
@@ -212,7 +212,7 @@ cat >expected <<\EOF
212212
?? .gitignore
213213
?? actual
214214
?? expected
215-
!! tracked/
215+
!! tracked/ignored/
216216
EOF
217217

218218
test_expect_success 'status ignored tracked directory with uncommitted file in untracked subdir with --ignore' '
@@ -239,7 +239,7 @@ cat >expected <<\EOF
239239
?? .gitignore
240240
?? actual
241241
?? expected
242-
!! tracked/
242+
!! tracked/ignored/uncommitted
243243
EOF
244244

245245
test_expect_success 'status ignored tracked directory with uncommitted file in tracked subdir with --ignore' '

t/t7300-clean.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,23 @@ test_expect_success 'git clean -d -x' '
298298
299299
'
300300

301+
test_expect_success 'git clean -d -x with ignored tracked directory' '
302+
303+
mkdir -p build docs &&
304+
touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
305+
git clean -d -x -e src &&
306+
test -f Makefile &&
307+
test -f README &&
308+
test -f src/part1.c &&
309+
test -f src/part2.c &&
310+
test ! -f a.out &&
311+
test -f src/part3.c &&
312+
test ! -d docs &&
313+
test ! -f obj.o &&
314+
test ! -d build
315+
316+
'
317+
301318
test_expect_success 'git clean -X' '
302319
303320
mkdir -p build docs &&
@@ -332,6 +349,23 @@ test_expect_success 'git clean -d -X' '
332349
333350
'
334351

352+
test_expect_success 'git clean -d -X with ignored tracked directory' '
353+
354+
mkdir -p build docs &&
355+
touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
356+
git clean -d -X -e src &&
357+
test -f Makefile &&
358+
test -f README &&
359+
test -f src/part1.c &&
360+
test -f src/part2.c &&
361+
test -f a.out &&
362+
test ! -f src/part3.c &&
363+
test -f docs/manual.txt &&
364+
test ! -f obj.o &&
365+
test ! -d build
366+
367+
'
368+
335369
test_expect_success 'clean.requireForce defaults to true' '
336370
337371
git config --unset clean.requireForce &&

0 commit comments

Comments
 (0)