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,
	Christoph Reiter <reiter.christoph@gmail.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH] add --interactive: allow `update` to stage deleted files
Date: Tue, 28 Jun 2022 15:35:20 -0700	[thread overview]
Message-ID: <xmqqr138h0wn.fsf@gitster.g> (raw)
In-Reply-To: <pull.1273.git.1656454964378.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Tue, 28 Jun 2022 22:22:44 +0000")

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> diff --git a/add-interactive.c b/add-interactive.c
> index 6047e8f6489..22fcd3412ca 100644
> --- a/add-interactive.c
> +++ b/add-interactive.c
> @@ -697,8 +697,16 @@ static int run_update(struct add_i_state *s, const struct pathspec *ps,
>  
>  	for (i = 0; i < files->items.nr; i++) {
>  		const char *name = files->items.items[i].string;
> -		if (files->selected[i] &&
> -		    add_file_to_index(s->r->index, name, 0) < 0) {
> +		struct stat st;
> +
> +		if (!files->selected[i])
> +			continue;
> +		if (lstat(name, &st) && is_missing_file_error(errno)) {
> +			if (remove_file_from_index(s->r->index, name) < 0) {
> +				res = error(_("could not stage '%s'"), name);
> +				break;
> +			}
> +		} else if (add_file_to_index(s->r->index, name, 0) < 0) {
>  			res = error(_("could not stage '%s'"), name);
>  			break;
>  		}

The fix looks quite straight-forward.  It is somewhat disappointing
that it was caught after this loooong time, but as they say, better
late than never.

Thanks for a quick report and a fix.

> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index fc26cb8bae8..b354fb39de8 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -103,6 +103,15 @@ test_expect_success 'status works (commit)' '
>  	grep "+1/-0 *+2/-0 file" output
>  '
>  
> +test_expect_success 'update can stage deletions' '
> +	>to-delete &&
> +	git add to-delete &&
> +	rm to-delete &&
> +	test_write_lines u t "" | git add -i &&
> +	git ls-files to-delete >output &&
> +	test_must_be_empty output
> +'
> +
>  test_expect_success 'setup expected' '
>  	cat >expected <<-\EOF
>  	index 180b47c..b6f2c08 100644
>
> base-commit: e4a4b31577c7419497ac30cebe30d755b97752c5

  reply	other threads:[~2022-06-28 22:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28 22:22 [PATCH] add --interactive: allow `update` to stage deleted files Johannes Schindelin via GitGitGadget
2022-06-28 22:35 ` Junio C Hamano [this message]
2022-06-28 23:08   ` Taylor Blau
2022-06-29 10:22     ` Ævar Arnfjörð Bjarmason

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=xmqqr138h0wn.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=reiter.christoph@gmail.com \
    /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.