Message ID | 353c748838d341bb325149234657c27215a9fab3.1579163587.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Two fixes for the built-in git add -i | expand |
"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? > > 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",
Hi Junio, On Thu, 16 Jan 2020, Junio C Hamano wrote: > "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 > > > > > 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", >
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",