sparse-checkout: correct reapply's handling of options

Commit 4e256731d6 ("sparse-checkout: enable reapply to take --[no-]{cone,sparse-index}", 2021-12-14) made it so that reapply could take additional options but added no tests. Tests would have shown that the feature doesn't work because the initial values are set AFTER parsing the command line options instead of before. Add a test and set the initial value at the appropriate time. Reviewed-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Feb 19, 2022 at 16:44 UTC f748012e01109d04d3e956e26557a7fb4f92ce47
2 files changed +31 -3
builtin/sparse-checkout.c
+3 -3
@@ -789,15 +789,15 @@ static int sparse_checkout_reapply(int argc, const char **argv)
789 if (!core_apply_sparse_checkout)
790 die(_("must be in a sparse-checkout to reapply sparsity patterns"));
791
792 + reapply_opts.cone_mode = -1;
793 + reapply_opts.sparse_index = -1;
794 +
795 argc = parse_options(argc, argv, NULL,
796 builtin_sparse_checkout_reapply_options,
797 builtin_sparse_checkout_reapply_usage, 0);
798
799 repo_read_index(the_repository);
800
798 - reapply_opts.cone_mode = -1;
799 - reapply_opts.sparse_index = -1;
800 -
801 if (update_modes(&reapply_opts.cone_mode, &reapply_opts.sparse_index))
802 return 1;
803
t/t1091-sparse-checkout-builtin.sh
+28
@@ -495,6 +495,34 @@ test_expect_failure 'sparse-checkout reapply' '
495 git -C tweak sparse-checkout disable
496 '
497
498 +test_expect_success 'reapply can handle config options' '
499 + git -C repo sparse-checkout init --cone --no-sparse-index &&
500 + git -C repo config --worktree --list >actual &&
501 + cat >expect <<-\EOF &&
502 + core.sparsecheckout=true
503 + core.sparsecheckoutcone=true
504 + EOF
505 + test_cmp expect actual &&
506 +
507 + git -C repo sparse-checkout reapply --no-cone --no-sparse-index &&
508 + git -C repo config --worktree --list >actual &&
509 + cat >expect <<-\EOF &&
510 + core.sparsecheckout=true
511 + EOF
512 + test_cmp expect actual &&
513 +
514 + git -C repo sparse-checkout reapply --cone --sparse-index &&
515 + git -C repo config --worktree --list >actual &&
516 + cat >expect <<-\EOF &&
517 + core.sparsecheckout=true
518 + core.sparsecheckoutcone=true
519 + index.sparse=true
520 + EOF
521 + test_cmp expect actual &&
522 +
523 + git -C repo sparse-checkout disable
524 +'
525 +
526 test_expect_success 'cone mode: set with core.ignoreCase=true' '
527 rm repo/.git/info/sparse-checkout &&
528 git -C repo sparse-checkout init --cone &&