Skip to content

Commit 6e98305

Browse files
jonathantanmygitster
authored andcommitted
clone: send server options when using protocol v2
Commit 5e3548e ("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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35eb824 commit 6e98305

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

Documentation/fetch-options.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ endif::git-pull[]
216216
--server-option=<option>::
217217
Transmit the given string to the server when communicating using
218218
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.
220221
When multiple `--server-option=<option>` are given, they are all
221222
sent to the other side in the order listed on the command line.
222223

Documentation/git-clone.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ objects from the source repository into a pack in the cloned repository.
131131
is specified. This flag forces progress status even if the
132132
standard error stream is not directed to a terminal.
133133

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+
134142
--no-checkout::
135143
-n::
136144
No checkout of HEAD is performed after the clone is complete.

builtin/clone.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static int option_dissociate;
6666
static int max_jobs = -1;
6767
static struct string_list option_recurse_submodules = STRING_LIST_INIT_NODUP;
6868
static struct list_objects_filter_options filter_options;
69+
static struct string_list server_options = STRING_LIST_INIT_NODUP;
6970

7071
static int recurse_submodules_cb(const struct option *opt,
7172
const char *arg, int unset)
@@ -137,6 +138,8 @@ static struct option builtin_clone_options[] = {
137138
N_("separate git dir from working tree")),
138139
OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
139140
N_("set config inside the new repository")),
141+
OPT_STRING_LIST(0, "server-option", &server_options,
142+
N_("server-specific"), N_("option to transmit")),
140143
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
141144
TRANSPORT_FAMILY_IPV4),
142145
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)
11361139
transport_set_option(transport, TRANS_OPT_UPLOADPACK,
11371140
option_upload_pack);
11381141

1142+
if (server_options.nr)
1143+
transport->server_options = &server_options;
1144+
11391145
if (filter_options.choice) {
11401146
struct strbuf expanded_filter_spec = STRBUF_INIT;
11411147
expand_list_objects_filter_spec(&filter_options,

t/t5702-protocol-v2.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,28 @@ test_expect_success 'warn if using server-option with fetch with legacy protocol
270270
test_i18ngrep "server options require protocol version 2 or later" err
271271
'
272272

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+
273295
test_expect_success 'upload-pack respects config using protocol v2' '
274296
git init server &&
275297
write_script server/.git/hook <<-\EOF &&

0 commit comments

Comments
 (0)