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
This commit is contained in:
Junio C Hamano 2019-08-22 12:34:11 -07:00
commit 072735ea58
3 changed files with 23 additions and 0 deletions

View file

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

View file

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

View file

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