Skip to content

Commit 09e393d

Browse files
committed
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
2 parents 45f47ff + e701bab commit 09e393d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

builtin/checkout.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ static int checkout_paths(const struct checkout_opts *opts,
524524
/* Now we are committed to check them out */
525525
if (opts->checkout_worktree)
526526
errs |= checkout_worktree(opts);
527+
else
528+
remove_marked_cache_entries(&the_index, 1);
527529

528530
/*
529531
* Allow updating the index when checking out from the index.

t/t2070-restore.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,21 @@ test_expect_success 'restore --staged adds deleted intent-to-add file back to in
106106
git diff --cached --exit-code
107107
'
108108

109+
test_expect_success 'restore --staged invalidates cache tree for deletions' '
110+
test_when_finished git reset --hard &&
111+
>new1 &&
112+
>new2 &&
113+
git add new1 new2 &&
114+
115+
# It is important to commit and then reset here, so that the index
116+
# contains a valid cache-tree for the "both" tree.
117+
git commit -m both &&
118+
git reset --soft HEAD^ &&
119+
120+
git restore --staged new1 &&
121+
git commit -m "just new2" &&
122+
git rev-parse HEAD:new2 &&
123+
test_must_fail git rev-parse HEAD:new1
124+
'
125+
109126
test_done

0 commit comments

Comments
 (0)