summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2020-02-14 12:42:29 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-02-14 12:42:29 -0800
commite361f36f61b664a36db1d34c3f9e3427ac42656d (patch)
tree3a34e8dbb31faa251fd7865a8b0aebef76dd3ff7
parentMerge branch 'jk/no-flush-upon-disconnecting-slrpc-transport' into maint (diff)
parentrestore: invalidate cache-tree when removing entries with --staged (diff)
downloadtgif-e361f36f61b664a36db1d34c3f9e3427ac42656d.tar.xz
Merge branch 'nd/switch-and-restore' into maint
"git restore --staged" did not correctly update the cache-tree structure, resulting in bogus trees to be written afterwards, which has been corrected. * nd/switch-and-restore: restore: invalidate cache-tree when removing entries with --staged
-rw-r--r--builtin/checkout.c2
-rwxr-xr-xt/t2070-restore.sh17
2 files changed, 19 insertions, 0 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index b52c490c8f..18ef5fb975 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -524,6 +524,8 @@ static int checkout_paths(const struct checkout_opts *opts,
/* Now we are committed to check them out */
if (opts->checkout_worktree)
errs |= checkout_worktree(opts);
+ else
+ remove_marked_cache_entries(&the_index, 1);
/*
* Allow updating the index when checking out from the index.
diff --git a/t/t2070-restore.sh b/t/t2070-restore.sh
index 21c3f84459..076d0df7fc 100755
--- a/t/t2070-restore.sh
+++ b/t/t2070-restore.sh
@@ -106,4 +106,21 @@ test_expect_success 'restore --staged adds deleted intent-to-add file back to in
git diff --cached --exit-code
'
+test_expect_success 'restore --staged invalidates cache tree for deletions' '
+ test_when_finished git reset --hard &&
+ >new1 &&
+ >new2 &&
+ git add new1 new2 &&
+
+ # It is important to commit and then reset here, so that the index
+ # contains a valid cache-tree for the "both" tree.
+ git commit -m both &&
+ git reset --soft HEAD^ &&
+
+ git restore --staged new1 &&
+ git commit -m "just new2" &&
+ git rev-parse HEAD:new2 &&
+ test_must_fail git rev-parse HEAD:new1
+'
+
test_done