summaryrefslogtreecommitdiff
path: root/t/t2022-checkout-paths.sh
diff options
context:
space:
mode:
authorVarun Naik <vcnaik94@gmail.com>2019-08-02 16:28:52 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-08-02 17:28:10 (GMT)
commitecd72042de7d79c05d8f153e288766c7f88f0b10 (patch)
tree3236d9ee05eb72644b922cce1a9e50f58cc15f69 /t/t2022-checkout-paths.sh
parent51cf315870bbb7254ddf06c84fe03b41bc48eebd (diff)
downloadgit-ecd72042de7d79c05d8f153e288766c7f88f0b10.zip
git-ecd72042de7d79c05d8f153e288766c7f88f0b10.tar.gz
git-ecd72042de7d79c05d8f153e288766c7f88f0b10.tar.bz2
checkout.c: unstage empty deleted ita files
It is possible to delete a committed file from the index and then add it as intent-to-add. After `git checkout HEAD <pathspec>`, the file should be identical in the index and HEAD. The command already works correctly if the file has contents in HEAD. This patch provides the desired behavior even when the file is empty in HEAD. `git checkout HEAD <pathspec>` calls tree.c:read_tree_1(), with fn pointing to checkout.c:update_some(). update_some() creates a new cache entry but discards it when its mode and oid match those of the old entry. A cache entry for an ita file and a cache entry for an empty file have the same oid. Therefore, an empty deleted ita file previously passed both of these checks, and the new entry was discarded, so the file remained unchanged in the index. After this fix, if the file is marked as ita in the cache, then we avoid discarding the new entry and add the new entry 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 is never called. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Varun Naik <vcnaik94@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2022-checkout-paths.sh')
-rwxr-xr-xt/t2022-checkout-paths.sh11
1 files changed, 11 insertions, 0 deletions
diff --git a/t/t2022-checkout-paths.sh b/t/t2022-checkout-paths.sh
index fc3eb43..6844afa 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 --cached --exit-code
+'
+
test_done