Skip to content

Commit 339eba6

Browse files
trieu1162000gitster
authored andcommitted
backfill: auto-detect sparse-checkout from config
Commit 85127bc ("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>
1 parent e565f37 commit 339eba6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

builtin/backfill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
120120
.repo = repo,
121121
.current_batch = OID_ARRAY_INIT,
122122
.min_batch_size = 50000,
123-
.sparse = 0,
123+
.sparse = -1,
124124
};
125125
struct option options[] = {
126126
OPT_INTEGER(0, "min-batch-size", &ctx.min_batch_size,

t/t5620-backfill.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ test_expect_success 'backfill --sparse' '
119119
test_line_count = 0 missing
120120
'
121121

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+
122137
test_expect_success 'backfill --sparse without cone mode (positive)' '
123138
git clone --no-checkout --filter=blob:none \
124139
--single-branch --branch=main \

0 commit comments

Comments
 (0)