diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-02-27 13:57:13 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-02-27 13:57:13 -0800 |
commit | 015fba38345c685275864e5b216c74e8ba0633bb (patch) | |
tree | 353f4ca0bb1b0d5e3bb504c9fe4d227a2fd3ad93 /pathspec.c | |
parent | fb75e317614c1d6aec2ef5b65775a603db8f68da (diff) | |
parent | 859b7f1d0e742493d2a9396794cd9040213ad846 (diff) | |
download | git-015fba38345c685275864e5b216c74e8ba0633bb.tar.gz |
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 '!'
Diffstat (limited to 'pathspec.c')
-rw-r--r-- | pathspec.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/pathspec.c b/pathspec.c index 7ababb3159..b961f00c8c 100644 --- a/pathspec.c +++ b/pathspec.c @@ -224,6 +224,12 @@ static const char *parse_short_magic(unsigned *magic, const char *elem) char ch = *pos; int i; + /* Special case alias for '!' */ + if (ch == '^') { + *magic |= PATHSPEC_EXCLUDE; + continue; + } + if (!is_pathspec_magic(ch)) break; @@ -516,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; @@ -540,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) |