push options: pass push options to the transport helper

When using non-builtin protocols relying on a transport helper (such as http), push options are not propagated to the helper. The user could ask for push options and a push would seemingly succeed, but the push options would never be transported to the server, misleading the users expectation. Fix this by propagating the push options to the transport helper. This is only addressing the first issue of (1) the helper protocol does not propagate push-option (2) the http helper is not prepared to handle push-option Once we fix (2), the http transport helper can make use of push options as well, but that happens as a follow up. (1) is a bug fix, whereas (2) is a feature, which is why we only do (1) here. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Feb 8, 2017 at 14:04 UTC 438fc68462d5839ef6ca231cdcb411105eaf0ba2
3 files changed +26
Documentation/gitremote-helpers.txt
+4
@@ -462,6 +462,10 @@ set by Git if the remote helper has the 'option' capability.
462 'option pushcert {'true'|'false'}::
463 GPG sign pushes.
464
465 +'option push-option <string>::
466 + Transmit <string> as a push option. As the a push option
467 + must not contain LF or NUL characters, the string is not encoded.
468 +
469 SEE ALSO
470 --------
471 linkgit:git-remote[1]
t/t5545-push-options.sh
+15
@@ -3,6 +3,8 @@
3 test_description='pushing to a repository using push options'
4
5 . ./test-lib.sh
6 +. "$TEST_DIRECTORY"/lib-httpd.sh
7 +start_httpd
8
9 mk_repo_pair () {
10 rm -rf workbench upstream &&
@@ -100,4 +102,17 @@ 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' '\
106 + mk_repo_pair &&
107 + git -C upstream config receive.advertisePushOptions false &&
108 + git -C upstream config http.receivepack true &&
109 + cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
110 + git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
111 + test_commit -C test_http_clone one &&
112 + test_must_fail git -C test_http_clone push --push-option=asdf origin master &&
113 + git -C test_http_clone push origin master
114 +'
115 +
116 +stop_httpd
117 +
118 test_done
transport-helper.c
+7
@@ -826,6 +826,13 @@ static void set_common_push_options(struct transport *transport,
826 if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "if-asked") != 0)
827 die("helper %s does not support --signed=if-asked", name);
828 }
829 +
830 + if (flags & TRANSPORT_PUSH_OPTIONS) {
831 + struct string_list_item *item;
832 + for_each_string_list_item(item, transport->push_options)
833 + if (set_helper_option(transport, "push-option", item->string) != 0)
834 + die("helper %s does not support 'push-option'", name);
835 + }
836 }
837
838 static int push_refs_with_push(struct transport *transport,