aboutsummaryrefslogtreecommitdiff
path: root/pathspec.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-04-04 11:16:56 +0200
committerJunio C Hamano <gitster@pobox.com>2017-04-14 23:55:24 -0700
commitbe4dbbbed931a1683e351b872865ed8d90e9ac2b (patch)
tree4f6e7fb77efb74684af8d8dc0b71558a81f60a82 /pathspec.c
parent153e0d762c15d8a85f0070cd01aff45f5c232e3f (diff)
downloadgit-be4dbbbed931a1683e351b872865ed8d90e9ac2b.tar.gz
git-be4dbbbed931a1683e351b872865ed8d90e9ac2b.tar.xz
pathspec: honor `PATHSPEC_PREFIX_ORIGIN` with empty prefix
Previous to commit 5d8f084a5 (pathspec: simpler logic to prefix original pathspec elements, 2017-01-04), we were always using the computed `match` variable to perform pathspec matching whenever `PATHSPEC_PREFIX_ORIGIN` is set. This is for example useful when passing the parsed pathspecs to other commands, as the computed `match` may contain a pathspec relative to the repository root. The commit changed this logic to only do so when we do have an actual prefix and when literal pathspecs are deactivated. But this change may actually break some commands which expect passed pathspecs to be relative to the repository root. One such case is `git add --patch`, which now fails when using relative paths from a subdirectory. For example if executing "git add -p ../foo.c" in a subdirectory, the `git-add--interactive` command will directly pass "../foo.c" to `git-ls-files`. As ls-files is executed at the repository's root, the command will notice that "../foo.c" is outside the repository and fail. Fix the issue by again using the computed `match` variable when `PATHSPEC_PREFIX_ORIGIN` is set and global literal pathspecs are deactivated. Note that in contrast to previous behavior, we will now always call `prefix_magic` regardless of whether a prefix is actually set. But this is the right thing to do: when the `match` variable has been resolved to the repository's root, it will be set to an empty string. When passing the empty string directly to other commands, it will result in a warning regarding deprecated empty pathspecs. By always adding the prefix magic, we will end up with at least the string ":(prefix:0)" and thus avoid the warning. Signed-off-by: Patrick Steinhardt <ps@pks.im> Acked-by: Brandon Williams <bmwill@google.com> Reviewed-by: Duy Nguyen <pclouds@gmail.com>
Diffstat (limited to 'pathspec.c')
-rw-r--r--pathspec.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/pathspec.c b/pathspec.c
index 303efda83..3079a817a 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -505,7 +505,7 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
* original. Useful for passing to another command.
*/
if ((flags & PATHSPEC_PREFIX_ORIGIN) &&
- prefixlen && !get_literal_global()) {
+ !get_literal_global()) {
struct strbuf sb = STRBUF_INIT;
/* Preserve the actual prefix length of each pattern */