]> git.ipfire.org Git - thirdparty/git.git/commitdiff
built-in add -i: do not try to `patch`/`diff` an empty list of files
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 16 Jan 2020 08:33:06 +0000 (08:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Jan 2020 22:10:21 +0000 (14:10 -0800)
When the user does not select any files to `patch` or `diff`, there is
no need to call `run_add_p()` on them.

Even worse: we _have_ to avoid calling `parse_pathspec()` with an empty
list because that would trigger this error:

BUG: pathspec.c:557: PATHSPEC_PREFER_CWD requires arguments

So let's avoid doing any work on a list of files that is empty anyway.

This fixes https://github.com/git-for-windows/git/issues/2466.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-interactive.c

index f395d54c08df577e557ef1590780c7e1f7c92296..14d4688c26804624eb1ad77689d0d28742088821 100644 (file)
@@ -915,7 +915,7 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
 
        opts->prompt = N_("Patch update");
        count = list_and_choose(s, files, opts);
-       if (count >= 0) {
+       if (count > 0) {
                struct argv_array args = ARGV_ARRAY_INIT;
 
                argv_array_pushl(&args, "git", "add--interactive", "--patch",
@@ -953,7 +953,7 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
        opts->flags = IMMEDIATE;
        count = list_and_choose(s, files, opts);
        opts->flags = 0;
-       if (count >= 0) {
+       if (count > 0) {
                struct argv_array args = ARGV_ARRAY_INIT;
 
                argv_array_pushl(&args, "git", "diff", "-p", "--cached",