Skip to content

Commit 438fc68

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e3a7b3 commit 438fc68

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Documentation/gitremote-helpers.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ set by Git if the remote helper has the 'option' capability.
462462
'option pushcert {'true'|'false'}::
463463
GPG sign pushes.
464464

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+
465469
SEE ALSO
466470
--------
467471
linkgit:git-remote[1]

t/t5545-push-options.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
test_description='pushing to a repository using push options'
44

55
. ./test-lib.sh
6+
. "$TEST_DIRECTORY"/lib-httpd.sh
7+
start_httpd
68

79
mk_repo_pair () {
810
rm -rf workbench upstream &&
@@ -100,4 +102,17 @@ test_expect_success 'two push options work' '
100102
test_cmp expect upstream/.git/hooks/post-receive.push_options
101103
'
102104

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+
103118
test_done

transport-helper.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,13 @@ static void set_common_push_options(struct transport *transport,
826826
if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "if-asked") != 0)
827827
die("helper %s does not support --signed=if-asked", name);
828828
}
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+
}
829836
}
830837

831838
static int push_refs_with_push(struct transport *transport,

0 commit comments

Comments
 (0)