Merge branch 'nd/switch-and-restore'

"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
This commit is contained in:
Junio C Hamano 2020-01-22 15:07:32 -08:00
commit 09e393d913
2 changed files with 19 additions and 0 deletions

View File

@ -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.

View File

@ -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