clone: send server options when using protocol v2

Commit 5e3548ef16 ("fetch: send server options when using protocol v2", 2018-04-24) taught "fetch" the ability to send server options when using protocol v2, but not "clone". This ability is triggered by "-o" or "--server-option". Teach "clone" the same ability, except that because "clone" already has "-o" for another parameter, teach "clone" only to receive "--server-option". Explain in the documentation, both for clone and for fetch, that server handling of server options are server-specific. This is similar to receive-pack's handling of push options - currently, they are just sent to hooks to interpret as they see fit. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Apr 12, 2019 at 12:51 UTC 6e98305985555ced61971ca0170dd976554193c0
4 files changed +38 -1
Documentation/fetch-options.txt
+2 -1
@@ -216,7 +216,8 @@ endif::git-pull[]
216 --server-option=<option>::
217 Transmit the given string to the server when communicating using
218 protocol version 2. The given string must not contain a NUL or LF
219 - character.
219 + character. The server's handling of server options, including
220 + unknown ones, is server-specific.
221 When multiple `--server-option=<option>` are given, they are all
222 sent to the other side in the order listed on the command line.
223
Documentation/git-clone.txt
+8
@@ -131,6 +131,14 @@ objects from the source repository into a pack in the cloned repository.
131 is specified. This flag forces progress status even if the
132 standard error stream is not directed to a terminal.
133
134 +--server-option=<option>::
135 + Transmit the given string to the server when communicating using
136 + protocol version 2. The given string must not contain a NUL or LF
137 + character. The server's handling of server options, including
138 + unknown ones, is server-specific.
139 + When multiple `--server-option=<option>` are given, they are all
140 + sent to the other side in the order listed on the command line.
141 +
142 --no-checkout::
143 -n::
144 No checkout of HEAD is performed after the clone is complete.
builtin/clone.c
+6
@@ -66,6 +66,7 @@ static int option_dissociate;
66 static int max_jobs = -1;
67 static struct string_list option_recurse_submodules = STRING_LIST_INIT_NODUP;
68 static struct list_objects_filter_options filter_options;
69 +static struct string_list server_options = STRING_LIST_INIT_NODUP;
70
71 static int recurse_submodules_cb(const struct option *opt,
72 const char *arg, int unset)
@@ -137,6 +138,8 @@ static struct option builtin_clone_options[] = {
138 N_("separate git dir from working tree")),
139 OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
140 N_("set config inside the new repository")),
141 + OPT_STRING_LIST(0, "server-option", &server_options,
142 + N_("server-specific"), N_("option to transmit")),
143 OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
144 TRANSPORT_FAMILY_IPV4),
145 OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
@@ -1136,6 +1139,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1139 transport_set_option(transport, TRANS_OPT_UPLOADPACK,
1140 option_upload_pack);
1141
1142 + if (server_options.nr)
1143 + transport->server_options = &server_options;
1144 +
1145 if (filter_options.choice) {
1146 struct strbuf expanded_filter_spec = STRBUF_INIT;
1147 expand_list_objects_filter_spec(&filter_options,
t/t5702-protocol-v2.sh
+22
@@ -270,6 +270,28 @@ test_expect_success 'warn if using server-option with fetch with legacy protocol
270 test_i18ngrep "server options require protocol version 2 or later" err
271 '
272
273 +test_expect_success 'server-options are sent when cloning' '
274 + test_when_finished "rm -rf log myclone" &&
275 +
276 + GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
277 + clone --server-option=hello --server-option=world \
278 + "file://$(pwd)/file_parent" myclone &&
279 +
280 + grep "server-option=hello" log &&
281 + grep "server-option=world" log
282 +'
283 +
284 +test_expect_success 'warn if using server-option with clone with legacy protocol' '
285 + test_when_finished "rm -rf myclone" &&
286 +
287 + test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
288 + clone --server-option=hello --server-option=world \
289 + "file://$(pwd)/file_parent" myclone 2>err &&
290 +
291 + test_i18ngrep "see protocol.version in" err &&
292 + test_i18ngrep "server options require protocol version 2 or later" err
293 +'
294 +
295 test_expect_success 'upload-pack respects config using protocol v2' '
296 git init server &&
297 write_script server/.git/hook <<-\EOF &&