]> git.ipfire.org Git - thirdparty/git.git/commitdiff
backfill: auto-detect sparse-checkout from config
authorTrieu Huynh <vikingtc4@gmail.com>
Sat, 4 Apr 2026 11:15:57 +0000 (18:15 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Apr 2026 16:26:08 +0000 (09:26 -0700)
Commit 85127bcdea ("backfill: assume --sparse when sparse-checkout is
enabled") intended for 'git backfill' to consult the repository
configuration when the user does not pass '--sparse' or
'--no-sparse' on the command line. It added the sentinel check:

    if (ctx->sparse < 0)
        ctx->sparse = cfg->apply_sparse_checkout;

However, the ctx->sparse field is initialized to 0 instead of -1,
so this guard never triggers. Consequently, the repository config
(core.sparseCheckout) is never checked, and the command always
performs a full backfill even when sparse-checkout is enabled.

Fix this by initializing ctx->sparse to -1, ensuring the existing
fallback logic correctly reads the repository configuration when
no explicit flags are provided.

Add a test to verify that 'git backfill' automatically respects
sparse-checkout settings when no flags are passed.

Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/backfill.c
t/t5620-backfill.sh

index 33e1ea2f84ff6b09ef99408d6878808bb6c23017..77d154958cb27576da84522bfada71b4d5e14ac4 100644 (file)
@@ -120,7 +120,7 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
                .repo = repo,
                .current_batch = OID_ARRAY_INIT,
                .min_batch_size = 50000,
-               .sparse = 0,
+               .sparse = -1,
        };
        struct option options[] = {
                OPT_INTEGER(0, "min-batch-size", &ctx.min_batch_size,
index 58c81556e72c899a6ff5a7a7d0169441bb62aa8f..bed4987124f9dd6f68724fb1d58b0bbaca1d27c1 100755 (executable)
@@ -119,6 +119,21 @@ test_expect_success 'backfill --sparse' '
        test_line_count = 0 missing
 '
 
+test_expect_success 'backfill auto-detects sparse-checkout from config' '
+       git clone --sparse --filter=blob:none \
+               --single-branch --branch=main \
+               "file://$(pwd)/srv.bare" backfill-auto-sparse &&
+
+       git -C backfill-auto-sparse rev-list --quiet --objects --missing=print HEAD >missing &&
+       test_line_count = 44 missing &&
+
+       GIT_TRACE2_EVENT="$(pwd)/auto-sparse-trace" git \
+               -C backfill-auto-sparse backfill &&
+
+       test_trace2_data promisor fetch_count 4 <auto-sparse-trace &&
+       test_trace2_data path-walk paths 5 <auto-sparse-trace
+'
+
 test_expect_success 'backfill --sparse without cone mode (positive)' '
        git clone --no-checkout --filter=blob:none              \
                --single-branch --branch=main           \