]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-checkout: fix cone mode behavior mismatch
authorDerrick Stolee <dstolee@microsoft.com>
Fri, 31 Jan 2020 20:16:15 +0000 (20:16 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 31 Jan 2020 21:05:29 +0000 (13:05 -0800)
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>
t/t1091-sparse-checkout-builtin.sh
unpack-trees.c

index 37e9304ef32cf0bd84da1ba8038743d1180410e6..7d982096fbf0a25262b975f57f625895eac0aa33 100755 (executable)
@@ -305,6 +305,18 @@ test_expect_success 'different sparse-checkouts with worktrees' '
        check_files worktree a deep
 '
 
+test_expect_success 'set using filename keeps file on-disk' '
+       git -C repo sparse-checkout set a deep &&
+       cat >expect <<-\EOF &&
+       /*
+       !/*/
+       /a/
+       /deep/
+       EOF
+       test_cmp expect repo/.git/info/sparse-checkout &&
+       check_files repo a deep
+'
+
 check_read_tree_errors () {
        REPO=$1
        FILES=$2
index 3789a22cf0a519ac7b913c09b7b673a17bbe0ca4..78425ce74b5da2cbf9280770ec415e1b15ef7db4 100644 (file)
@@ -1416,7 +1416,7 @@ static int clear_ce_flags_1(struct index_state *istate,
                                                name, &dtype, pl, istate);
                if (ret == UNDECIDED)
                        ret = default_match;
-               if (ret == MATCHED)
+               if (ret == MATCHED || ret == MATCHED_RECURSIVE)
                        ce->ce_flags &= ~clear_mask;
                cache++;
                progress_nr++;