git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] built-in add -i: do not try to `patch`/`diff` an empty list of files

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 16, 2020, 08:33 UTC
Message-ID
<353c748838d341bb325149234657c27215a9fab3.1579163587.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.528.git.1579163587.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

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>
---
 add-interactive.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/add-interactive.c b/add-interactive.c
index f395d54c08..14d4688c26 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -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",
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Junio C Hamano
Message 2 of 8 in “Two fixes for the built-in git add -i”
  1. 0/2 Two fixes for the built-in git add -iJohannes Schindelin via GitGitGadget, Jan 16, 2020
  2. 1/2 built-in add -i: do not try to `patch`/`diff` an empty list of filesJohannes Schindelin via GitGitGadget, Jan 16, 2020
  3. Junio C HamanoJan 16, 2020
  4. Johannes SchindelinJan 17, 2020
  5. 2/2 built-in add -i: accept open-ended ranges againJohannes Schindelin via GitGitGadget, Jan 16, 2020
  6. Junio C HamanoJan 16, 2020
  7. Johannes SchindelinJan 17, 2020
  8. Junio C HamanoJan 17, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.