From: Junio C Hamano <gitster@pobox.com>
To: Robert Dailey <rcdailey.lists@gmail.com>
Cc: Git <git@vger.kernel.org>
Subject: Re: Excluding paths with wildcard not working with add -p
Date: Sun, 29 May 2022 11:42:53 -0700 [thread overview]
Message-ID: <xmqq8rqkyyc2.fsf@gitster.g> (raw)
In-Reply-To: <xmqqh758yz4u.fsf@gitster.g> (Junio C. Hamano's message of "Sun, 29 May 2022 11:25:37 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> Does this command
>
> git add -p -- . ':^*.cs'
>
> work as you expect?
We used to error out when you give a pathspec with only negative
elements in it, like the one you gave above. Later, we tweaked this
logic at 859b7f1d (pathspec: don't error out on all-exclusionary
pathspec patterns, 2017-02-07) so that we add an empty string as an
extra element when your pathspec has only negative elements.
At around the same time, we were migrating from "an empty string is
a valid pathspec element that matches everything" to "either a dot
or ":/" is used for that purpose, and an empty string is rejected",
between d426430e (pathspec: warn on empty strings as pathspec,
2016-06-22) and 9e4e8a64 (pathspec: die on empty strings as
pathspec, 2017-06-06). I think 9e4e8a64 was not careful enough to
turn the empty string 859b7f1d added to either a dot or ":/"
For the purpose of "add -p", I _think_ adding a "dot" is correct,
but depending on the command, the code needs to add ":/".
Here is a quick trial patch, which seems to compile and pass all the
tests we have, but the fact that this lingered with us for the past
5 years is a strong sign that we lack coverage in this area, so it
may be breaking something else in a big way.
pathspec.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git c/pathspec.c w/pathspec.c
index ddeeba7911..1b0ae51aa4 100644
--- c/pathspec.c
+++ w/pathspec.c
@@ -628,8 +628,10 @@ void parse_pathspec(struct pathspec *pathspec,
* that matches everything. 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, "");
+ if (!(flags & PATHSPEC_PREFER_CWD))
+ init_pathspec_item(item + n, 0, NULL, 0, ":/");
+ else
+ init_pathspec_item(item + n, 0, prefix, prefixlen, ".");
pathspec->nr++;
}
next prev parent reply other threads:[~2022-05-29 18:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-29 17:27 Excluding paths with wildcard not working with add -p Robert Dailey
2022-05-29 18:25 ` Junio C Hamano
2022-05-29 18:42 ` Junio C Hamano [this message]
2022-05-29 22:39 ` [PATCH] pathspec: correct an empty string used as a pathspec element Junio C Hamano
2022-05-29 23:01 ` rsbecker
2022-05-29 21:15 ` Excluding paths with wildcard not working with add -p Robert Dailey
2022-05-30 17:20 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq8rqkyyc2.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=rcdailey.lists@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.