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

[PATCH 3/8] dir.c: git-status --ignored: don't list empty ignored directories

From
Karsten Blees <karsten.blees@gmail.com>
Date
Mar 18, 2013, 20:28 UTC
Message-ID
<514778FB.20603@gmail.com>
In-Reply-To
<514775FA.9080304@gmail.com>

'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 <blees@dcon.de>
---
 dir.c                      | 11 ++++-------
 t/t7061-wtstatus-ignore.sh | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/dir.c b/dir.c
index 7c9bc9c..fd1f088 100644
--- a/dir.c
+++ b/dir.c
@@ -1109,16 +1109,13 @@ static int treat_file(struct dir_struct *dir, struct strbuf *path, int exclude,
 	struct path_exclude_check check;
 	int exclude_file = 0;
 
+	/* Always exclude indexed files */
+	if (index_name_exists(&the_index, path->buf, path->len, ignore_case))
+		return 1;
+
 	if (exclude)
 		exclude_file = !(dir->flags & DIR_SHOW_IGNORED);
 	else if (dir->flags & DIR_SHOW_IGNORED) {
-		/* Always exclude indexed files */
-		struct cache_entry *ce = index_name_exists(&the_index,
-		    path->buf, path->len, ignore_case);
-
-		if (ce)
-			return 1;
-
 		path_exclude_check_init(&check, dir);
 
 		if (!is_path_excluded(&check, path->buf, path->len, dtype))
diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh
index 4ece129..28b7d95 100755
--- a/t/t7061-wtstatus-ignore.sh
+++ b/t/t7061-wtstatus-ignore.sh
@@ -122,10 +122,34 @@ cat >expected <<\EOF
 ?? .gitignore
 ?? actual
 ?? expected
+EOF
+
+test_expect_success 'status ignored tracked directory and ignored file with --ignore' '
+	echo "committed" >>.gitignore &&
+	git status --porcelain --ignored >actual &&
+	test_cmp expected actual
+'
+
+cat >expected <<\EOF
+?? .gitignore
+?? actual
+?? expected
+EOF
+
+test_expect_success 'status ignored tracked directory and ignored file with --ignore -u' '
+	git status --porcelain --ignored -u >actual &&
+	test_cmp expected actual
+'
+
+cat >expected <<\EOF
+?? .gitignore
+?? actual
+?? expected
 !! tracked/
 EOF
 
 test_expect_success 'status ignored tracked directory and uncommitted file with --ignore' '
+	echo "tracked" >.gitignore &&
 	: >tracked/uncommitted &&
 	git status --porcelain --ignored >actual &&
 	test_cmp expected actual
-- 
1.8.1.2.8021.g7e51819
Previous: Karsten BleesNext: Karsten Blees
Message 3 of 10 in “dir.c: git-status --ignored: don't drop ignored directories”
  1. 1/8 dir.c: git-status --ignored: don't drop ignored directoriesKarsten Blees, Mar 18, 2013
  2. 2/8 dir.c: git-status --ignored: don't list files in ignored directoriesKarsten Blees, Mar 18, 2013
  3. 3/8 dir.c: git-status --ignored: don't list empty ignored directoriesKarsten Blees, Mar 18, 2013
  4. 4/8 dir.c: git-status --ignored: don't list empty directories as ignoredKarsten Blees, Mar 18, 2013
  5. Eric SunshineMar 18, 2013
  6. 5/8 dir.c: move prep_exclude and factor out parts of last_exclude_matchingKarsten Blees, Mar 18, 2013
  7. 6/8 dir.c: unify is_excluded and is_path_excluded APIsKarsten Blees, Mar 18, 2013
  8. Eric SunshineMar 18, 2013
  9. 7/8 dir.c: replace is_path_excluded with now equivalent is_excluded APIKarsten Blees, Mar 18, 2013
  10. 8/8 dir.c: git-status: avoid is_excluded checks for tracked filesKarsten Blees, Mar 18, 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.