提交 859b7f1d 编写于 作者: L Linus Torvalds 提交者: Junio C Hamano

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: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 42ebeb9d
......@@ -387,7 +387,9 @@ Glob magic is incompatible with literal magic.
exclude;;
After a path matches any non-exclude pathspec, it will be run
through all exclude pathspec (magic signature: `!` or its
synonym `^`). If it matches, the path is ignored.
synonym `^`). If it matches, the path is ignored. When there
is no non-exclude pathspec, the exclusion is applied to the
result set as if invoked without any pathspec.
--
[[def_parent]]parent::
......
......@@ -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)
......
......@@ -25,8 +25,10 @@ EOF
test_cmp expect actual
'
test_expect_success 'exclude only should error out' '
test_must_fail git log --oneline --format=%s -- ":(exclude)sub"
test_expect_success 'exclude only no longer errors out' '
git log --oneline --format=%s -- . ":(exclude)sub" >expect &&
git log --oneline --format=%s -- ":(exclude)sub" >actual &&
test_cmp expect actual
'
test_expect_success 't_e_i() exclude sub' '
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册