backfill: auto-detect sparse-checkout from config

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>

Trieu Huynh committed Apr 4, 2026 at 18:15 UTC 339eba65a7f8aa596199e04f45683c48a1562b9c
2 files changed +16 -1
builtin/backfill.c
+1 -1
@@ -120,7 +120,7 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
120 .repo = repo,
121 .current_batch = OID_ARRAY_INIT,
122 .min_batch_size = 50000,
123 - .sparse = 0,
123 + .sparse = -1,
124 };
125 struct option options[] = {
126 OPT_INTEGER(0, "min-batch-size", &ctx.min_batch_size,
t/t5620-backfill.sh
+15
@@ -119,6 +119,21 @@ test_expect_success 'backfill --sparse' '
119 test_line_count = 0 missing
120 '
121
122 +test_expect_success 'backfill auto-detects sparse-checkout from config' '
123 + git clone --sparse --filter=blob:none \
124 + --single-branch --branch=main \
125 + "file://$(pwd)/srv.bare" backfill-auto-sparse &&
126 +
127 + git -C backfill-auto-sparse rev-list --quiet --objects --missing=print HEAD >missing &&
128 + test_line_count = 44 missing &&
129 +
130 + GIT_TRACE2_EVENT="$(pwd)/auto-sparse-trace" git \
131 + -C backfill-auto-sparse backfill &&
132 +
133 + test_trace2_data promisor fetch_count 4 <auto-sparse-trace &&
134 + test_trace2_data path-walk paths 5 <auto-sparse-trace
135 +'
136 +
137 test_expect_success 'backfill --sparse without cone mode (positive)' '
138 git clone --no-checkout --filter=blob:none \
139 --single-branch --branch=main \