diff --git a/builtin/stash.c b/builtin/stash.c index 2e2e40823b77f9..79fec5612edb6c 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -403,7 +403,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 c264766dd632d9..485b3972836d7d 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -375,6 +375,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 @@ -433,9 +437,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;