git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] Teach ignore machinery about pattern "/"
Date: Fri, 25 May 2012 19:47:36 +0700	[thread overview]
Message-ID: <1337950056-26491-1-git-send-email-pclouds@gmail.com> (raw)

Pattern "/" is ambiguous because the slash can mean "anchor the
pattern to this location" (e.g. /path), but it can also mean
"match directories only" (e.g. path/). Currently git interprets it as
the latter except that 'path' is an empty string, which makes this
pattern totally useless.

On the other hand, it's intuitive to read '/' as "match root
directory", or equivalent to "/*". (The other way to see it is "match
all directories", which leads to the same result).

One may wonder why bother an "ignore all" pattern. The pattern is
useful when you want to keep just a small portion of the working
directory. But that's still a rare case.

A more popular case would be sparse checkout, where ignore rules are
used to _include_. The thus now "include all" pattern is used to say
"make a sparse checkout that includes everything except this and
this".

Recognize this special pattern and turn it the working equivalence
pattern "/*"

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c                              | 3 +++
 t/t3001-ls-files-others-exclude.sh | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/dir.c b/dir.c
index c6a98cc..b65d37c 100644
--- a/dir.c
+++ b/dir.c
@@ -308,6 +308,9 @@ void add_exclude(const char *string, const char *base,
 	int to_exclude = 1;
 	int flags = 0;
 
+	if (string[0] == '/' && string[1] == '\0')
+		string = "/*";
+
 	if (*string == '!') {
 		to_exclude = 0;
 		string++;
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index c8fe978..7cb790d 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -175,6 +175,12 @@ test_expect_success 'negated exclude matches can override previous ones' '
 	grep "^a.1" output
 '
 
+test_expect_success '"/" pattern is equivalent to "/*" (exclude all)' '
+	git ls-files --others --exclude=/ >output &&
+	: >expected &&
+	test_cmp expected output
+'
+
 test_expect_success 'subdirectory ignore (setup)' '
 	mkdir -p top/l1/l2 &&
 	(
-- 
1.7.10.2.549.g9354186

             reply	other threads:[~2012-05-25 12:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-25 12:47 Nguyễn Thái Ngọc Duy [this message]
2012-05-25 17:32 ` [PATCH] Teach ignore machinery about pattern "/" Junio C Hamano
2012-05-26  4:30   ` Nguyen Thai Ngoc Duy
2012-05-27  6:15     ` Junio C Hamano
2012-06-03 12:36     ` Nguyen Thai Ngoc Duy
2012-06-03 21:49       ` Junio C Hamano
2012-06-03 22:50         ` Caleb Marchent

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

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

  git send-email \
    --in-reply-to=1337950056-26491-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.
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 NNTP newsgroup(s).