diff --git a/builtin/stash.c b/builtin/stash.c index ec0a4ee08238dc..9493cff0ee90ee 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -402,7 +402,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 13c8e46c21d1b4..958c14a0987594 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -374,6 +374,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 @@ -432,9 +436,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;