Merge branch 'lt/pathspec-negative'
The "negative" pathspec feature was somewhat more cumbersome to use than necessary in that its short-hand used "!" which needed to be escaped from shells, and it required "exclude from what?" specified. * lt/pathspec-negative: pathspec: don't error out on all-exclusionary pathspec patterns pathspec magic: add '^' as alias for '!'
This commit is contained in:
commit
015fba3834
@ -386,8 +386,10 @@ Glob magic is incompatible with literal magic.
|
|||||||
|
|
||||||
exclude;;
|
exclude;;
|
||||||
After a path matches any non-exclude pathspec, it will be run
|
After a path matches any non-exclude pathspec, it will be run
|
||||||
through all exclude pathspec (magic signature: `!`). If it
|
through all exclude pathspec (magic signature: `!` or its
|
||||||
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::
|
[[def_parent]]parent::
|
||||||
|
21
pathspec.c
21
pathspec.c
@ -224,6 +224,12 @@ static const char *parse_short_magic(unsigned *magic, const char *elem)
|
|||||||
char ch = *pos;
|
char ch = *pos;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* Special case alias for '!' */
|
||||||
|
if (ch == '^') {
|
||||||
|
*magic |= PATHSPEC_EXCLUDE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_pathspec_magic(ch))
|
if (!is_pathspec_magic(ch))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -516,7 +522,7 @@ void parse_pathspec(struct pathspec *pathspec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pathspec->nr = n;
|
pathspec->nr = n;
|
||||||
ALLOC_ARRAY(pathspec->items, n);
|
ALLOC_ARRAY(pathspec->items, n + 1);
|
||||||
item = pathspec->items;
|
item = pathspec->items;
|
||||||
prefixlen = prefix ? strlen(prefix) : 0;
|
prefixlen = prefix ? strlen(prefix) : 0;
|
||||||
|
|
||||||
@ -540,10 +546,15 @@ void parse_pathspec(struct pathspec *pathspec,
|
|||||||
pathspec->magic |= item[i].magic;
|
pathspec->magic |= item[i].magic;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nr_exclude == n)
|
/*
|
||||||
die(_("There is nothing to exclude from by :(exclude) patterns.\n"
|
* If everything is an exclude pattern, add one positive pattern
|
||||||
"Perhaps you forgot to add either ':/' or '.' ?"));
|
* 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 (pathspec->magic & PATHSPEC_MAXDEPTH) {
|
||||||
if (flags & PATHSPEC_KEEP_ORDER)
|
if (flags & PATHSPEC_KEEP_ORDER)
|
||||||
|
@ -25,8 +25,10 @@ EOF
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'exclude only should error out' '
|
test_expect_success 'exclude only no longer errors out' '
|
||||||
test_must_fail git log --oneline --format=%s -- ":(exclude)sub"
|
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' '
|
test_expect_success 't_e_i() exclude sub' '
|
||||||
|
Loading…
Reference in New Issue
Block a user