git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 07/14] dir.c: git-clean -d -X: don't delete tracked directories

From
Karsten Blees <karsten.blees@gmail.com>
Date
Apr 15, 2013, 19:10 UTC
Message-ID
<516C508D.2050200@gmail.com>
In-Reply-To
<516C4F27.30203@gmail.com>

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>
---
 dir.c                              | 11 +++--------
 t/t3001-ls-files-others-exclude.sh | 26 ++++++++++++++++++++++++++
 t/t7061-wtstatus-ignore.sh         |  6 +++---
 t/t7300-clean.sh                   | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 11 deletions(-)
diff --git a/dir.c b/dir.c
index 822e501..f10fb69 100644
--- a/dir.c
+++ b/dir.c
@@ -897,8 +897,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
 
 static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
 {
-	if (!(dir->flags & DIR_SHOW_IGNORED) &&
-	    cache_name_exists(pathname, len, ignore_case))
+	if (cache_name_exists(pathname, len, ignore_case))
 		return NULL;
 
 	ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
@@ -1000,9 +999,8 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
  * traversal routine.
  *
  * Case 1: If we *already* have entries in the index under that
- * directory name, we recurse into the directory to see all the files,
- * unless the directory is excluded and we want to show ignored
- * directories
+ * directory name, we always recurse into the directory to see
+ * all the files.
  *
  * Case 2: If we *already* have that directory name as a gitlink,
  * we always continue to see it as a gitlink, regardless of whether
@@ -1037,9 +1035,6 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
 	/* The "len-1" is to strip the final '/' */
 	switch (directory_exists_in_index(dirname, len-1)) {
 	case index_directory:
-		if ((dir->flags & DIR_SHOW_OTHER_DIRECTORIES) && exclude)
-			break;
-
 		return recurse_into_directory;
 
 	case index_gitdir:
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index 859da35..ec4fae2 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -237,6 +237,32 @@ test_expect_success 'hide empty ignored directory with --no-empty-directory' '
 	test_cmp expect actual
 '
 
+test_expect_success 'show/hide empty ignored sub-directory (setup)' '
+	> top/l1/tracked &&
+	(
+		cd top &&
+		git add -f l1/tracked
+	)
+'
+
+test_expect_success 'show empty ignored sub-directory with --directory' '
+	(
+		cd top &&
+		git ls-files -o -i --exclude l1 --directory
+	) >actual &&
+	echo l1/l2/ >expect &&
+	test_cmp expect actual
+'
+
+test_expect_success 'hide empty ignored sub-directory with --no-empty-directory' '
+	(
+		cd top &&
+		git ls-files -o -i --exclude l1 --directory --no-empty-directory
+	) >actual &&
+	>expect &&
+	test_cmp expect actual
+'
+
 test_expect_success 'pattern matches prefix completely' '
 	: >expect &&
 	git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh
index 4c6f145..460789b 100755
--- a/t/t7061-wtstatus-ignore.sh
+++ b/t/t7061-wtstatus-ignore.sh
@@ -186,7 +186,7 @@ cat >expected <<\EOF
 ?? .gitignore
 ?? actual
 ?? expected
-!! tracked/
+!! tracked/uncommitted
 EOF
 
 test_expect_success 'status ignored tracked directory and uncommitted file with --ignore' '
@@ -212,7 +212,7 @@ cat >expected <<\EOF
 ?? .gitignore
 ?? actual
 ?? expected
-!! tracked/
+!! tracked/ignored/
 EOF
 
 test_expect_success 'status ignored tracked directory with uncommitted file in untracked subdir with --ignore' '
@@ -239,7 +239,7 @@ cat >expected <<\EOF
 ?? .gitignore
 ?? actual
 ?? expected
-!! tracked/
+!! tracked/ignored/uncommitted
 EOF
 
 test_expect_success 'status ignored tracked directory with uncommitted file in tracked subdir with --ignore' '
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index ccfb54d..710be90 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -298,6 +298,23 @@ test_expect_success 'git clean -d -x' '
 
 '
 
+test_expect_success 'git clean -d -x with ignored tracked directory' '
+
+	mkdir -p build docs &&
+	touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
+	git clean -d -x -e src &&
+	test -f Makefile &&
+	test -f README &&
+	test -f src/part1.c &&
+	test -f src/part2.c &&
+	test ! -f a.out &&
+	test -f src/part3.c &&
+	test ! -d docs &&
+	test ! -f obj.o &&
+	test ! -d build
+
+'
+
 test_expect_success 'git clean -X' '
 
 	mkdir -p build docs &&
@@ -332,6 +349,23 @@ test_expect_success 'git clean -d -X' '
 
 '
 
+test_expect_success 'git clean -d -X with ignored tracked directory' '
+
+	mkdir -p build docs &&
+	touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
+	git clean -d -X -e src &&
+	test -f Makefile &&
+	test -f README &&
+	test -f src/part1.c &&
+	test -f src/part2.c &&
+	test -f a.out &&
+	test ! -f src/part3.c &&
+	test -f docs/manual.txt &&
+	test ! -f obj.o &&
+	test ! -d build
+
+'
+
 test_expect_success 'clean.requireForce defaults to true' '
 
 	git config --unset clean.requireForce &&
-- 
1.8.1.2.8026.g2b66448.dirty
Previous: Karsten BleesNext: Karsten Blees
Message 20 of 36 in “Improve git-status --ignored”
  1. 0/8 Improve git-status --ignoredKarsten Blees, Mar 18, 2013
  2. Junio C HamanoMar 19, 2013
  3. Duy NguyenMar 19, 2013
  4. Karsten BleesMar 19, 2013
  5. Junio C HamanoMar 19, 2013
  6. Duy NguyenMar 19, 2013
  7. 00/14 Improve git-status --ignoredKarsten Blees, Apr 15, 2013
  8. 01/14 dir.c: git-status --ignored: don't drop ignored directoriesKarsten Blees, Apr 15, 2013
  9. Ramkumar RamachandraApr 16, 2013
  10. Karsten BleesApr 17, 2013
  11. 02/14 dir.c: git-status --ignored: don't list files in ignored directoriesKarsten Blees, Apr 15, 2013
  12. read_revisions_from_stdin: make copies for handle_revision_argThomas Rast, Apr 16, 2013
  13. Junio C HamanoApr 16, 2013
  14. 03/14 dir.c: git-status --ignored: don't list empty ignored directoriesKarsten Blees, Apr 15, 2013
  15. Ramkumar RamachandraApr 16, 2013
  16. Karsten BleesApr 17, 2013
  17. 04/14 dir.c: git-ls-files --directories: don't hide empty directoriesKarsten Blees, Apr 15, 2013
  18. 05/14 dir.c: git-status --ignored: don't list empty directories as ignoredKarsten Blees, Apr 15, 2013
  19. 06/14 dir.c: make 'git-status --ignored' work within leading directoriesKarsten Blees, Apr 15, 2013
  20. 07/14 dir.c: git-clean -d -X: don't delete tracked directoriesKarsten Blees, Apr 15, 2013
  21. 08/14 dir.c: factor out parts of last_exclude_matching for later reuseKarsten Blees, Apr 15, 2013
  22. 09/14 dir.c: move prep_excludeKarsten Blees, Apr 15, 2013
  23. 10/14 dir.c: unify is_excluded and is_path_excluded APIsKarsten Blees, Apr 15, 2013
  24. Junio C HamanoApr 15, 2013
  25. 11/14 dir.c: replace is_path_excluded with now equivalent is_excluded APIKarsten Blees, Apr 15, 2013
  26. 12/14 dir.c: git-status: avoid is_excluded checks for tracked filesKarsten Blees, Apr 15, 2013
  27. 13/14 dir.c: git-status --ignored: don't scan the work tree three timesKarsten Blees, Apr 15, 2013
  28. 14/14 dir.c: git-status --ignored: don't scan the work tree twiceKarsten Blees, Apr 15, 2013
  29. Junio C HamanoApr 15, 2013
  30. Junio C HamanoApr 15, 2013
  31. Karsten BleesApr 15, 2013
  32. Junio C HamanoApr 15, 2013
  33. Karsten BleesApr 17, 2013
  34. Junio C HamanoApr 17, 2013
  35. 11/14 dir.c: replace is_path_excluded with now equivalent is_excluded APIKarsten Blees, Apr 17, 2013
  36. 14/14 dir.c: git-status --ignored: don't scan the work tree twiceKarsten Blees, Apr 17, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.