{"thread":{"id":"63034","subject":"[PATCH] add --must-filter option for fetch and clone","startedAt":"2025-03-01T21:07:26Z","lastAt":"2025-03-01T21:07:26Z","messageCount":1,"participants":["John Giorshev via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"513345","messageId":"pull.1869.git.1740863242815.gitgitgadget@gmail.com","threadId":"63034","inReplyTo":null,"subject":"[PATCH] add --must-filter option for fetch and clone","fromName":"John Giorshev via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-03-01T21:07:22Z","receivedAt":"2025-03-01T21:07:26Z","isPatch":true,"sender":{"key":"john.giorshev1@gmail.com","avatar":null},"body":"From: John Giorshev <john.giorshev1@gmail.com>\n\nSigned-off-by: John Giorshev <john.giorshev1@gmail.com>\n---\n    add --must-filter, give error on filter not supported instead of warn\n    \n    from:\n    https://public-inbox.org/git/20250225013227.GB752084@coredump.intra.peff.net/\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1869%2Fjagprog5%2Fmaster-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1869/jagprog5/master-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1869\n\n builtin/clone.c          |  6 ++++++\n builtin/fetch.c          |  7 ++++++-\n fetch-pack.c             |  8 ++++++--\n fetch-pack.h             |  1 +\n t/t0410-partial-clone.sh | 17 +++++++++++++++++\n transport.c              |  1 +\n transport.h              |  1 +\n 7 files changed, 38 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex f9a2ecbe9cc..7000b0ecd36 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -887,6 +887,7 @@ int cmd_clone(int argc,\n \tenum ref_storage_format ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;\n \tconst int do_not_override_repo_unix_permissions = -1;\n \tint option_reject_shallow = -1; /* unspecified */\n+\tint must_filter = 0;\n \tint deepen = 0;\n \tchar *option_template = NULL, *option_depth = NULL, *option_since = NULL;\n \tchar *option_origin = NULL;\n@@ -915,6 +916,8 @@ int cmd_clone(int argc,\n \t\t\t N_(\"force progress reporting\")),\n \t\tOPT_BOOL(0, \"reject-shallow\", &option_reject_shallow,\n \t\t\t N_(\"don't clone shallow repository\")),\n+\t\tOPT_BOOL(0, \"must-filter\", &must_filter,\n+\t\t\t N_(\"error on filter not supported by server\")),\n \t\tOPT_BOOL('n', \"no-checkout\", &option_no_checkout,\n \t\t\t N_(\"don't create a checkout\")),\n \t\tOPT_BOOL(0, \"bare\", &option_bare, N_(\"create a bare repository\")),\n@@ -1333,6 +1336,9 @@ int cmd_clone(int argc,\n \ttransport_set_verbosity(transport, option_verbosity, option_progress);\n \ttransport->family = family;\n \ttransport->cloning = 1;\n+\tif (transport->smart_options) {\n+\t\ttransport->smart_options->must_filter = must_filter;\n+\t}\n \n \tif (is_bundle) {\n \t\tstruct bundle_header header = BUNDLE_HEADER_INIT;\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 1c740d5aac3..1f3cdf53148 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -84,7 +84,7 @@ static int prune_tags = -1; /* unspecified */\n \n static int append, dry_run, force, keep, update_head_ok;\n static int write_fetch_head = 1;\n-static int verbosity, deepen_relative, set_upstream, refetch;\n+static int verbosity, deepen_relative, set_upstream, refetch, must_filter;\n static int progress = -1;\n static int tags = TAGS_DEFAULT, update_shallow, deepen;\n static int atomic_fetch;\n@@ -1508,6 +1508,9 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)\n \ttransport = transport_get(remote, NULL);\n \ttransport_set_verbosity(transport, verbosity, progress);\n \ttransport->family = family;\n+\tif (transport->smart_options) {\n+\t\ttransport->smart_options->must_filter = must_filter;\n+\t}\n \tif (upload_pack)\n \t\tset_option(transport, TRANS_OPT_UPLOADPACK, upload_pack);\n \tif (keep)\n@@ -2322,6 +2325,8 @@ int cmd_fetch(int argc,\n \t\t\t N_(\"append to .git/FETCH_HEAD instead of overwriting\")),\n \t\tOPT_BOOL(0, \"atomic\", &atomic_fetch,\n \t\t\t N_(\"use atomic transaction to update references\")),\n+\t\tOPT_BOOL(0, \"must-filter\", &must_filter,\n+\t\t\t N_(\"error on filter not supported by server\")),\n \t\tOPT_STRING(0, \"upload-pack\", &upload_pack, N_(\"path\"),\n \t\t\t   N_(\"path to upload pack on remote end\")),\n \t\tOPT__FORCE(&force, N_(\"force overwrite of local reference\"), 0),\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 1ed5e11dd56..0cf59c1bc82 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -319,9 +319,13 @@ static void send_filter(struct fetch_pack_args *args,\n \t\t\ttrace2_data_string(\"fetch\", the_repository,\n \t\t\t\t\t   \"filter/effective\", spec);\n \t\t} else {\n-\t\t\twarning(\"filtering not recognized by server, ignoring\");\n-\t\t\ttrace2_data_string(\"fetch\", the_repository,\n+\t\t\tif (args->must_filter) {\n+\t\t\t\tdie(\"filtering not recognized by server\");\n+\t\t\t} else {\n+\t\t\t\twarning(\"filtering not recognized by server, ignoring\");\n+\t\t\t\ttrace2_data_string(\"fetch\", the_repository,\n \t\t\t\t\t   \"filter/unsupported\", spec);\n+\t\t\t}\n \t\t}\n \t} else {\n \t\ttrace2_data_string(\"fetch\", the_repository,\ndiff --git a/fetch-pack.h b/fetch-pack.h\nindex 9d3470366f8..01ab94fc24b 100644\n--- a/fetch-pack.h\n+++ b/fetch-pack.h\n@@ -40,6 +40,7 @@ struct fetch_pack_args {\n \tunsigned cloning:1;\n \tunsigned update_shallow:1;\n \tunsigned reject_shallow_remote:1;\n+\tunsigned must_filter:1;\n \tunsigned deepen:1;\n \tunsigned refetch:1;\n \ndiff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh\nindex 2a5bdbeeb87..0166c491ca5 100755\n--- a/t/t0410-partial-clone.sh\n+++ b/t/t0410-partial-clone.sh\n@@ -48,6 +48,23 @@ test_expect_success 'convert shallow clone to partial clone' '\n \ttest_cmp_config -C client 1 core.repositoryformatversion\n '\n \n+test_expect_failure 'must filter clone' '\n+\trm -fr server client &&\n+\ttest_create_repo server &&\n+\ttest_commit -C server my_commit 1 &&\n+\ttest_commit -C server my_commit2 1 &&\n+\tgit clone --filter=\"blob:none\" --must-filter \"file://$(pwd)/server\" client\n+'\n+\n+test_expect_failure 'must filter fetch' '\n+\trm -fr server client &&\n+\ttest_create_repo server &&\n+\ttest_commit -C server my_commit 1 &&\n+\ttest_commit -C server my_commit2 1 &&\n+\tgit clone --depth=1 \"file://$(pwd)/server\" client &&\n+\tgit -C client fetch --unshallow --filter=\"blob:none\" --must-filter\n+'\n+\n test_expect_success DEFAULT_REPO_FORMAT 'convert to partial clone with noop extension' '\n \trm -fr server client &&\n \ttest_create_repo server &&\ndiff --git a/transport.c b/transport.c\nindex 6c2801bcbd9..0543821399d 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -450,6 +450,7 @@ static int fetch_refs_via_pack(struct transport *transport,\n \targs.quiet = (transport->verbose < 0);\n \targs.no_progress = !transport->progress;\n \targs.depth = data->options.depth;\n+\targs.must_filter = data->options.must_filter;\n \targs.deepen_since = data->options.deepen_since;\n \targs.deepen_not = data->options.deepen_not;\n \targs.deepen_relative = data->options.deepen_relative;\ndiff --git a/transport.h b/transport.h\nindex 44100fa9b7f..0ffc8d273ab 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -16,6 +16,7 @@ struct git_transport_options {\n \tunsigned reject_shallow : 1;\n \tunsigned deepen_relative : 1;\n \tunsigned refetch : 1;\n+\tunsigned must_filter : 1;\n \n \t/* see documentation of corresponding flag in fetch-pack.h */\n \tunsigned from_promisor : 1;\n\nbase-commit: a554262210b4a2ee6fa2d594e1f09f5830888c56\n-- \ngitgitgadget\n"}]}