Skip to content

Commit c434b3c

Browse files
derrickstoleegitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 09762ce commit c434b3c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Documentation/git-backfill.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ OPTIONS
5656

5757
--[no-]sparse::
5858
Only download objects if they appear at a path that matches the
59-
current sparse-checkout.
59+
current sparse-checkout. If the sparse-checkout feature is enabled,
60+
then `--sparse` is assumed and can be disabled with `--no-sparse`.
6061

6162
SEE ALSO
6263
--------

builtin/backfill.c

Lines changed: 7 additions & 0 deletions
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"
@@ -140,5 +144,8 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
140144

141145
repo_config(repo, git_default_config, NULL);
142146

147+
if (ctx.sparse < 0)
148+
ctx.sparse = core_apply_sparse_checkout;
149+
143150
return do_backfill(&ctx);
144151
}

t/t5620-backfill.sh

Lines changed: 12 additions & 1 deletion
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' '

0 commit comments

Comments
 (0)