Skip to content

Commit 072735e

Browse files
committed
Merge branch 'vn/restore-empty-ita-corner-case-fix'
"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
2 parents 207ad3c + 620c09e commit 072735e

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

builtin/checkout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
126126
if (pos >= 0) {
127127
struct cache_entry *old = active_cache[pos];
128128
if (ce->ce_mode == old->ce_mode &&
129+
!ce_intent_to_add(old) &&
129130
oideq(&ce->oid, &old->oid)) {
130131
old->ce_flags |= CE_UPDATE;
131132
discard_cache_entry(ce);

t/t2022-checkout-paths.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,15 @@ test_expect_success 'do not touch files that are already up-to-date' '
7878
test_cmp expect actual
7979
'
8080

81+
test_expect_success 'checkout HEAD adds deleted intent-to-add file back to index' '
82+
echo "nonempty" >nonempty &&
83+
>empty &&
84+
git add nonempty empty &&
85+
git commit -m "create files to be deleted" &&
86+
git rm --cached nonempty empty &&
87+
git add -N nonempty empty &&
88+
git checkout HEAD nonempty empty &&
89+
git diff --cached --exit-code
90+
'
91+
8192
test_done

t/t2070-restore.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,15 @@ test_expect_success 'restore --ignore-unmerged ignores unmerged entries' '
9595
)
9696
'
9797

98+
test_expect_success 'restore --staged adds deleted intent-to-add file back to index' '
99+
echo "nonempty" >nonempty &&
100+
>empty &&
101+
git add nonempty empty &&
102+
git commit -m "create files to be deleted" &&
103+
git rm --cached nonempty empty &&
104+
git add -N nonempty empty &&
105+
git restore --staged nonempty empty &&
106+
git diff --cached --exit-code
107+
'
108+
98109
test_done

0 commit comments

Comments
 (0)