Skip to content

Commit ce904bd

Browse files
vdyedscho
authored andcommitted
Fix sparse-checkout set crashes (#607)
2 parents ea74993 + f2db492 commit ce904bd

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
@@ -402,7 +402,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
402402
if (pl &&
403403
path_matches_pattern_list(ce->name, ce->ce_namelen,
404404
NULL, &dtype,
405-
pl, istate) == NOT_MATCHED) {
405+
pl, full) == NOT_MATCHED) {
406406
set_index_entry(full, full->cache_nr++, ce);
407407
continue;
408408
}
@@ -430,6 +430,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
430430
}
431431

432432
/* Copy back into original index. */
433+
istate->name_hash_initialized = full->name_hash_initialized;
433434
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
434435
memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash));
435436
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
@@ -317,6 +317,22 @@ test_expect_success 'root directory cannot be sparse' '
317317
test_cmp expect actual
318318
'
319319

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

0 commit comments

Comments
 (0)