Skip to content

Commit c3a46e3

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 0e66529 commit c3a46e3

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
@@ -48,7 +48,8 @@ OPTIONS
4848

4949
--[no-]sparse::
5050
Only download objects if they appear at a path that matches the
51-
current sparse-checkout.
51+
current sparse-checkout. If the sparse-checkout feature is enabled,
52+
then `--sparse` is assumed and can be disabled with `--no-sparse`.
5253

5354
SEE ALSO
5455
--------

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"
@@ -136,5 +140,8 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
136140

137141
repo_config(repo, git_default_config, NULL);
138142

143+
if (ctx.sparse < 0)
144+
ctx.sparse = core_apply_sparse_checkout;
145+
139146
return do_backfill(&ctx);
140147
}

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 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' '

0 commit comments

Comments
 (0)