diff --git a/builtin/stash.c b/builtin/stash.c index ab703f96ad5d3c..114fa0c38701dc 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -399,7 +399,7 @@ static int restore_untracked(struct object_id *u_tree) child_process_init(&cp); cp.git_cmd = 1; - strvec_pushl(&cp.args, "checkout-index", "--all", NULL); + strvec_pushl(&cp.args, "checkout-index", "--all", "-f", NULL); strvec_pushf(&cp.env, "GIT_INDEX_FILE=%s", stash_index_path.buf); diff --git a/sparse-index.c b/sparse-index.c index 1fd70155a368e2..74883a8c87aa05 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -369,6 +369,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl) full = xcalloc(1, sizeof(struct index_state)); memcpy(full, istate, sizeof(struct index_state)); + full->name_hash_initialized = 0; + memset(&full->name_hash, 0, sizeof(full->name_hash)); + memset(&full->dir_hash, 0, sizeof(full->dir_hash)); + /* * This slightly-misnamed 'full' index might still be sparse if we * are only modifying the list of sparse directories. This hinges @@ -427,9 +431,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl) } /* Copy back into original index. */ + if (istate->name_hash_initialized) { + hashmap_clear(&istate->name_hash); + hashmap_clear(&istate->dir_hash); + } + istate->name_hash_initialized = full->name_hash_initialized; memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash)); memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash)); + istate->sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED; free(istate->cache); istate->cache = full->cache;