diff --git a/cache.h b/cache.h index bcf0fc55fd..add5f9f50a 100644 --- a/cache.h +++ b/cache.h @@ -340,7 +340,8 @@ struct index_state { struct split_index *split_index; struct cache_time timestamp; unsigned name_hash_initialized : 1, - initialized : 1; + initialized : 1, + drop_cache_tree : 1; struct hashmap name_hash; struct hashmap dir_hash; unsigned char sha1[20]; diff --git a/read-cache.c b/read-cache.c index 1248a09de4..5cd14e2f72 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2199,7 +2199,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, struct stat st; struct ondisk_cache_entry_extended ondisk; struct strbuf previous_name_buf = STRBUF_INIT, *previous_name; - int drop_cache_tree = 0; + int drop_cache_tree = istate->drop_cache_tree; for (i = removed = extended = 0; i < entries; i++) { if (cache[i]->ce_flags & CE_REMOVE) diff --git a/split-index.c b/split-index.c index 83e39ec8d7..284d04d67f 100644 --- a/split-index.c +++ b/split-index.c @@ -238,6 +238,8 @@ void prepare_to_write_split_index(struct index_state *istate) ALLOC_GROW(entries, nr_entries+1, nr_alloc); entries[nr_entries++] = ce; } + if (is_null_oid(&ce->oid)) + istate->drop_cache_tree = 1; } } diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh index 22f69a410b..322721dd64 100755 --- a/t/t1700-split-index.sh +++ b/t/t1700-split-index.sh @@ -400,4 +400,23 @@ done <<\EOF 0642 -rw-r---w- EOF +test_expect_success 'writing split index with null sha1 does not write cache tree' ' + git config core.splitIndex true && + git config splitIndex.maxPercentChange 0 && + git commit -m "commit" && + { + git ls-tree HEAD && + printf "160000 commit $_z40\\tbroken\\n" + } >broken-tree && + echo "add broken entry" >msg && + + tree=$(git mktree cache-tree.out || true) && + test_line_count = 0 cache-tree.out +' + test_done