Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sparse-checkout set crashes #607

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sparse-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static int add_path_to_index(const struct object_id *oid,
size_t len = base->len;

if (S_ISDIR(mode)) {
int dtype;
int dtype = DT_DIR;
size_t baselen = base->len;
if (!ctx->pl)
return READ_TREE_RECURSIVE;
Expand Down Expand Up @@ -360,7 +360,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
struct cache_entry *ce = istate->cache[i];
struct tree *tree;
struct pathspec ps;
int dtype;
int dtype = DT_UNKNOWN;

if (!S_ISSPARSEDIR(ce->ce_mode)) {
set_index_entry(full, full->cache_nr++, ce);
Expand All @@ -371,7 +371,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
if (pl &&
path_matches_pattern_list(ce->name, ce->ce_namelen,
NULL, &dtype,
pl, istate) == NOT_MATCHED) {
pl, full) == NOT_MATCHED) {
set_index_entry(full, full->cache_nr++, ce);
continue;
}
Expand Down Expand Up @@ -399,6 +399,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
}

/* Copy back into original index. */
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;
Expand Down
16 changes: 16 additions & 0 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,22 @@ test_expect_success 'root directory cannot be sparse' '
test_cmp expect actual
'

test_expect_success 'sparse-checkout with untracked files and dirs' '
init_repos &&
# Empty directories outside sparse cone are deleted
run_on_sparse mkdir -p deep/empty &&
test_sparse_match git sparse-checkout set folder1 &&
test_must_be_empty sparse-checkout-err &&
run_on_sparse test_path_is_missing deep &&
# Untracked files outside sparse cone are not deleted
run_on_sparse touch folder1/another &&
test_sparse_match git sparse-checkout set folder2 &&
grep "directory ${SQ}folder1/${SQ} contains untracked files" sparse-checkout-err &&
run_on_sparse test_path_exists folder1/another
'

test_expect_success 'status with options' '
init_repos &&
test_sparse_match ls &&
Expand Down
Loading