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

Re: [PATCH 2/2] built-in add -i: accept open-ended ranges again

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 17, 2020, 10:01 UTC
Message-ID
<nycvar.QRO.7.76.6.2001171100030.46@tvgsbejvaqbjf.bet>
In-Reply-To
<xmqqv9pbf3mu.fsf@gitster-ct.c.googlers.com>
Hi Junio,
On Thu, 16 Jan 2020, Junio C Hamano wrote:
Show 38 quoted lines
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> >
> > The interactive `add` command allows selecting multiple files for some
> > of its sub-commands, via unique prefixes, indices or index ranges.
> >
> > When re-implementing `git add -i` in C, we even added a code comment
> > talking about ranges with a missing end index, such as `2-`, but the
> > code did not actually accept those, as pointed out in
> > https://github.com/git-for-windows/git/issues/2466#issuecomment-574142760.
> >
> > Let's fix this, and add a test case to verify that this stays fixed
> > forever.
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> >  add-interactive.c          | 5 ++++-
> >  t/t3701-add-interactive.sh | 9 +++++++++
> >  2 files changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/add-interactive.c b/add-interactive.c
> > index 14d4688c26..396066e724 100644
> > --- a/add-interactive.c
> > +++ b/add-interactive.c
> > @@ -328,7 +328,10 @@ static ssize_t list_and_choose(struct add_i_state *s,
> >  				if (endp == p + sep)
> >  					to = from + 1;
> >  				else if (*endp == '-') {
> > -					to = strtoul(++endp, &endp, 10);
> > +					if (isdigit(*(++endp)))
> > +						to = strtoul(endp, &endp, 10);
> > +					else
> > +						to = items->items.nr;
>
> Good.  We do not allow "everything up to N" with "-N", so covering
> "N and everything after" with "N-" is sufficient.

Even worse, `-N` means "toggle N off". But that can't be fixed easily as it has been part of the UI for ages.

Thanks, Dscho

Show 22 quoted lines
>
> > diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> > index d4f9386621..b02fe73631 100755
> > --- a/t/t3701-add-interactive.sh
> > +++ b/t/t3701-add-interactive.sh
> > @@ -57,6 +57,15 @@ test_expect_success 'revert works (initial)' '
> >  	! grep . output
> >  '
> >
> > +test_expect_success 'add untracked (multiple)' '
> > +	test_when_finished "git reset && rm [1-9]" &&
> > +	touch $(test_seq 9) &&
> > +	test_write_lines a "2-5 8-" | git add -i -- [1-9] &&
> > +	test_write_lines 2 3 4 5 8 9 >expected &&
> > +	git ls-files [1-9] >output &&
> > +	test_cmp expected output
> > +'
> > +
> >  test_expect_success 'setup (commit)' '
> >  	echo baseline >file &&
> >  	git add file &&
>
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 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.