1
0
mirror of https://github.com/git/git.git synced 2024-11-05 22:19:47 +01:00

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
This commit is contained in:
Junio C Hamano 2018-02-28 13:37:58 -08:00
commit 69917e6439
2 changed files with 39 additions and 12 deletions

@ -13,6 +13,7 @@
#include "credential.h"
#include "sha1-array.h"
#include "send-pack.h"
#include "quote.h"
static struct remote *remote;
/* always ends with a trailing slash */
@ -145,7 +146,15 @@ static int set_option(const char *name, const char *value)
return -1;
return 0;
} else if (!strcmp(name, "push-option")) {
if (*value != '"')
string_list_append(&options.push_options, value);
else {
struct strbuf unquoted = STRBUF_INIT;
if (unquote_c_style(&unquoted, value, NULL) < 0)
die("invalid quoting in push-option value");
string_list_append_nodup(&options.push_options,
strbuf_detach(&unquoted, NULL));
}
return 0;
#if LIBCURL_VERSION_NUM >= 0x070a08

@ -217,17 +217,32 @@ test_expect_success 'invalid push option in config' '
test_refs master HEAD@{1}
'
test_expect_success 'push options keep quoted characters intact (direct)' '
mk_repo_pair &&
git -C upstream config receive.advertisePushOptions true &&
test_commit -C workbench one &&
git -C workbench push --push-option="\"embedded quotes\"" up master &&
echo "\"embedded quotes\"" >expect &&
test_cmp expect upstream/.git/hooks/pre-receive.push_options
'
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
test_expect_success 'push option denied properly by http server' '
# set up http repository for fetching/pushing, with push options config
# bool set to $1
mk_http_pair () {
test_when_finished "rm -rf test_http_clone" &&
test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
test_when_finished 'rm -rf "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git' &&
mk_repo_pair &&
git -C upstream config receive.advertisePushOptions false &&
git -C upstream config receive.advertisePushOptions "$1" &&
git -C upstream config http.receivepack true &&
cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
git clone "$HTTPD_URL"/smart/upstream test_http_clone
}
test_expect_success 'push option denied properly by http server' '
mk_http_pair false &&
test_commit -C test_http_clone one &&
test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
test_i18ngrep "the receiving end does not support push options" actual &&
@ -235,13 +250,7 @@ test_expect_success 'push option denied properly by http server' '
'
test_expect_success 'push options work properly across http' '
test_when_finished "rm -rf test_http_clone" &&
test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
mk_repo_pair &&
git -C upstream config receive.advertisePushOptions true &&
git -C upstream config http.receivepack true &&
cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
mk_http_pair true &&
test_commit -C test_http_clone one &&
git -C test_http_clone push origin master &&
@ -260,6 +269,15 @@ test_expect_success 'push options work properly across http' '
test_cmp expect actual
'
test_expect_success 'push options keep quoted characters intact (http)' '
mk_http_pair true &&
test_commit -C test_http_clone one &&
git -C test_http_clone push --push-option="\"embedded quotes\"" origin master &&
echo "\"embedded quotes\"" >expect &&
test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options
'
stop_httpd
test_done