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@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html