@matheusbsbs / matheus-bagliano / commits / f998a3f1e5
Fork 0

sparse-checkout: fix cone mode behavior mismatch

The intention of the special "cone mode" in the sparse-checkout feature is to always match the same patterns that are matched by the same sparse-checkout file as when cone mode is disabled. When a file path is given to "git sparse-checkout set" in cone mode, then the cone mode improperly matches the file as a recursive path. When setting the skip-worktree bits, files were not expecting the MATCHED_RECURSIVE response, and hence these were left out of the matched cone. Fix this bug by checking for MATCHED_RECURSIVE in addition to MATCHED and add a test that prevents regression. Reported-by: Finn Bryant <finnbryant@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 31, 2020 at 20:16 UTC f998a3f1e588d73ed7285cb14ac4839f63f6dc82
2 files changed +13 -1
t/t1091-sparse-checkout-builtin.sh
+12
@@ -305,6 +305,18 @@ test_expect_success 'different sparse-checkouts with worktrees' '
305 check_files worktree a deep
306 '
307
308 +test_expect_success 'set using filename keeps file on-disk' '
309 + git -C repo sparse-checkout set a deep &&
310 + cat >expect <<-\EOF &&
311 + /*
312 + !/*/
313 + /a/
314 + /deep/
315 + EOF
316 + test_cmp expect repo/.git/info/sparse-checkout &&
317 + check_files repo a deep
318 +'
319 +
320 check_read_tree_errors () {
321 REPO=$1
322 FILES=$2
unpack-trees.c
+1 -1
@@ -1416,7 +1416,7 @@ static int clear_ce_flags_1(struct index_state *istate,
1416 name, &dtype, pl, istate);
1417 if (ret == UNDECIDED)
1418 ret = default_match;
1419 - if (ret == MATCHED)
1419 + if (ret == MATCHED || ret == MATCHED_RECURSIVE)
1420 ce->ce_flags &= ~clear_mask;
1421 cache++;
1422 progress_nr++;