git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Varun Naik <vcnaik94@gmail.com>
To: Varun Naik <vcnaik94@gmail.com>
Cc: git@vger.kernel.org, peff@peff.net
Subject: Re: [PATCH] checkout.c: unstage empty deleted ita files
Date: Thu, 25 Jul 2019 22:01:13 -0700	[thread overview]
Message-ID: <CAK_rgsG2ghwqDfRzyAy9MvFujsR=-Hy7YRiAv=RH1DpoZ-06hA@mail.gmail.com> (raw)
In-Reply-To: <20190726045645.2437-1-vcnaik94@gmail.com>

Got the CC list wrong in the first email...

Varun


On Thu, Jul 25, 2019 at 9:57 PM Varun Naik <vcnaik94@gmail.com> wrote:
>
> It is possible to delete a committed file from the index and then add it
> as intent-to-add. After `git checkout HEAD` or `git restore --staged`,
> the file should be identical in the index and HEAD. This patch provides
> the desired behavior even when the file is empty in the index.
>
> Signed-off-by: Varun Naik <vcnaik94@gmail.com>
> ---
> CC Jeff because you wrote the code that I am changing now.
>
> checkout.c:update_some() discards the newly created cache entry when its
> mode and oid match those of the old entry. Since an ita file has the
> same oid as an empty file, an empty deleted ita file passes both of
> these checks, and the new entry is discarded. In this case, the file
> should be added to the cache instead.
>
> This change should not affect newly added ita files. For those, inside
> tree.c:read_tree_1(), tree_entry_interesting() returns
> entry_not_interesting, so fn (which points to update_some()) is never
> called.
>
> To the best of my understanding, the only other command that makes
> changes to the index differently for nonempty vs empty deleted ita files
> is "reset", which I am fixing in [0]. I am separating the two changes
> because this change affects "restore", which has not reached maint yet.
>
> [0]: https://public-inbox.org/git/20190726044806.2216-1-vcnaik94@gmail.com/
>
>  builtin/checkout.c        |  1 +
>  t/t2022-checkout-paths.sh | 11 +++++++++++
>  t/t2070-restore.sh        | 11 +++++++++++
>  3 files changed, 23 insertions(+)
>
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 91f8509f85..27daa09c3c 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -126,6 +126,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
>         if (pos >= 0) {
>                 struct cache_entry *old = active_cache[pos];
>                 if (ce->ce_mode == old->ce_mode &&
> +                   !ce_intent_to_add(old) &&
>                     oideq(&ce->oid, &old->oid)) {
>                         old->ce_flags |= CE_UPDATE;
>                         discard_cache_entry(ce);
> diff --git a/t/t2022-checkout-paths.sh b/t/t2022-checkout-paths.sh
> index fc3eb43b89..74add853fd 100755
> --- a/t/t2022-checkout-paths.sh
> +++ b/t/t2022-checkout-paths.sh
> @@ -78,4 +78,15 @@ test_expect_success 'do not touch files that are already up-to-date' '
>         test_cmp expect actual
>  '
>
> +test_expect_success 'checkout HEAD adds deleted intent-to-add file back to index' '
> +       echo "nonempty" >nonempty &&
> +       >empty &&
> +       git add nonempty empty &&
> +       git commit -m "create files to be deleted" &&
> +       git rm --cached nonempty empty &&
> +       git add -N nonempty empty &&
> +       git checkout HEAD nonempty empty &&
> +       git diff --staged --exit-code
> +'
> +
>  test_done
> diff --git a/t/t2070-restore.sh b/t/t2070-restore.sh
> index 2650df1966..09b1543a5b 100755
> --- a/t/t2070-restore.sh
> +++ b/t/t2070-restore.sh
> @@ -95,4 +95,15 @@ test_expect_success 'restore --ignore-unmerged ignores unmerged entries' '
>         )
>  '
>
> +test_expect_success 'restore --staged adds deleted intent-to-add file back to index' '
> +       echo "nonempty" >nonempty &&
> +       >empty &&
> +       git add nonempty empty &&
> +       git commit -m "create files to be deleted" &&
> +       git rm --cached nonempty empty &&
> +       git add -N nonempty empty &&
> +       git restore --staged nonempty empty &&
> +       git diff --staged --exit-code
> +'
> +
>  test_done
> --
> 2.22.0
>

  reply	other threads:[~2019-07-26  5:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-26  4:56 [PATCH] checkout.c: unstage empty deleted ita files Varun Naik
2019-07-26  5:01 ` Varun Naik [this message]
2019-07-26  8:57 ` Jeff King
2019-07-29  6:54   ` Varun Naik
2019-07-29  9:11     ` Jeff King
2019-08-01 16:07 ` [PATCH v2] " Varun Naik
2019-08-01 17:34   ` Junio C Hamano
2019-08-01 21:51   ` Jeff King
2019-08-01 16:09 ` [PATCH] restore: add test for " Varun Naik
2019-08-02 16:16   ` Junio C Hamano
2019-08-02 16:28 ` [PATCH v3] checkout.c: unstage empty " Varun Naik

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to='CAK_rgsG2ghwqDfRzyAy9MvFujsR=-Hy7YRiAv=RH1DpoZ-06hA@mail.gmail.com' \
    --to=vcnaik94@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).