All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 2/2] built-in add -i: accept open-ended ranges again
Date: Thu, 16 Jan 2020 14:16:57 -0800	[thread overview]
Message-ID: <xmqqv9pbf3mu.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <7e4bf4bbbcd8c81a19d690aee379042e47246947.1579163587.git.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Thu, 16 Jan 2020 08:33:07 +0000")

"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.

> 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 &&

  reply	other threads:[~2020-01-16 22:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16  8:33 [PATCH 0/2] Two fixes for the built-in git add -i Johannes Schindelin via GitGitGadget
2020-01-16  8:33 ` [PATCH 1/2] built-in add -i: do not try to `patch`/`diff` an empty list of files Johannes Schindelin via GitGitGadget
2020-01-16 22:13   ` Junio C Hamano
2020-01-17 10:03     ` Johannes Schindelin
2020-01-16  8:33 ` [PATCH 2/2] built-in add -i: accept open-ended ranges again Johannes Schindelin via GitGitGadget
2020-01-16 22:16   ` Junio C Hamano [this message]
2020-01-17 10:01     ` Johannes Schindelin
2020-01-17 17:35       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqv9pbf3mu.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.