diff --git a/Documentation/git-backfill.txt b/Documentation/git-backfill.txt index ecf2ac428cefb7..066ec6b161a22c 100644 --- a/Documentation/git-backfill.txt +++ b/Documentation/git-backfill.txt @@ -48,7 +48,8 @@ OPTIONS --[no-]sparse:: Only download objects if they appear at a path that matches the - current sparse-checkout. + current sparse-checkout. If the sparse-checkout feature is enabled, + then `--sparse` is assumed and can be disabled with `--no-sparse`. SEE ALSO -------- diff --git a/builtin/backfill.c b/builtin/backfill.c index de75471cf44657..82a18e58a4102f 100644 --- a/builtin/backfill.c +++ b/builtin/backfill.c @@ -5,6 +5,7 @@ #include "repository.h" #include "commit.h" #include "dir.h" +#include "environment.h" #include "hex.h" #include "tree.h" #include "tree-walk.h" @@ -133,5 +134,8 @@ int cmd_backfill(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); + if (ctx.sparse < 0) + ctx.sparse = core_apply_sparse_checkout; + return do_backfill(&ctx); } diff --git a/t/t5620-backfill.sh b/t/t5620-backfill.sh index c7bb27b72c15ee..1fa2e90f8cf57f 100755 --- a/t/t5620-backfill.sh +++ b/t/t5620-backfill.sh @@ -80,6 +80,12 @@ test_expect_success 'do partial clone 2, backfill batch size' ' test_line_count = 0 revs2 ' +test_expect_success 'backfill --sparse without sparse-checkout fails' ' + git init not-sparse && + test_must_fail git -C not-sparse backfill --sparse 2>err && + grep "problem loading sparse-checkout" err +' + test_expect_success 'backfill --sparse' ' git clone --sparse --filter=blob:none \ --single-branch --branch=main \ @@ -108,7 +114,12 @@ test_expect_success 'backfill --sparse' ' test_trace2_data promisor fetch_count 8 missing && - test_line_count = 24 missing + test_line_count = 24 missing && + + # Disabling the --sparse option (on by default) will download everything + git -C backfill3 backfill --no-sparse && + git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing && + test_line_count = 0 missing ' test_expect_success 'backfill --sparse without cone mode' '