git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Karsten Blees <karsten.blees@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Duy Nguyen" <pclouds@gmail.com>,
	"Git Mailing List" <git@vger.kernel.org>,
	"Misty De Meo" <misty@brew.sh>,
	"Øystein Walle" <oystwa@gmail.com>
Subject: [PATCH] dir.c: fix ignore processing within not-ignored directories
Date: Wed, 29 May 2013 22:32:36 +0200	[thread overview]
Message-ID: <51A665E4.9080307@gmail.com> (raw)
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

  parent reply	other threads:[~2013-05-29 20:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-28 17:54 1.8.3 - gitignore not being parsed correctly on OS X; regex support is broken? Misty De Meo
2013-05-28 21:35 ` Øystein Walle
2013-05-28 21:59   ` Junio C Hamano
2013-05-29  3:41 ` Duy Nguyen
2013-05-29  4:19   ` Duy Nguyen
2013-05-29  7:43     ` David Aguilar
2013-05-29 16:19     ` Karsten Blees
2013-05-29 18:49       ` Øystein Walle
2013-05-29 20:32       ` Karsten Blees [this message]
2013-06-01 10:44         ` [PATCH] dir.c: fix ignore processing within not-ignored directories Duy Nguyen
2013-06-02 19:25           ` Junio C Hamano
2013-06-04 16:10             ` Karsten Blees
2013-06-04 16:50             ` [PATCH] t/README: test_must_fail is for testing Git Junio C Hamano
2013-06-04 20:16               ` Philip Oakley
2013-06-04 20:49                 ` Junio C Hamano
2013-06-04 21:12                   ` Philip Oakley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51A665E4.9080307@gmail.com \
    --to=karsten.blees@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=misty@brew.sh \
    --cc=oystwa@gmail.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).