diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index 822ca832640fe0142e364e99468715d45d2e1fc5..fc9320e59ecac99fc4d3f6234c74f89aab4dd45b 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -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:: diff --git a/pathspec.c b/pathspec.c index ecad03406397338961fa0cb065b7ca18889d86ef..b961f00c8cd0eb68c56b33aa829579e8609edba6 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) diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh index d51595cf6b189a59d271dcc69c3f245b72dcb8f6..9dd5cde5fc53deb365234e815d7142de9a975005 100755 --- a/t/t6132-pathspec-exclude.sh +++ b/t/t6132-pathspec-exclude.sh @@ -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' '