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

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 17, 2020, 10:03 UTC
Message-ID
<nycvar.QRO.7.76.6.2001171101150.46@tvgsbejvaqbjf.bet>
In-Reply-To
<xmqqzhenf3t0.fsf@gitster-ct.c.googlers.com>
Hi Junio,
On Thu, 16 Jan 2020, Junio C Hamano wrote:
Show 23 quoted lines
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > 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(-)
>
> Makes sense.  No tests?
Do we really need tests here? ;-)

Honestly, I would deem the likelihood of this to get broken again very low, and the effort for writing a regression test relatively high...

If you insist, I will add some, of course, but not today.

Ciao, Dscho

Show 25 quoted lines
>
> >
> > 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",
>
Previous: Junio C HamanoNext: Johannes Schindelin via GitGitGadget
Message 4 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.