git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Teach ignore machinery about pattern "/"
@ 2012-05-25 12:47 Nguyễn Thái Ngọc Duy
  2012-05-25 17:32 ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-05-25 12:47 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-06-03 22:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-25 12:47 [PATCH] Teach ignore machinery about pattern "/" Nguyễn Thái Ngọc Duy
2012-05-25 17:32 ` 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

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).