dir.c: git-clean -d -X: don't delete tracked directories

The notion of "ignored tracked" directories introduced in 721ac4ed "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 <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Apr 15, 2013 at 21:10 UTC 5bd8e2d894be3a27e9b32b062ff224cc2396b69c
4 files changed +66 -11
dir.c
+3 -8
@@ -941,8 +941,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
941
942 static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
943 {
944 - if (!(dir->flags & DIR_SHOW_IGNORED) &&
945 - cache_name_exists(pathname, len, ignore_case))
944 + if (cache_name_exists(pathname, len, ignore_case))
945 return NULL;
946
947 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)
1043 * traversal routine.
1044 *
1045 * 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.
1048 *
1049 * Case 2: If we *already* have that directory name as a gitlink,
1050 * 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,
1079 /* The "len-1" is to strip the final '/' */
1080 switch (directory_exists_in_index(dirname, len-1)) {
1081 case index_directory:
1084 - if ((dir->flags & DIR_SHOW_OTHER_DIRECTORIES) && exclude)
1085 - break;
1086 -
1082 return recurse_into_directory;
1083
1084 case index_gitdir:
t/t3001-ls-files-others-exclude.sh
+26
@@ -237,6 +237,32 @@ test_expect_success 'hide empty ignored directory with --no-empty-directory' '
237 test_cmp expect actual
238 '
239
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 +
266 test_expect_success 'pattern matches prefix completely' '
267 : >expect &&
268 git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
t/t7061-wtstatus-ignore.sh
+3 -3
@@ -186,7 +186,7 @@ cat >expected <<\EOF
186 ?? .gitignore
187 ?? actual
188 ?? expected
189 -!! tracked/
189 +!! tracked/uncommitted
190 EOF
191
192 test_expect_success 'status ignored tracked directory and uncommitted file with --ignore' '
@@ -212,7 +212,7 @@ cat >expected <<\EOF
212 ?? .gitignore
213 ?? actual
214 ?? expected
215 -!! tracked/
215 +!! tracked/ignored/
216 EOF
217
218 test_expect_success 'status ignored tracked directory with uncommitted file in untracked subdir with --ignore' '
@@ -239,7 +239,7 @@ cat >expected <<\EOF
239 ?? .gitignore
240 ?? actual
241 ?? expected
242 -!! tracked/
242 +!! tracked/ignored/uncommitted
243 EOF
244
245 test_expect_success 'status ignored tracked directory with uncommitted file in tracked subdir with --ignore' '
t/t7300-clean.sh
+34
@@ -298,6 +298,23 @@ test_expect_success 'git clean -d -x' '
298
299 '
300
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 +
318 test_expect_success 'git clean -X' '
319
320 mkdir -p build docs &&
@@ -332,6 +349,23 @@ test_expect_success 'git clean -d -X' '
349
350 '
351
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 +
369 test_expect_success 'clean.requireForce defaults to true' '
370
371 git config --unset clean.requireForce &&