aboutsummaryrefslogtreecommitdiff
path: root/pathspec.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-02-07 21:08:15 -0800
committerJunio C Hamano <gitster@pobox.com>2017-02-10 13:19:40 -0800
commit859b7f1d0e742493d2a9396794cd9040213ad846 (patch)
tree8dd558e38011f8192a12ab5e371a5656062130c7 /pathspec.c
parent42ebeb9d07de3c6d3a263f8ebce0508e489e5cc9 (diff)
downloadgit-859b7f1d0e742493d2a9396794cd9040213ad846.tar.gz
git-859b7f1d0e742493d2a9396794cd9040213ad846.tar.xz
pathspec: don't error out on all-exclusionary pathspec patterns
Instead of erroring out and telling the user that they should add a positive pattern that covers everything else, just _do_ that. For commands where we honor the current cwd by default (ie grep, ls-files etc), we make that default positive pathspec be the current working directory. And for commands that default to the whole project (ie diff, log, etc), the default positive pathspec is the whole project. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pathspec.c')
-rw-r--r--pathspec.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/pathspec.c b/pathspec.c
index ecad03406..b961f00c8 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -522,7 +522,7 @@ void parse_pathspec(struct pathspec *pathspec,
}
pathspec->nr = n;
- ALLOC_ARRAY(pathspec->items, n);
+ ALLOC_ARRAY(pathspec->items, n + 1);
item = pathspec->items;
prefixlen = prefix ? strlen(prefix) : 0;
@@ -546,10 +546,15 @@ void parse_pathspec(struct pathspec *pathspec,
pathspec->magic |= item[i].magic;
}
- if (nr_exclude == n)
- die(_("There is nothing to exclude from by :(exclude) patterns.\n"
- "Perhaps you forgot to add either ':/' or '.' ?"));
-
+ /*
+ * If everything is an exclude pattern, add one positive pattern
+ * that matches everyting. We allocated an extra one for this.
+ */
+ if (nr_exclude == n) {
+ int plen = (!(flags & PATHSPEC_PREFER_CWD)) ? 0 : prefixlen;
+ init_pathspec_item(item + n, 0, prefix, plen, "");
+ pathspec->nr++;
+ }
if (pathspec->magic & PATHSPEC_MAXDEPTH) {
if (flags & PATHSPEC_KEEP_ORDER)