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

[PATCH] unpack-trees: do not delete i-t-a entries in worktree even when forced

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 24, 2016, 11:45 UTC
Message-ID
<1456314317-30301-1-git-send-email-pclouds@gmail.com>

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: Junio C Hamano
Message 1 of 4 in “unpack-trees: do not delete i-t-a entries in worktree even when forced”
  1. unpack-trees: do not delete i-t-a entries in worktree even when forcedNguyễn Thái Ngọc Duy, Feb 24, 2016
  2. Junio C HamanoFeb 24, 2016
  3. Junio C HamanoFeb 24, 2016
  4. Duy NguyenFeb 25, 2016

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.