Skip to content

Commit 5e9fcce

Browse files
committed
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]>
1 parent 3dd8f97 commit 5e9fcce

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

t/t1091-sparse-checkout-builtin.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,18 @@ test_expect_success 'different sparse-checkouts with worktrees' '
305305
check_files worktree a deep
306306
'
307307

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+
308320
check_read_tree_errors () {
309321
REPO=$1
310322
FILES=$2

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ static int clear_ce_flags_1(struct index_state *istate,
14161416
name, &dtype, pl, istate);
14171417
if (ret == UNDECIDED)
14181418
ret = default_match;
1419-
if (ret == MATCHED)
1419+
if (ret == MATCHED || ret == MATCHED_RECURSIVE)
14201420
ce->ce_flags &= ~clear_mask;
14211421
cache++;
14221422
progress_nr++;

0 commit comments

Comments
 (0)