Skip to contentSkip to conversation

add --must-filter option for fetch and clone

PREVIEW John Giorshev 1 participant 1 message Mar 31, 2025 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CADJmAEg6M=FJcndQQ45odztyAq8jATonEwXjrkuoZuZ=WXh7vQ@mail.gmail.com

#2 lore raw
Quoted 183 lines · John Giorshev

cc'ing reviewers. thanks.

context:
- https://stackoverflow.com/q/79413099/15534181
- https://public-inbox.org/git/[email protected]/

Quoted 174 lines · John Giorshev via GitGitGadget

From: John Giorshev <[email protected]>

---
add --must-filter, give error on filter not supported instead of warn

from:
https://public-inbox.org/git/[email protected]/

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1869%2Fjagprog5%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1869/jagprog5/master-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1869

 builtin/clone.c          |  6 ++++++
 builtin/fetch.c          |  7 ++++++-
 fetch-pack.c             |  8 ++++++--
 fetch-pack.h             |  1 +
 t/t0410-partial-clone.sh | 17 +++++++++++++++++
 transport.c              |  1 +
 transport.h              |  1 +
 7 files changed, 38 insertions(+), 3 deletions(-)
builtin/clone.c +6 -0
index f9a2ecbe9cc..7000b0ecd36 100644
@@ -887,6 +887,7 @@ int cmd_clone(int argc,
        enum ref_storage_format ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
        const int do_not_override_repo_unix_permissions = -1;
        int option_reject_shallow = -1; /* unspecified */
+       int must_filter = 0;
        int deepen = 0;
        char *option_template = NULL, *option_depth = NULL, *option_since = NULL;
        char *option_origin = NULL;
@@ -915,6 +916,8 @@ int cmd_clone(int argc,
                         N_("force progress reporting")),
                OPT_BOOL(0, "reject-shallow", &option_reject_shallow,
                         N_("don't clone shallow repository")),
+               OPT_BOOL(0, "must-filter", &must_filter,
+                        N_("error on filter not supported by server")),
                OPT_BOOL('n', "no-checkout", &option_no_checkout,
                         N_("don't create a checkout")),
                OPT_BOOL(0, "bare", &option_bare, N_("create a bare repository")),
@@ -1333,6 +1336,9 @@ int cmd_clone(int argc,
        transport_set_verbosity(transport, option_verbosity, option_progress);
        transport->family = family;
        transport->cloning = 1;
+       if (transport->smart_options) {
+               transport->smart_options->must_filter = must_filter;
+       }
 
        if (is_bundle) {
                struct bundle_header header = BUNDLE_HEADER_INIT;
builtin/fetch.c +6 -1
index 1c740d5aac3..1f3cdf53148 100644
@@ -84,7 +84,7 @@ static int prune_tags = -1; /* unspecified */
 
 static int append, dry_run, force, keep, update_head_ok;
 static int write_fetch_head = 1;
-static int verbosity, deepen_relative, set_upstream, refetch;
+static int verbosity, deepen_relative, set_upstream, refetch, must_filter;
 static int progress = -1;
 static int tags = TAGS_DEFAULT, update_shallow, deepen;
 static int atomic_fetch;
@@ -1508,6 +1508,9 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
        transport = transport_get(remote, NULL);
        transport_set_verbosity(transport, verbosity, progress);
        transport->family = family;
+       if (transport->smart_options) {
+               transport->smart_options->must_filter = must_filter;
+       }
        if (upload_pack)
                set_option(transport, TRANS_OPT_UPLOADPACK, upload_pack);
        if (keep)
@@ -2322,6 +2325,8 @@ int cmd_fetch(int argc,
                         N_("append to .git/FETCH_HEAD instead of overwriting")),
                OPT_BOOL(0, "atomic", &atomic_fetch,
                         N_("use atomic transaction to update references")),
+               OPT_BOOL(0, "must-filter", &must_filter,
+                        N_("error on filter not supported by server")),
                OPT_STRING(0, "upload-pack", &upload_pack, N_("path"),
                           N_("path to upload pack on remote end")),
                OPT__FORCE(&force, N_("force overwrite of local reference"), 0),
fetch-pack.c +6 -2
index 1ed5e11dd56..0cf59c1bc82 100644
@@ -319,9 +319,13 @@ static void send_filter(struct fetch_pack_args *args,
                        trace2_data_string("fetch", the_repository,
                                           "filter/effective", spec);
                } else {
-                       warning("filtering not recognized by server, ignoring");
-                       trace2_data_string("fetch", the_repository,
+                       if (args->must_filter) {
+                               die("filtering not recognized by server");
+                       } else {
+                               warning("filtering not recognized by server, ignoring");
+                               trace2_data_string("fetch", the_repository,
                                           "filter/unsupported", spec);
+                       }
                }
        } else {
                trace2_data_string("fetch", the_repository,
fetch-pack.h +1 -0
index 9d3470366f8..01ab94fc24b 100644
@@ -40,6 +40,7 @@ struct fetch_pack_args {
        unsigned cloning:1;
        unsigned update_shallow:1;
        unsigned reject_shallow_remote:1;
+       unsigned must_filter:1;
        unsigned deepen:1;
        unsigned refetch:1;
 
t/t0410-partial-clone.sh +17 -0
index 2a5bdbeeb87..0166c491ca5 100755
@@ -48,6 +48,23 @@ test_expect_success 'convert shallow clone to partial clone' '
        test_cmp_config -C client 1 core.repositoryformatversion
 '
 
+test_expect_failure 'must filter clone' '
+       rm -fr server client &&
+       test_create_repo server &&
+       test_commit -C server my_commit 1 &&
+       test_commit -C server my_commit2 1 &&
+       git clone --filter="blob:none" --must-filter "file://$(pwd)/server" client
+'
+
+test_expect_failure 'must filter fetch' '
+       rm -fr server client &&
+       test_create_repo server &&
+       test_commit -C server my_commit 1 &&
+       test_commit -C server my_commit2 1 &&
+       git clone --depth=1 "file://$(pwd)/server" client &&
+       git -C client fetch --unshallow --filter="blob:none" --must-filter
+'
+
 test_expect_success DEFAULT_REPO_FORMAT 'convert to partial clone with noop extension' '
        rm -fr server client &&
        test_create_repo server &&
transport.c +1 -0
index 6c2801bcbd9..0543821399d 100644
@@ -450,6 +450,7 @@ static int fetch_refs_via_pack(struct transport *transport,
        args.quiet = (transport->verbose < 0);
        args.no_progress = !transport->progress;
        args.depth = data->options.depth;
+       args.must_filter = data->options.must_filter;
        args.deepen_since = data->options.deepen_since;
        args.deepen_not = data->options.deepen_not;
        args.deepen_relative = data->options.deepen_relative;
transport.h +1 -0
index 44100fa9b7f..0ffc8d273ab 100644
@@ -16,6 +16,7 @@ struct git_transport_options {
        unsigned reject_shallow : 1;
        unsigned deepen_relative : 1;
        unsigned refetch : 1;
+       unsigned must_filter : 1;
 
        /* see documentation of corresponding flag in fetch-pack.h */
        unsigned from_promisor : 1;

base-commit: a554262210b4a2ee6fa2d594e1f09f5830888c56 --
gitgitgadget