remote-curl: allow push options

Teach remote-curl to understand push options and to be able to convey them across HTTP. Signed-off-by: Brandon Williams <bmwill@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Mar 22, 2017 at 15:22 UTC 511155db51ff9870d2b3fd74c6dfdd558b5fa37b
4 files changed +50 -2
Documentation/git-send-pack.txt
+6
@@ -81,6 +81,12 @@ be in a separate packet, and the list must end with a flush packet.
81 will also fail if the actual call to `gpg --sign` fails. See
82 linkgit:git-receive-pack[1] for the details on the receiving end.
83
84 +--push-option=<string>::
85 + Pass the specified string as a push option for consumption by
86 + hooks on the server side. If the server doesn't support push
87 + options, error out. See linkgit:git-push[1] and
88 + linkgit:githooks[5] for details.
89 +
90 <host>::
91 A remote host to house the repository. When this
92 part is specified, 'git-receive-pack' is invoked via
builtin/send-pack.c
+5
@@ -144,6 +144,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
144 unsigned force_update = 0;
145 unsigned quiet = 0;
146 int push_cert = 0;
147 + struct string_list push_options = STRING_LIST_INIT_NODUP;
148 unsigned use_thin_pack = 0;
149 unsigned atomic = 0;
150 unsigned stateless_rpc = 0;
@@ -165,6 +166,9 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
166 { OPTION_CALLBACK,
167 0, "signed", &push_cert, "yes|no|if-asked", N_("GPG sign the push"),
168 PARSE_OPT_OPTARG, option_parse_push_signed },
169 + OPT_STRING_LIST(0, "push-option", &push_options,
170 + N_("server-specific"),
171 + N_("option to transmit")),
172 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
173 OPT_BOOL(0, "thin", &use_thin_pack, N_("use thin pack")),
174 OPT_BOOL(0, "atomic", &atomic, N_("request atomic transaction on remote side")),
@@ -199,6 +203,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
203 args.use_thin_pack = use_thin_pack;
204 args.atomic = atomic;
205 args.stateless_rpc = stateless_rpc;
206 + args.push_options = push_options.nr ? &push_options : NULL;
207
208 if (from_stdin) {
209 struct argv_array all_refspecs = ARGV_ARRAY_INIT;
remote-curl.c
+8
@@ -22,6 +22,7 @@ struct options {
22 unsigned long depth;
23 char *deepen_since;
24 struct string_list deepen_not;
25 + struct string_list push_options;
26 unsigned progress : 1,
27 check_self_contained_and_connected : 1,
28 cloning : 1,
@@ -139,6 +140,9 @@ static int set_option(const char *name, const char *value)
140 else
141 return -1;
142 return 0;
143 + } else if (!strcmp(name, "push-option")) {
144 + string_list_append(&options.push_options, value);
145 + return 0;
146
147 #if LIBCURL_VERSION_NUM >= 0x070a08
148 } else if (!strcmp(name, "family")) {
@@ -943,6 +947,9 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
947 argv_array_push(&args, "--quiet");
948 else if (options.verbosity > 1)
949 argv_array_push(&args, "--verbose");
950 + for (i = 0; i < options.push_options.nr; i++)
951 + argv_array_pushf(&args, "--push-option=%s",
952 + options.push_options.items[i].string);
953 argv_array_push(&args, options.progress ? "--progress" : "--no-progress");
954 for_each_string_list_item(cas_option, &cas_options)
955 argv_array_push(&args, cas_option->string);
@@ -1028,6 +1035,7 @@ int cmd_main(int argc, const char **argv)
1035 options.progress = !!isatty(2);
1036 options.thin = 1;
1037 string_list_init(&options.deepen_not, 1);
1038 + string_list_init(&options.push_options, 1);
1039
1040 remote = remote_get(argv[1]);
1041
t/t5545-push-options.sh
+31 -2
@@ -102,17 +102,46 @@ test_expect_success 'two push options work' '
102 test_cmp expect upstream/.git/hooks/post-receive.push_options
103 '
104
105 -test_expect_success 'push option denied properly by http remote helper' '\
105 +test_expect_success 'push option denied properly by http server' '
106 + test_when_finished "rm -rf test_http_clone" &&
107 + test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
108 mk_repo_pair &&
109 git -C upstream config receive.advertisePushOptions false &&
110 git -C upstream config http.receivepack true &&
111 cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
112 git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
113 test_commit -C test_http_clone one &&
112 - test_must_fail git -C test_http_clone push --push-option=asdf origin master &&
114 + test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
115 + test_i18ngrep "the receiving end does not support push options" actual &&
116 git -C test_http_clone push origin master
117 '
118
119 +test_expect_success 'push options work properly across http' '
120 + test_when_finished "rm -rf test_http_clone" &&
121 + test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
122 + mk_repo_pair &&
123 + git -C upstream config receive.advertisePushOptions true &&
124 + git -C upstream config http.receivepack true &&
125 + cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
126 + git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
127 +
128 + test_commit -C test_http_clone one &&
129 + git -C test_http_clone push origin master &&
130 + git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
131 + git -C test_http_clone rev-parse --verify master >actual &&
132 + test_cmp expect actual &&
133 +
134 + test_commit -C test_http_clone two &&
135 + git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin master &&
136 + printf "asdf\nmore structured text\n" >expect &&
137 + test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
138 + test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
139 +
140 + git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
141 + git -C test_http_clone rev-parse --verify master >actual &&
142 + test_cmp expect actual
143 +'
144 +
145 stop_httpd
146
147 test_done