Merge branch 'js/empty-index-fixes' into next

A few places failed to differenciate the case where the index is
truly empty (nothing added) and we haven't yet read from the
on-disk index file, which have been corrected.

* js/empty-index-fixes:
  commit -a -m: allow the top-level tree to become empty again
  split-index: accept that a base index can be empty
  do_read_index(): always mark index as initialized unless erroring out
This commit is contained in:
Junio C Hamano
2023-06-29 16:45:32 -07:00
3 changed files with 22 additions and 11 deletions

View File

@ -1002,11 +1002,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
struct object_id oid;
const char *parent = "HEAD";
if (!the_index.cache_nr) {
discard_index(&the_index);
if (repo_read_index(the_repository) < 0)
die(_("Cannot read index"));
}
if (!the_index.initialized && repo_read_index(the_repository) < 0)
die(_("Cannot read index"));
if (amend)
parent = "HEAD^1";