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

[PATCH] dir.c: fix ignore processing within not-ignored directories

From
Karsten Blees <karsten.blees@gmail.com>
Date
May 29, 2013, 20:32 UTC
Message-ID
<51A665E4.9080307@gmail.com>
In-Reply-To
<51A62A96.6040009@gmail.com>

As of 95c6f271 "dir.c: unify is_excluded and is_path_excluded APIs", the is_excluded API no longer recurses into directories that match an ignore pattern, and returns the directory's ignored state for all contained paths.

This is OK for normal ignore patterns, i.e. ignoring a directory affects the entire contents recursively.

Unfortunately, this also "works" for negated ignore patterns ('!dir'), i.e. the entire contents is "not-ignored" recursively, regardless of ignore patterns that match the contents directly.

In prep_exclude, skip recursing into a directory only if it is really ignored (i.e. the ignore pattern is not negated).

Signed-off-by: Karsten Blees <blees@dcon.de>
---

Also available here: https://github.com/kblees/git/tree/kb/ignore-within-not-ignored-dir git pull git://github.com/kblees/git.git kb/ignore-within-not-ignored-dir

 dir.c                              |  3 +++
 t/t3001-ls-files-others-exclude.sh | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
diff --git a/dir.c b/dir.c
index a5926fb..13858fe 100644
--- a/dir.c
+++ b/dir.c
@@ -821,6 +821,9 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
 				dir->basebuf, stk->baselen - 1,
 				dir->basebuf + current, &dt);
 			dir->basebuf[stk->baselen - 1] = '/';
+			if (dir->exclude &&
+			    dir->exclude->flags & EXC_FLAG_NEGATIVE)
+				dir->exclude = NULL;
 			if (dir->exclude) {
 				dir->basebuf[stk->baselen] = 0;
 				dir->exclude_stack = stk;
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index 4e3735f..f0421c0 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -175,6 +175,24 @@ test_expect_success 'negated exclude matches can override previous ones' '
 	grep "^a.1" output
 '
 
+test_expect_success 'excluded directory overrides content patterns' '
+
+	git ls-files --others --exclude="one" --exclude="!one/a.1" >output &&
+	if grep "^one/a.1" output
+	then
+		false
+	fi
+'
+
+test_expect_success 'negated directory doesn'\''t affect content patterns' '
+
+	git ls-files --others --exclude="!one" --exclude="one/a.1" >output &&
+	if grep "^one/a.1" output
+	then
+		false
+	fi
+'
+
 test_expect_success 'subdirectory ignore (setup)' '
 	mkdir -p top/l1/l2 &&
 	(
-- 
1.8.3.8097.gdc25f02.dirty
Previous: Øystein WalleNext: Duy Nguyen
Message 9 of 16 in “1.8.3 - gitignore not being parsed correctly on OS X; regex support is broken?”
  1. Misty De MeoMay 28, 2013
  2. Øystein WalleMay 28, 2013
  3. Junio C HamanoMay 28, 2013
  4. Duy NguyenMay 29, 2013
  5. Duy NguyenMay 29, 2013
  6. David AguilarMay 29, 2013
  7. Karsten BleesMay 29, 2013
  8. Øystein WalleMay 29, 2013
  9. dir.c: fix ignore processing within not-ignored directoriesKarsten Blees, May 29, 2013
  10. Duy NguyenJun 1, 2013
  11. Junio C HamanoJun 2, 2013
  12. Karsten BleesJun 4, 2013
  13. t/README: test_must_fail is for testing GitJunio C Hamano, Jun 4, 2013
  14. Philip OakleyJun 4, 2013
  15. Junio C HamanoJun 4, 2013
  16. Philip OakleyJun 4, 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.