about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-08-22 12:34:11 -0700
committerJunio C Hamano <gitster@pobox.com>2019-08-22 12:34:11 -0700
commit072735ea58407db41c0874fd2f8a91d0c191d49b (patch)
tree1179894f8b5414c88bf7874a4510a702b36e8b2d
parent207ad3cb203b7adeeb52b5372ace497e20739d49 (diff)
parent620c09e1b686e06c4ddbd5fb153f7ad898bab412 (diff)
downloadgit-svn-072735ea58407db41c0874fd2f8a91d0c191d49b.tar.gz
"git checkout" and "git restore" to re-populate the index from a
tree-ish (typically HEAD) did not work correctly for a path that
was removed and then added again with the intent-to-add bit, when
the corresponding working tree file was empty.  This has been
corrected.

* vn/restore-empty-ita-corner-case-fix:
  restore: add test for deleted ita files
  checkout.c: unstage empty deleted ita files
-rw-r--r--builtin/checkout.c1
-rwxr-xr-xt/t2022-checkout-paths.sh11
-rwxr-xr-xt/t2070-restore.sh11
3 files changed, 23 insertions, 0 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 6123f732a2..8d3ad7cd9e 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..6844afafc0 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
diff --git a/t/t2070-restore.sh b/t/t2070-restore.sh
index 2650df1966..21c3f84459 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 --cached --exit-code
+'
+
 test_done