Skip to content

Commit dcc5fd5

Browse files
derrickstoleegitster
authored andcommitted
sparse-checkout: disable sparse-index
We use 'git sparse-checkout init --cone --sparse-index' to toggle the sparse-index feature. It makes sense to also disable it when running 'git sparse-checkout disable'. This is particularly important because it removes the extensions.sparseIndex config option, allowing other tools to use this Git repository again. This does mean that 'git sparse-checkout init' will not re-enable the sparse-index feature, even if it was previously enabled. While testing this feature, I noticed that the sparse-index was not being written on the first run, but by a second. This was caught by the call to 'test-tool read-cache --table'. This requires adjusting some assignments to core_apply_sparse_checkout and pl.use_cone_patterns in the sparse_checkout_init() logic. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 122ba1f commit dcc5fd5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

builtin/sparse-checkout.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ static int set_config(enum sparse_checkout_mode mode)
280280
"core.sparseCheckoutCone",
281281
mode == MODE_CONE_PATTERNS ? "true" : NULL);
282282

283+
if (mode == MODE_NO_PATTERNS)
284+
set_sparse_index_config(the_repository, 0);
285+
283286
return 0;
284287
}
285288

@@ -341,10 +344,11 @@ static int sparse_checkout_init(int argc, const char **argv)
341344
the_repository->index->updated_workdir = 1;
342345
}
343346

347+
core_apply_sparse_checkout = 1;
348+
344349
/* If we already have a sparse-checkout file, use it. */
345350
if (res >= 0) {
346351
free(sparse_filename);
347-
core_apply_sparse_checkout = 1;
348352
return update_working_directory(NULL);
349353
}
350354

@@ -366,6 +370,7 @@ static int sparse_checkout_init(int argc, const char **argv)
366370
add_pattern(strbuf_detach(&pattern, NULL), empty_base, 0, &pl, 0);
367371
strbuf_addstr(&pattern, "!/*/");
368372
add_pattern(strbuf_detach(&pattern, NULL), empty_base, 0, &pl, 0);
373+
pl.use_cone_patterns = init_opts.cone_mode;
369374

370375
return write_patterns_and_update(&pl);
371376
}
@@ -632,6 +637,9 @@ static int sparse_checkout_disable(int argc, const char **argv)
632637
strbuf_addstr(&match_all, "/*");
633638
add_pattern(strbuf_detach(&match_all, NULL), empty_base, 0, &pl, 0);
634639

640+
prepare_repo_settings(the_repository);
641+
the_repository->settings.sparse_index = 0;
642+
635643
if (update_working_directory(&pl))
636644
die(_("error while refreshing working directory"));
637645

t/t1091-sparse-checkout-builtin.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ test_expect_success 'sparse-checkout disable' '
205205
check_files repo a deep folder1 folder2
206206
'
207207

208+
test_expect_success 'sparse-index enabled and disabled' '
209+
git -C repo sparse-checkout init --cone --sparse-index &&
210+
test_cmp_config -C repo true index.sparse &&
211+
test-tool -C repo read-cache --table >cache &&
212+
grep " tree " cache &&
213+
214+
git -C repo sparse-checkout disable &&
215+
test-tool -C repo read-cache --table >cache &&
216+
! grep " tree " cache &&
217+
git -C repo config --list >config &&
218+
! grep index.sparse config
219+
'
220+
208221
test_expect_success 'cone mode: init and set' '
209222
git -C repo sparse-checkout init --cone &&
210223
git -C repo config --list >config &&

0 commit comments

Comments
 (0)