summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-03-27 10:59:27 -0700
committerJunio C Hamano <gitster@pobox.com>2017-03-27 10:59:27 -0700
commit4e87565d2a3e315b7afc39e9e1fe98c5607a1b11 (patch)
tree6f268f4c98d8c9a06536a5a2fbea5ee9a7df83fc
parent4a2b50a1e3667ee40bf08726fb249b634e9df1b6 (diff)
parent511155db51ff9870d2b3fd74c6dfdd558b5fa37b (diff)
downloadgit-4e87565d2a3e315b7afc39e9e1fe98c5607a1b11.tar.gz
Merge branch 'sb/push-options-via-transport'
Recently we started passing the "--push-options" through the external remote helper interface; now the "smart HTTP" remote helper understands what to do with the passed information. * sb/push-options-via-transport: remote-curl: allow push options send-pack: send push options correctly in stateless-rpc case
-rw-r--r--Documentation/git-send-pack.txt6
-rw-r--r--builtin/send-pack.c5
-rw-r--r--remote-curl.c8
-rw-r--r--send-pack.c20
-rwxr-xr-xt/t5545-push-options.sh33
5 files changed, 58 insertions, 14 deletions
diff --git a/Documentation/git-send-pack.txt b/Documentation/git-send-pack.txt
index a831dd0288..966abb0df8 100644
--- a/Documentation/git-send-pack.txt
+++ b/Documentation/git-send-pack.txt
@@ -81,6 +81,12 @@ be in a separate packet, and the list must end with a flush packet.
will also fail if the actual call to `gpg --sign` fails. See
linkgit:git-receive-pack[1] for the details on the receiving end.
+--push-option=<string>::
+ Pass the specified string as a push option for consumption by
+ hooks on the server side. If the server doesn't support push
+ options, error out. See linkgit:git-push[1] and
+ linkgit:githooks[5] for details.
+
<host>::
A remote host to house the repository. When this
part is specified, 'git-receive-pack' is invoked via
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index 1ff5a67538..832fd7ed0a 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -144,6 +144,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
unsigned force_update = 0;
unsigned quiet = 0;
int push_cert = 0;
+ struct string_list push_options = STRING_LIST_INIT_NODUP;
unsigned use_thin_pack = 0;
unsigned atomic = 0;
unsigned stateless_rpc = 0;
@@ -165,6 +166,9 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
{ OPTION_CALLBACK,
0, "signed", &push_cert, "yes|no|if-asked", N_("GPG sign the push"),
PARSE_OPT_OPTARG, option_parse_push_signed },
+ OPT_STRING_LIST(0, "push-option", &push_options,
+ N_("server-specific"),
+ N_("option to transmit")),
OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
OPT_BOOL(0, "thin", &use_thin_pack, N_("use thin pack")),
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)
args.use_thin_pack = use_thin_pack;
args.atomic = atomic;
args.stateless_rpc = stateless_rpc;
+ args.push_options = push_options.nr ? &push_options : NULL;
if (from_stdin) {
struct argv_array all_refspecs = ARGV_ARRAY_INIT;
diff --git a/remote-curl.c b/remote-curl.c
index 34a97e7328..e953d06f66 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -22,6 +22,7 @@ struct options {
unsigned long depth;
char *deepen_since;
struct string_list deepen_not;
+ struct string_list push_options;
unsigned progress : 1,
check_self_contained_and_connected : 1,
cloning : 1,
@@ -139,6 +140,9 @@ static int set_option(const char *name, const char *value)
else
return -1;
return 0;
+ } else if (!strcmp(name, "push-option")) {
+ string_list_append(&options.push_options, value);
+ return 0;
#if LIBCURL_VERSION_NUM >= 0x070a08
} else if (!strcmp(name, "family")) {
@@ -943,6 +947,9 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
argv_array_push(&args, "--quiet");
else if (options.verbosity > 1)
argv_array_push(&args, "--verbose");
+ for (i = 0; i < options.push_options.nr; i++)
+ argv_array_pushf(&args, "--push-option=%s",
+ options.push_options.items[i].string);
argv_array_push(&args, options.progress ? "--progress" : "--no-progress");
for_each_string_list_item(cas_option, &cas_options)
argv_array_push(&args, cas_option->string);
@@ -1028,6 +1035,7 @@ int cmd_main(int argc, const char **argv)
options.progress = !!isatty(2);
options.thin = 1;
string_list_init(&options.deepen_not, 1);
+ string_list_init(&options.push_options, 1);
remote = remote_get(argv[1]);
diff --git a/send-pack.c b/send-pack.c
index d2d2a49a02..66e652f7ef 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -532,6 +532,14 @@ int send_pack(struct send_pack_args *args,
}
}
+ if (use_push_options) {
+ struct string_list_item *item;
+
+ packet_buf_flush(&req_buf);
+ for_each_string_list_item(item, args->push_options)
+ packet_buf_write(&req_buf, "%s", item->string);
+ }
+
if (args->stateless_rpc) {
if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
packet_buf_flush(&req_buf);
@@ -544,18 +552,6 @@ int send_pack(struct send_pack_args *args,
strbuf_release(&req_buf);
strbuf_release(&cap_buf);
- if (use_push_options) {
- struct string_list_item *item;
- struct strbuf sb = STRBUF_INIT;
-
- for_each_string_list_item(item, args->push_options)
- packet_buf_write(&sb, "%s", item->string);
-
- write_or_die(out, sb.buf, sb.len);
- packet_flush(out);
- strbuf_release(&sb);
- }
-
if (use_sideband && cmds_sent) {
memset(&demux, 0, sizeof(demux));
demux.proc = sideband_demux;
diff --git a/t/t5545-push-options.sh b/t/t5545-push-options.sh
index 9a57a7d8f2..97065e62b8 100755
--- a/t/t5545-push-options.sh
+++ b/t/t5545-push-options.sh
@@ -102,17 +102,46 @@ test_expect_success 'two push options work' '
test_cmp expect upstream/.git/hooks/post-receive.push_options
'
-test_expect_success 'push option denied properly by http remote helper' '\
+test_expect_success 'push option denied properly by http server' '
+ 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 false &&
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 &&
test_commit -C test_http_clone one &&
- test_must_fail git -C test_http_clone push --push-option=asdf origin master &&
+ 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 &&
git -C test_http_clone push origin master
'
+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 &&
+
+ test_commit -C test_http_clone one &&
+ git -C test_http_clone push origin master &&
+ git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
+ git -C test_http_clone rev-parse --verify master >actual &&
+ test_cmp expect actual &&
+
+ test_commit -C test_http_clone two &&
+ git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin master &&
+ printf "asdf\nmore structured text\n" >expect &&
+ test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
+ test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
+
+ git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
+ git -C test_http_clone rev-parse --verify master >actual &&
+ test_cmp expect actual
+'
+
stop_httpd
test_done