From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] unpack-trees: do not delete i-t-a entries in worktree even when forced
Date: Wed, 24 Feb 2016 18:45:17 +0700 [thread overview]
Message-ID: <1456314317-30301-1-git-send-email-pclouds@gmail.com> (raw)
Intent-to-add entries are basically "I may want to commit these files
later, but for now they are untracked". As such, when the user does "git
reset --hard <tree>", which removes i-t-a entries from the index, i-t-a
entries in worktree should be kept as untracked.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Lost two files today, luckily I had a backup.
t/t2203-add-intent.sh | 15 +++++++++++++++
unpack-trees.c | 2 +-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh
index 2a4a749..63086bf 100755
--- a/t/t2203-add-intent.sh
+++ b/t/t2203-add-intent.sh
@@ -82,5 +82,20 @@ test_expect_success 'cache-tree invalidates i-t-a paths' '
test_cmp expect actual
'
+test_expect_success 'reset --hard leaves on-disk ita entries alone' '
+ git init keep-ita &&
+ (
+ cd keep-ita &&
+ echo abc >abc &&
+ echo def >def &&
+ git add abc &&
+ git commit -m abc &&
+ git add -N def &&
+ git reset --hard HEAD &&
+ echo def >expected &&
+ test_cmp expected def
+ )
+'
+
test_done
diff --git a/unpack-trees.c b/unpack-trees.c
index 9f55cc2..1a2271b 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -104,7 +104,7 @@ static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
{
clear |= CE_HASHED;
- if (set & CE_REMOVE)
+ if ((set & CE_REMOVE) && !ce_intent_to_add(ce))
set |= CE_WT_REMOVE;
ce->ce_flags = (ce->ce_flags & ~clear) | set;
--
2.7.2.531.gc9e018c
next reply other threads:[~2016-02-24 11:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 11:45 Nguyễn Thái Ngọc Duy [this message]
2016-02-24 22:57 ` [PATCH] unpack-trees: do not delete i-t-a entries in worktree even when forced Junio C Hamano
2016-02-24 23:23 ` Junio C Hamano
2016-02-25 10:45 ` Duy Nguyen
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=1456314317-30301-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 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 NNTP newsgroup(s).