Skip to content

Commit 69917e6

Browse files
committed
Merge branch 'jk/push-options-via-transport-fix'
"git push" over http transport did not unquote the push-options correctly. * jk/push-options-via-transport-fix: remote-curl: unquote incoming push-options t5545: factor out http repository setup
2 parents 0996727 + 90dce21 commit 69917e6

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

remote-curl.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "credential.h"
1414
#include "sha1-array.h"
1515
#include "send-pack.h"
16+
#include "quote.h"
1617

1718
static struct remote *remote;
1819
/* always ends with a trailing slash */
@@ -145,7 +146,15 @@ static int set_option(const char *name, const char *value)
145146
return -1;
146147
return 0;
147148
} else if (!strcmp(name, "push-option")) {
148-
string_list_append(&options.push_options, value);
149+
if (*value != '"')
150+
string_list_append(&options.push_options, value);
151+
else {
152+
struct strbuf unquoted = STRBUF_INIT;
153+
if (unquote_c_style(&unquoted, value, NULL) < 0)
154+
die("invalid quoting in push-option value");
155+
string_list_append_nodup(&options.push_options,
156+
strbuf_detach(&unquoted, NULL));
157+
}
149158
return 0;
150159

151160
#if LIBCURL_VERSION_NUM >= 0x070a08

t/t5545-push-options.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,31 +217,40 @@ test_expect_success 'invalid push option in config' '
217217
test_refs master HEAD@{1}
218218
'
219219

220+
test_expect_success 'push options keep quoted characters intact (direct)' '
221+
mk_repo_pair &&
222+
git -C upstream config receive.advertisePushOptions true &&
223+
test_commit -C workbench one &&
224+
git -C workbench push --push-option="\"embedded quotes\"" up master &&
225+
echo "\"embedded quotes\"" >expect &&
226+
test_cmp expect upstream/.git/hooks/pre-receive.push_options
227+
'
228+
220229
. "$TEST_DIRECTORY"/lib-httpd.sh
221230
start_httpd
222231

223-
test_expect_success 'push option denied properly by http server' '
232+
# set up http repository for fetching/pushing, with push options config
233+
# bool set to $1
234+
mk_http_pair () {
224235
test_when_finished "rm -rf test_http_clone" &&
225-
test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
236+
test_when_finished 'rm -rf "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git' &&
226237
mk_repo_pair &&
227-
git -C upstream config receive.advertisePushOptions false &&
238+
git -C upstream config receive.advertisePushOptions "$1" &&
228239
git -C upstream config http.receivepack true &&
229240
cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
230-
git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
241+
git clone "$HTTPD_URL"/smart/upstream test_http_clone
242+
}
243+
244+
test_expect_success 'push option denied properly by http server' '
245+
mk_http_pair false &&
231246
test_commit -C test_http_clone one &&
232247
test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
233248
test_i18ngrep "the receiving end does not support push options" actual &&
234249
git -C test_http_clone push origin master
235250
'
236251

237252
test_expect_success 'push options work properly across http' '
238-
test_when_finished "rm -rf test_http_clone" &&
239-
test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
240-
mk_repo_pair &&
241-
git -C upstream config receive.advertisePushOptions true &&
242-
git -C upstream config http.receivepack true &&
243-
cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
244-
git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
253+
mk_http_pair true &&
245254
246255
test_commit -C test_http_clone one &&
247256
git -C test_http_clone push origin master &&
@@ -260,6 +269,15 @@ test_expect_success 'push options work properly across http' '
260269
test_cmp expect actual
261270
'
262271

272+
test_expect_success 'push options keep quoted characters intact (http)' '
273+
mk_http_pair true &&
274+
275+
test_commit -C test_http_clone one &&
276+
git -C test_http_clone push --push-option="\"embedded quotes\"" origin master &&
277+
echo "\"embedded quotes\"" >expect &&
278+
test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options
279+
'
280+
263281
stop_httpd
264282

265283
test_done

0 commit comments

Comments
 (0)