Skip to content

Commit ce7360d

Browse files
committed
backfill: assume --sparse when sparse-checkout is enabled
The previous change introduced the '--[no-]sparse' option for the 'git backfill' command, but did not assume it as enabled by default. However, this is likely the behavior that users will most often want to happen. Without this default, users with a small sparse-checkout may be confused when 'git backfill' downloads every version of every object in the full history. However, this is left as a separate change so this decision can be reviewed independently of the value of the '--[no-]sparse' option. Add a test of adding the '--sparse' option to a repo without sparse-checkout to make it clear that supplying it without a sparse-checkout is an error. Signed-off-by: Derrick Stolee <[email protected]>
1 parent c4a01c2 commit ce7360d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Documentation/git-backfill.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ OPTIONS
5959

6060
`--[no-]sparse`::
6161
Only download objects if they appear at a path that matches the
62-
current sparse-checkout.
62+
current sparse-checkout. If the sparse-checkout feature is enabled,
63+
then `--sparse` is assumed and can be disabled with `--no-sparse`.
6364

6465
SEE ALSO
6566
--------

builtin/backfill.c

+7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
/* We need this macro to access core_apply_sparse_checkout */
2+
#define USE_THE_REPOSITORY_VARIABLE
3+
14
#include "builtin.h"
25
#include "git-compat-util.h"
36
#include "config.h"
47
#include "parse-options.h"
58
#include "repository.h"
69
#include "commit.h"
710
#include "dir.h"
11+
#include "environment.h"
812
#include "hex.h"
913
#include "tree.h"
1014
#include "tree-walk.h"
@@ -133,6 +137,9 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
133137

134138
repo_config(repo, git_default_config, NULL);
135139

140+
if (ctx.sparse < 0)
141+
ctx.sparse = core_apply_sparse_checkout;
142+
136143
result = do_backfill(&ctx);
137144
backfill_context_clear(&ctx);
138145
return result;

t/t5620-backfill.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ test_expect_success 'do partial clone 2, backfill min batch size' '
7777
test_line_count = 0 revs2
7878
'
7979

80+
test_expect_success 'backfill --sparse without sparse-checkout fails' '
81+
git init not-sparse &&
82+
test_must_fail git -C not-sparse backfill --sparse 2>err &&
83+
grep "problem loading sparse-checkout" err
84+
'
85+
8086
test_expect_success 'backfill --sparse' '
8187
git clone --sparse --filter=blob:none \
8288
--single-branch --branch=main \
@@ -105,7 +111,12 @@ test_expect_success 'backfill --sparse' '
105111
test_trace2_data promisor fetch_count 8 <sparse-trace2 &&
106112
test_trace2_data path-walk paths 15 <sparse-trace2 &&
107113
git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
108-
test_line_count = 24 missing
114+
test_line_count = 24 missing &&
115+
116+
# Disabling the --sparse option (on by default) will download everything
117+
git -C backfill3 backfill --no-sparse &&
118+
git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
119+
test_line_count = 0 missing
109120
'
110121

111122
test_expect_success 'backfill --sparse without cone mode (positive)' '

0 commit comments

Comments
 (0)