Skip to content

Commit 215c831

Browse files
vdyedscho
authored andcommitted
Fix sparse-checkout set crashes (#607)
2 parents 207f703 + aad6134 commit 215c831

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

sparse-index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
399399
if (pl &&
400400
path_matches_pattern_list(ce->name, ce->ce_namelen,
401401
NULL, &dtype,
402-
pl, istate) == NOT_MATCHED) {
402+
pl, full) == NOT_MATCHED) {
403403
set_index_entry(full, full->cache_nr++, ce);
404404
continue;
405405
}
@@ -427,6 +427,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
427427
}
428428

429429
/* Copy back into original index. */
430+
istate->name_hash_initialized = full->name_hash_initialized;
430431
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
431432
memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash));
432433
istate->sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED;

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,22 @@ test_expect_success 'root directory cannot be sparse' '
314314
test_cmp expect actual
315315
'
316316

317+
test_expect_success 'sparse-checkout with untracked files and dirs' '
318+
init_repos &&
319+
320+
# Empty directories outside sparse cone are deleted
321+
run_on_sparse mkdir -p deep/empty &&
322+
test_sparse_match git sparse-checkout set folder1 &&
323+
test_must_be_empty sparse-checkout-err &&
324+
run_on_sparse test_path_is_missing deep &&
325+
326+
# Untracked files outside sparse cone are not deleted
327+
run_on_sparse touch folder1/another &&
328+
test_sparse_match git sparse-checkout set folder2 &&
329+
grep "directory ${SQ}folder1/${SQ} contains untracked files" sparse-checkout-err &&
330+
run_on_sparse test_path_exists folder1/another
331+
'
332+
317333
test_expect_success 'status with options' '
318334
init_repos &&
319335
test_sparse_match ls &&

0 commit comments

Comments
 (0)