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

[PATCH v2] reset: unstage empty deleted ita files

From
Varun Naik <vcnaik94@gmail.com>
Date
Jul 26, 2019, 04:48 UTC
Message-ID
<20190726044806.2216-1-vcnaik94@gmail.com>
In-Reply-To
<20190712150235.12633-1-vcnaik94@gmail.com>

It is possible to delete a committed file from the index and then add it as intent-to-add. After `git reset HEAD`, 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 Duy because you seem to be the one who is most involved in changes to
ita behavior.

The test description was incorrect, so I changed that now. I also figured out how to fix the related problem in "restore"; separate patch coming soon.

 builtin/reset.c  |  1 +
 t/t7102-reset.sh | 11 +++++++++++
 2 files changed, 12 insertions(+)
diff --git a/builtin/reset.c b/builtin/reset.c
index 26ef9a7bd0..47a088f4b7 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -163,6 +163,7 @@ static int read_from_tree(const struct pathspec *pathspec,
 	opt.format_callback_data = &intent_to_add;
 	opt.flags.override_submodule_config = 1;
 	opt.repo = the_repository;
+	opt.ita_invisible_in_index = 1;
 
 	if (do_diff_cache(tree_oid, &opt))
 		return 1;
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 97be0d968d..9f3854e8f0 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -566,4 +566,15 @@ test_expect_success 'reset --mixed sets up work tree' '
 	test_must_be_empty actual
 '
 
+test_expect_success 'reset --mixed 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 reset HEAD nonempty empty &&
+	git diff --staged --exit-code
+'
+
 test_done
-- 
2.22.0
Previous: Varun NaikNext: Junio C Hamano
Message 2 of 11 in “reset: unstage empty deleted ita files”
  1. reset: unstage empty deleted ita filesVarun Naik, Jul 12, 2019
  2. reset: unstage empty deleted ita filesVarun Naik, Jul 26, 2019
  3. Junio C HamanoJul 26, 2019
  4. Varun NaikJul 29, 2019
  5. Junio C HamanoJul 29, 2019
  6. diff-lib.c: handle empty deleted ita filesVarun Naik, Aug 1, 2019
  7. Varun NaikAug 15, 2019
  8. Junio C HamanoAug 15, 2019
  9. Varun NaikAug 19, 2019
  10. Junio C HamanoAug 19, 2019
  11. Varun NaikFeb 14, 2020

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.