Skip to content

Commit f748012

Browse files
newrengitster
authored andcommitted
sparse-checkout: correct reapply's handling of options
Commit 4e25673 ("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 <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b801210 commit f748012

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

builtin/sparse-checkout.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,15 +789,15 @@ static int sparse_checkout_reapply(int argc, const char **argv)
789789
if (!core_apply_sparse_checkout)
790790
die(_("must be in a sparse-checkout to reapply sparsity patterns"));
791791

792+
reapply_opts.cone_mode = -1;
793+
reapply_opts.sparse_index = -1;
794+
792795
argc = parse_options(argc, argv, NULL,
793796
builtin_sparse_checkout_reapply_options,
794797
builtin_sparse_checkout_reapply_usage, 0);
795798

796799
repo_read_index(the_repository);
797800

798-
reapply_opts.cone_mode = -1;
799-
reapply_opts.sparse_index = -1;
800-
801801
if (update_modes(&reapply_opts.cone_mode, &reapply_opts.sparse_index))
802802
return 1;
803803

t/t1091-sparse-checkout-builtin.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,34 @@ test_expect_failure 'sparse-checkout reapply' '
495495
git -C tweak sparse-checkout disable
496496
'
497497

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+
498526
test_expect_success 'cone mode: set with core.ignoreCase=true' '
499527
rm repo/.git/info/sparse-checkout &&
500528
git -C repo sparse-checkout init --cone &&

0 commit comments

Comments
 (0)