Skip to content

Commit 4824feb

Browse files
vdyedscho
authored andcommitted
Fix sparse-checkout set crashes (#607)
2 parents 4e4811b + e768441 commit 4824feb

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
@@ -371,7 +371,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
371371
if (pl &&
372372
path_matches_pattern_list(ce->name, ce->ce_namelen,
373373
NULL, &dtype,
374-
pl, istate) == NOT_MATCHED) {
374+
pl, full) == NOT_MATCHED) {
375375
set_index_entry(full, full->cache_nr++, ce);
376376
continue;
377377
}
@@ -399,6 +399,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
399399
}
400400

401401
/* Copy back into original index. */
402+
istate->name_hash_initialized = full->name_hash_initialized;
402403
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
403404
memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash));
404405
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
@@ -311,6 +311,22 @@ test_expect_success 'root directory cannot be sparse' '
311311
test_cmp expect actual
312312
'
313313

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

0 commit comments

Comments
 (0)