New execute-commands hook for centralized workflow
Subsystems (2)
Re: [PATCH v10 2/8] receive-pack: add new proc-receive hook
In reply to Junio C HamanoQuoted 15 lines · Junio C Hamano <[email protected]> 于2020年4月13日周一 上午5:30写道:
Quoted 8 lines · Jiang Xin
# Receive result from the hook.
# OK, run this command successfully.
H: PKT-LINE(<old-oid> <new-oid> <ref> ok)
# NO, I reject it.
H: PKT-LINE(<old-oid> <new-oid> <ref> ng <reason>)
# Fall through, let 'receive-pack' to execute it.
H: PKT-LINE(<old-oid> <new-oid> <ref> ft)
# OK, but has an alternate reference. The alternate reference nameQuoted 4 lines
# and other status are given in key=value pairs after the null # character. H: PKT-LINE(<old-oid> <new-oid> <ref> ok\0ref=refs/pull/123/head forced-update)
Quoted 7 lines
The semantics of this one is fuzzy. We made an update to a ref that is different from the one that was requested (presumably that is what is reported after "\0ref="), OK, but did we update the ref in the request, too, or did we leave the ref in the request intact? Or, do we say "no\0ref=..." if we don't update the requested ref and instead update a different one? Let's hold the answer at this point and keep thinking...
Before making a decision, we must consider some limitations or backward compatibility issues. See the limitations from following code snippet of "send-pack.c" and "transport.c":
* "receive-pack" should not send status other than "ok" and "ng" to "send-pack". We must keep this for backward compatibility.
# File: send-pack.c
#
152 static int receive_status(struct packet_reader *reader, struct ref *refs) 153 {
159 while (1) {
160 const char *refname;
161 char *msg;
162 if (packet_reader_read(reader) != PACKET_READ_NORMAL)
163 break;
164 if (!starts_with(reader->line, "ok ") && !starts_with(reader->line, "ng ")) { 165 error("invalid ref status from remote: %s", reader->line); 166 ret = -1;
167 break;
168 }
* Do not report unknown reference to "send-pack". Each returned reference must be included in remote_refs.
175 /* first try searching at our hint, falling back to all refs */ 176 if (hint)
177 hint = find_ref_by_name(hint, refname);
178 if (!hint)
179 hint = find_ref_by_name(refs, refname);
180 Â if (!hint) {
181 warning("remote reported status on unknown ref: %s", 182 refname);
* Do not report unexpected reference to "send-pack".
185 if (hint->status != REF_STATUS_EXPECTING_REPORT) { 186 warning("remote reported status on unexpected ref: %s", 187 refname);
188 continue;
189 }
* Client will complain if a expecting command not is not received from the report.
# File: transport.c
#
531 static int print_one_push_status(struct ref *ref, const char *dest, int count, 532 int porcelain, int summary_width) 540 switch(ref->status) {
584 case REF_STATUS_EXPECTING_REPORT:
585 print_ref_status('!', "[remote failure]", ref,
586 ref->deletion ? NULL : ref->peer_ref, 587 "remote failed to report status",
588 porcelain, summary_width);
So we should not invent new status between "receive-pack" and "send-pack". It is reasonable to to extend the report function from 'receive-pack' to 'send-pack' (not the report from 'proc-receive' to 'receive-pack') by adding a null character and multiple key-value pairs as extended status after the "ok" and "ng" message.
For example, the following git-push command:
git push origin HEAD:refs/for/master/topic
The refspec points to a pseudo reference "refs/for/master/topic", which does not exist on the server, so the old-oid of the command to "receive-pack" must be a zero-oid. The command for 'proc-receive' is:
<zero-oid> <new-oid> refs/for/master/topic
If "proc-receive" find this git-push command is associated with an already exist pull request (such as "refs/pull/123/head"), it will update this reference instead of creating a new one.
For this case, we can extend the report line (from "receive-pack" to "send-pack”) like this:
ok refs/for/master/topic\0ref=refs/pull/123/head old-oid=<hash> [forced-push]
This extended report line is backward compatible. Old version of git client will show message like this:
To upstream.git
* [new branch] HEAD -> refs/for/master/topic
New version of git has the knowledge of how to handle the extended-status after the null character, will print the following message:
To upstream.git
+ 1234567...7654321 HEAD -> refs/pull/124/head (forced update)
Actually, both 'ok' and 'ng' status have the knowledge of '<msg>', even though the '<msg>' is ignored by the 'ok' status. After the extension, both of them can take key-value pairs as extended-status, like:
ok <reference> [msg]\0key=value ...
ng <reference> [msg]\0key=value ...We can use '<msg>' and the extended status to fit our needs in the future.
As for the design of status report from 'proc-receive' to 'receive-pack', we should follow the same rules:
1. Never report status for non-exists commands.
2. Do not forget to report some of the commands.
3. After receive report for commands from 'proc-receive', we should have enough information to generate report to 'send-pack' from these commands.
For the above example, when user push to 'refs/for/master/topic', 'proc-receive' may report to 'receive-pack' like this:
PKT-LINE(<old-oid> <new-oid> <ref> ok\0ref=refs/pull/123/head forced-update)
'send-pack' will save the key-value pairs into the cooresponding ref->remote_status. If the report line has a different '<old-oid>' or '<new-oid>' for the '<ref>', 'send-pack' will substitude the oids of the ref, and append new key-value pairs (old-oid=<hash> and new-oid=<hash>) to ref->remote_status.
Quoted 43 lines
Quoted 10 lines
H: ... ...
H: flush-pktAfter receiving a command, the hook will execute the command, and may create/update different reference. For example, a command for a pseudo reference "refs/for/master/topic" may create/update different reference such as "refs/pull/123/head". The alternate reference name and other status are given in key-value pairs as extended status of the report line.
Quoted 5 lines
The list of commands returned from "proc-receive" will replace the relevant commands that are sent from user to "receive-pack", and "receive-pack" will continue to run the "
execute_commands" function and other routines. Finally, the result of the execution of these commands will be reported to end user.It is not clear if there needs to be any correspondence between the sequence of input commands and the sequence of output commands. I am guessing that there is not any and the hook is allowed to do anything as it wants to. For example:
- it is OK to execute them all and report them, but in a totally random order.
- it is OK to ignore all input and report no update (not even "ng").
- it is OK to be asked to update one ref, but update and report updates to two refs that are not related to the requested ref.
Is my understanding correct?
Or does the design tie the set of input and output ref updates closely together, i.e. one input corresponds to one output and they are in order, so all the hook is allowed to do is
- to execute and update as it is told, and report "ok",
- to reject and report "ng", or
- to update *another* ref without updating the requested one, with "ok\0ref=..." mechanism.
Quoted 6 lines
I am not sure which one is more sensible, though.
If we choose to use the "anything goes" approach, I do not think there is no need for the "ok\nref=..." mechanism---we can just give two output records, one "ok" for the original request, and a new "ok" that reports the "we updated this one instead".
I saw you have noticed the code for replacing the commands of 'receive-pack' by comparing ref name.
Quoted 10 lines
Quoted 5 lines
+ } else if (
strcmp("ok", status)) {
+ strbuf_addf(errmsg, "proc-receive has bad status '%s' for '%s'\n",
+ status,reader->line);
+ code = -1;
+ /* Skip marking it asRUN_PROC_RECEIVE_RETURNED*/But then shouldn't we be complaining if msg is not NULL here, instead of silently ignoring? Also we didn't see what happened to the promised "ok\0ref=..." stuff here, or the passthru "ft". Puzzled...
I implement "ft" and "\0key=value..." features in patch 6/8, and it depends another refactoring commit. I can squash it to this commit in next reroll, and rearrange the refactoring commmit and test cases.
Quoted 9 lines
Quoted 5 lines
+ continue;
+ }
+oidcpy(&hint->old_oid, &old_oid);
+oidcpy(&hint->new_oid, &new_oid);
+hint->run_proc_receive|=RUN_PROC_RECEIVE_RETURNED;Or, is this last one the catch all for "ft" (in other words, the hook does not have to say "ft", but as long as it says two non-SP letters that are not "ok" nor "ng", it is taken as "ft")?
"ft" is implemented in patch 6/8. This code is used to help to find missing reported references.
Quoted 15 lines
builtin/receive-pack.c static int run_update_hook(struct command *cmd) · line 920
Quoted 12 lines
+ }
builtin/receive-pack.c +10
-0+ + for (cmd = commands; cmd; cmd = cmd->next) + if (cmd->run_proc_receive && !cmd->error_string && + !(cmd->run_proc_receive & RUN_PROC_RECEIVE_RETURNED)) { + cmd->error_string = "no report from proc-receive"; + code = -1; + } + + return code; +}OK, so this sort-of answers my earlier question. But not quite...
Quoted 6 lines
The output records and the input requests are tied by "<ref>" each input record wanted to udpate. The order does not matter, but not having a corresponding report in the hook's output is like the hook reporting a "ng" failure. It also means that the hook can update two refs in response to one request, but it is awkward.
Right sort order of the output commnands has better performace. The hook can only update commands marked with 'run_proc_receive'.
"update two refs", do you mean duplicate report line from 'proc-receive'? If 'proc-receive' really want to update several references for one command, it must report all of the updates in one report line by adding message, or adding additional key-value pairs.
Quoted 27 lines
Quoted 16 lines
builtin/receive-pack.c +16
-0+static int run_proc_receive_hook (struct command *commands, + const struct string_list *push_options) +{ + struct child_process proc = CHILD_PROCESS_INIT; + struct async muxer; + struct command *cmd; + const char *argv[2]; + struct packet_reader reader; + struct strbuf cap = STRBUF_INIT; + struct strbuf errmsg = STRBUF_INIT; + int pr_use_push_options = 0; + int version = 0; + int code; + + argv[0] = find_hook("proc-receive"); + if (!argv[0]) {builtin/receive-pack.c static int run_update_hook(struct command *cmd) · line 947
Quoted 10 lines
builtin/receive-pack.c +10
-0+ rp_error("cannot find hook 'proc-receive'"); + return -1; + } + argv[1] = NULL; + + proc.argv = argv; + proc.in = -1; + proc.out = -1; + proc.trace2_hook_name = "proc-receive"; +
Quoted 7 lines
Isn't this a brand new protocol between receive-pack and a hook? I am puzzled why we want a choice between using and not using sideband. It's not like you are maintaining compatibility with ancient version of Git that talked with proc-receive hook but without sideband, because it did not know how to multiplex sideband communication. Shouldn't we just always assume that the sideband is available?
The sideband message stream (stderr of 'proc-receive') will be sent directly to the client. If the client is a very old version of git, is is still safe?
Quoted 6 lines
Or are we just letting the hook directly answer the push client and that is why this thing needs to know if we are using sideband between us and the client? I kind of expected that you'd keep the two communication channels on both sides isolated so that the side that talks with the hook does not need to know how we are talking with the client.
In test cases for 'proc-receive', I output some debug info on stderr of 'proc-receive' hook. If the client (very old version of git) does not support sideband, it's ok.
Quoted 28 lines
Quoted 28 lines
+ if (
use_sideband) {
+memset(&muxer, 0, sizeof(muxer));
+ muxer.proc =copy_to_sideband;
+ muxer.in = -1;
+ code =start_async(&muxer);
+ if (code)
+ return code;
+ proc.err = muxer.in;
+ } else {
+ proc.err = 0;
+ }builtin/receive-pack.c +14
-0+ + code = start_command(&proc); + if (code) { + if (use_sideband) + finish_async(&muxer); + return code; + } + + sigchain_push(SIGPIPE, SIG_IGN); + + /* Version negotiaton */ + packet_reader_init(&reader, proc.out, NULL, 0, + PACKET_READ_CHOMP_NEWLINE | + PACKET_READ_DIE_ON_ERR_PACKET);@@ -1497,6 +1731,20 @@ static void execute_commands(struct command *commands,
Quoted 5 lines
builtin/receive-pack.c static void execute_commands(struct command *commands, · line 1734
Quoted 3 lines
builtin/receive-pack.c +1
-0reject_updates_to_hidden(commands); + /* Try to find commands that have special prefix in their reference names,Style?
Will fix.
Quoted 3 lines
Quoted 3 lines
builtin/receive-pack.c +2
-0+* and mark them to run an external "proc-receive" hook later. +*/
Re: [PATCH v10 2/8] receive-pack: add new proc-receive hook
Quoted 7 lines · Jiang Xin
Before making a decision, we must consider some limitations or backward compatibility issues. See the limitations from following code snippet of "
send-pack.c" and "transport.c":
...
The sideband message stream (stderr of 'proc-receive') will be sent directly to the client. If the client is a very old version of git, is is still safe?
These made your assumptions clear to me, I think.
I was expecting that the protocol was purely between receive-pack and the hook and the communication back to the "push" side was done by receive-pack, AFTER receive-pack finished talking with the hook, reading and understanding what the hook did. And with that expectation, the protocol to the hook is free of "compatibility" concern and does not have to be constrained to "one report packet, which may have to carry multiple updates if the hook updates multiple refs in response to a single update request packet".
But if you are letting the hook talk directly to the "push" side, without "receive-pack" even snooping/understanding what is going on, sure, I can understand why you have to put such a limitation to the protocol to the hook or use/unuse of the side-band.
I actually think we would need some update (new capability, perhaps) to the protocol between "push" and "receive-pack" when we want to fully support things like "you tried to push commit A to 'refs/for/X'; 'refs/for/X' is not created nor updated, but instead 'refs/heads/X' has been updated to commit B, which got created using info in A". A partial support can be done by just pretending that the proposed update for 'refs/for/X' succeeded and nothing else happened, and that may be a perfectly usable initial version. But I would suspect that we eventually would want to be able to tell the "git push" a bit more, and at that point, we'd probably want new capabilities between "push" and "receive-pack".
I think we should retain fairly strict control over the vocabulary used by "receive-pack" to explain what happened on "the server side" to the client, to avoid fracturing the ecosystem. With "hook's output is sent pass-thru back to the client" design, you'd allow a proprietary proc-receive hook to express what it did in a way that only a matching proprietary variant of "git push" can understand, which I do not think is a good thing.
Thanks.
PATCH v12 1/7 transport: not report a non-head push as a branch
From: Jiang Xin <[email protected]>
When pushing a new reference (not a head or tag), report it as a new reference instead of a new branch.
--- t/t5411-proc-receive-hook.sh | 67 +++++++++++++++++++ t/t5411/common-functions.sh | 50 ++++++++++++++ t/t5411/common-test-cases.sh | 43 ++++++++++++ t/t5412-proc-receive-hook-http-protocol.sh | 78 ++++++++++++++++++++++ t/t5516-fetch-push.sh | 2 +- transport.c | 9 ++- 6 files changed, 245 insertions(+), 4 deletions(-) create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/common-test-cases.sh create mode 100755 t/t5412-proc-receive-hook-http-protocol.sh
t/t5411-proc-receive-hook.sh new file +67 -0
@@ -0,0 +1,67 @@ +#!/bin/sh +# +# Copyright (c) 2020 Jiang Xin +# + +test_description='Test proc-receive hook' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/t5411/common-functions.sh + +# Format the output of git-push, git-show-ref and other commands to make a +# user-friendly and stable text. In addition to the common format method, +# we also replace the URL of different protocol for the upstream repository +# with a fixed pattern. +make_user_friendly_and_stable_output () { + make_user_friendly_and_stable_output_common | + sed -e "s#To ../upstream.git#To <URL/of/upstream.git>#" +} + +# Refs of upstream : master(B) next(A) +# Refs of workbench: master(A) tags/v123 +test_expect_success "setup" ' + git init --bare upstream.git && + git init workbench && + create_commits_in workbench A B && + ( + cd workbench && + # Try to make a stable fixed width for abbreviated commit ID, + # this fixed-width oid will be replaced with "<OID>". + git config core.abbrev 7 && + git remote add origin ../upstream.git && + git update-ref refs/heads/master $A && + git tag -m "v123" v123 $A && + git push origin \ + $B:refs/heads/master \ + $A:refs/heads/next + ) && + TAG=$(git -C workbench rev-parse v123) && + + # setup pre-receive hook + write_script upstream.git/hooks/pre-receive <<-\EOF && + exec >&2 + echo "# pre-receive hook" + while read old new ref + do + echo "pre-receive< $old $new $ref" + done + EOF + + # setup post-receive hook + write_script upstream.git/hooks/post-receive <<-\EOF && + exec >&2 + echo "# post-receive hook" + while read old new ref + do + echo "post-receive< $old $new $ref" + done + EOF + + upstream=upstream.git +' + +# Include test cases for both file and HTTP protocol +. "$TEST_DIRECTORY"/t5411/common-test-cases.sh + +test_done
t/t5411/common-functions.sh new file +50 -0
50 lines not on this page · raw message
t/t5411/common-test-cases.sh new file +43 -0
43 lines not on this page · raw message
t/t5412-proc-receive-hook-http-protocol.sh new file +78 -0
78 lines not on this page · raw message
t/t5516-fetch-push.sh +1 -1
@@ -1039,7 +1039,7 @@ test_force_fetch_tag "annotated tag" "-f -a -m'tag message'" test_expect_success 'push --porcelain' ' mk_empty testrepo && echo >.git/foo "To testrepo" && - echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" && + echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new reference]" && echo >>.git/foo "Done" && git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && (
transport.c +6 -3
@@ -500,9 +500,12 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt porcelain, summary_width); else if (is_null_oid(&ref->old_oid))print_ref_status ('*' , - (starts_with (ref->name,"refs/tags/" ) ?"[new tag]" : -"[new branch]" ), - ref, ref->peer_ref,NULL , porcelain, summary_width); + (starts_with (ref->name,"refs/tags/" ) + ?"[new tag]" + : (starts_with (ref->name,"refs/heads/" ) + ?"[new branch]" + :"[new reference]" )), + ref, ref->peer_ref,NULL , porcelain, summary_width); else {struct strbuf quickref =STRBUF_INIT ;char type;
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
v12 cover New proc-receive hook for centralized workflow
In reply to Junio C HamanoFrom: Jiang Xin <[email protected]>
## Changes since v11
* Change the syntax of status report from "proc-receive" to "receive-pack".
# Receive result from the hook.
# OK, run this command successfully.
H: PKT-LINE(ok <ref>)
# NO, I reject it.
H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
H: PKT-LINE(ft <ref>)
# OK, but has an alternate reference. The alternate reference name # is given in the third parameter, and other status can be given in # key-value pairs.
H: PKT-LINE(alt <ref> <alt-ref> old-oid=<old-oid> new-oid=<new-oid>
forced-update)
H: ... ...
H: flush-pkt
* Support multiple responses from "proc-receive" for one reference. Add test case:
test_expect_success "setup proc-receive hook (multiple responses)" '
write_script "$upstream/hooks/proc-receive" <<-EOF
printf >&2 "# proc-receive hook\n"
test-tool proc-receive -v \
-r "alt refs/for/master/topic refs/changes/23/123/1" \
-r "alt refs/for/master/topic refs/changes/24/124/2 old-oid=$A new-oid=$B"
EOF
'
# Refs of upstream : master(A)
# Refs of workbench: master(A) tags/v123
# git push : refs/for/master/topic(A)
test_expect_success "proc-receive: report multiple response" '
git -C workbench push origin \
HEAD:refs/for/master/topic \
>out 2>&1 &&
make_user_friendly_and_stable_output <out >actual &&
cat >expect <<-EOF &&
remote: # pre-receive hook
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
remote: # proc-receive hook
remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
remote: proc-receive> alt refs/for/master/topic refs/changes/23/123/1
remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/2 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
To <URL/of/upstream.git>
* [new reference] HEAD -> refs/changes/23/123/1
<OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
EOF
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
make_user_friendly_and_stable_output <out >actual &&
cat >expect <<-EOF &&
<COMMIT-A> refs/heads/master
EOF
test_cmp expect actual
'
* "receive-pack" checks format of the report from "proc-receive", will discard unknown status.
* Apply the SQUASH??? commit.
## Range-diff v11..v12
1: bef4360e58 ! 1: b76900cb0f receive-pack: add new proc-receive hook
@@ Commit message
# Receive result from the hook.
# OK, run this command successfully.
- H: PKT-LINE(<old-oid> <new-oid> <ref> ok)
+ H: PKT-LINE(ok <ref>)
# NO, I reject it.
- H: PKT-LINE(<old-oid> <new-oid> <ref> ng <reason>)
+ H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
- H: PKT-LINE(<old-oid> <new-oid> <ref> ft)
+ H: PKT-LINE(ft <ref>)
# OK, but has an alternate reference. The alternate reference name
- # and other status are given in key=value pairs after the null
- # character.
- H: PKT-LINE(<old-oid> <new-oid> <ref> ok\0ref=refs/pull/123/head
+ # is given in the third parameter, and other status can be given in
+ # key-value pairs.
+ H: PKT-LINE(alt <ref> <alt-ref> old-oid=<old-oid> new-oid=<new-oid>
forced-update)
H: ... ...
H: flush-pkt
@@ Commit message
other routines. Finally, the result of the execution of these commands
will be reported to end user.
- The reporting function from "receive-pack" to "send-pack" is also
- extended using a backward compatible way by adding key-value pairs
- after an null character, like:
+ The reporting function from "receive-pack" to "send-pack" is extended
+ using a backward compatible way by adding key-value pairs after an null
+ character, like:
# OK, run this command successfully with optional extended-status.
ok <reference>\0ref=refs/pull/123/head old-oid=...
@@ Makefile: TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
TEST_BUILTINS_OBJS += test-read-cache.o
## builtin/receive-pack.c ##
+@@
+ #include "remote.h"
+ #include "connect.h"
+ #include "string-list.h"
++#include "string.h"
+ #include "sha1-array.h"
+ #include "connected.h"
+ #include "argv-array.h"
@@ builtin/receive-pack.c: static void write_head_info(void)
packet_flush(1);
}
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+
+ for (;;) {
+ struct object_id old_oid, new_oid;
-+ const char *refname;
-+ const char *p;
+ char *status;
-+ char *msg = NULL;
-+ int len;
++ char *refname;
++ char *remains = NULL;
+
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
+ break;
-+ len = strlen(reader->line);
-+ if (parse_oid_hex(reader->line, &old_oid, &p) ||
-+ *p++ != ' ' ||
-+ parse_oid_hex(p, &new_oid, &p) ||
-+ *p++ != ' ') {
-+ strbuf_addf(errmsg, "proc-receive expected 'old new ref status [msg]', got '%s'\n",
-+ reader->line);
-+ code = -1;
-+ continue;
++ status = (char *)reader->line;
++ refname = strchr(status, ' ');
++ if (refname) {
++ *refname++ = '\0';
++ remains = strchr(refname, ' ');
++ if (remains)
++ *remains++ = '\0';
+ }
-+
-+ refname = p;
-+ status = strchr(p, ' ');
-+ if (!status) {
-+ strbuf_addf(errmsg, "proc-receive expected 'old new ref status [msg]', got '%s'\n",
++ if (!refname || strlen(refname) == 0) {
++ strbuf_addf(errmsg, "proc-receive expected '<status> <ref> ...', got '%s'\n",
+ reader->line);
+ code = -1;
+ continue;
+ }
-+ *status++ = '\0';
-+ msg = strchr(status, ' ');
-+ if (msg)
-+ *msg++ = '\0';
+
+ /* first try searching at our hint, falling back to all refs */
+ if (hint)
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ continue;
+ }
+ if (!strcmp(status, "ng")) {
-+ if (msg)
-+ hint->error_string = xstrdup(msg);
++ if (remains)
++ hint->error_string = xstrdup(remains);
+ else
+ hint->error_string = "failed";
+ code = -1;
+ } else if (!strcmp("ft", status)) {
+ /* Reset "run_proc_receive" field, and continue to run in "receive-pack" */
+ hint->run_proc_receive = 0;
++ } else if (!strcmp("alt", status)) {
++ char *alt_ref;
++
++ alt_ref = remains;
++ remains = strchr(alt_ref, ' ');
++ if (remains)
++ *remains++ = '\0';
++
++ if (hint->extended_status)
++ strbuf_addstr(&extended_status, hint->extended_status);
++
++ strbuf_addf(&extended_status, "%sref=%s",
++ extended_status.len > 0 ? " ": "",
++ alt_ref);
++
++ if (remains) {
++ const char *val;
++ int len;
++
++ val = parse_feature_value(remains, "old-oid", &len);
++ if (val && len > 0)
++ if (!parse_oid_hex(val, &old_oid, &val))
++ strbuf_addf(&extended_status, "%sold-oid=%s",
++ extended_status.len > 0 ? " ": "",
++ oid_to_hex(&old_oid));
++
++ val = parse_feature_value(remains, "new-oid", &len);
++ if (val && len > 0)
++ if (!parse_oid_hex(val, &new_oid, &val))
++ strbuf_addf(&extended_status, "%snew-oid=%s",
++ extended_status.len > 0 ? " ": "",
++ oid_to_hex(&new_oid));
++
++ if (parse_feature_request(remains, "forced-update"))
++ strbuf_addf(&extended_status, "%sforced-update",
++ extended_status.len > 0 ? " ": "");
++ }
++
++ if (extended_status.len > 0) {
++ free((void *)hint->extended_status);
++ hint->extended_status = strbuf_detach(&extended_status, NULL);
++ }
+ } else if (strcmp("ok", status)) {
+ strbuf_addf(errmsg, "proc-receive reported bad status '%s' on ref '%s'\n",
+ status, refname);
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ /* Skip marking it as RUN_PROC_RECEIVE_RETURNED */
+ continue;
+ }
-+ if (reader->pktlen > len)
-+ strbuf_addstr(&extended_status, (char *)reader->line + len + 1);
-+ if (oidcmp(&hint->old_oid, &old_oid)) {
-+ oidcpy(&hint->old_oid, &old_oid);
-+ strbuf_addf(&extended_status, "%sold-oid=%s",
-+ extended_status.len > 0 ? " ": "",
-+ oid_to_hex(&old_oid));
-+ }
-+ if (oidcmp(&hint->new_oid, &new_oid)) {
-+ oidcpy(&hint->new_oid, &new_oid);
-+ strbuf_addf(&extended_status, "%snew-oid=%s",
-+ extended_status.len > 0 ? " ": "",
-+ oid_to_hex(&new_oid));
-+ }
-+ if (extended_status.len > 0)
-+ hint->extended_status = strbuf_detach(&extended_status, NULL);
++
+ if (hint->run_proc_receive)
+ hint->run_proc_receive |= RUN_PROC_RECEIVE_RETURNED;
+ }
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+
+'
+
-+test_expect_success "setup proc-receive hook (bad oid)" '
++test_expect_success "setup proc-receive hook (no ref)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "bad-id new-id ref ok"
++ -r "ok"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: bad protocol (bad oid)" '
++test_expect_success "proc-receive: bad protocol (no ref)" '
+ test_must_fail git -C workbench push origin \
+ HEAD:refs/for/master/topic\
+ >out 2>&1 &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> bad-id new-id ref ok
-+ remote: error: proc-receive expected "old new ref status [msg]", got "bad-id new-id ref ok"
-+ To <URL/of/upstream.git>
-+ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
-+ EOF
-+ test_cmp expect actual &&
-+ git -C "$upstream" show-ref >out &&
-+ make_user_friendly_and_stable_output <out >actual &&
-+ cat >expect <<-EOF &&
-+ <COMMIT-A> refs/heads/master
-+ EOF
-+ test_cmp expect actual
-+'
-+
-+test_expect_success "setup proc-receive hook (no status)" '
-+ write_script "$upstream/hooks/proc-receive" <<-EOF
-+ printf >&2 "# proc-receive hook\n"
-+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $A refs/for/master/topic"
-+ EOF
-+'
-+
-+# Refs of upstream : master(A)
-+# Refs of workbench: master(A) tags/v123
-+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: bad protocol (no status)" '
-+ test_must_fail git -C workbench push origin \
-+ HEAD:refs/for/master/topic \
-+ >out 2>&1 &&
-+ make_user_friendly_and_stable_output <out >actual &&
-+ cat >expect <<-EOF &&
-+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: error: proc-receive expected "old new ref status [msg]", got "<ZERO-OID> <COMMIT-A> refs/for/master/topic"
++ remote: proc-receive> ok
++ remote: error: proc-receive expected "<status> <ref> ...", got "ok"
+ To <URL/of/upstream.git>
+ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
+ EOF
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $A refs/for/master/topic xx msg"
++ -r "xx refs/for/master/topic"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/master/topic xx msg
++ remote: proc-receive> xx refs/for/master/topic
+ remote: error: proc-receive reported bad status "xx" on ref "refs/for/master/topic"
+ To <URL/of/upstream.git>
+ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $A refs/for/master/topic ng"
++ -r "ng refs/for/master/topic"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/master/topic ng
++ remote: proc-receive> ng refs/for/master/topic
+ To <URL/of/upstream.git>
+ ! [remote rejected] HEAD -> refs/for/master/topic (failed)
+ EOF
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $A refs/for/master/topic ng error msg"
++ -r "ng refs/for/master/topic error msg"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/master/topic ng error msg
++ remote: proc-receive> ng refs/for/master/topic error msg
+ To <URL/of/upstream.git>
+ ! [remote rejected] HEAD -> refs/for/master/topic (error msg)
+ EOF
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $A refs/heads/master ok"
++ -r "ok refs/heads/master"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/heads/master ok
++ remote: proc-receive> ok refs/heads/master
+ remote: error: proc-receive reported status on unexpected ref: refs/heads/master
+ remote: # post-receive hook
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $A refs/for/master/topic ok"
++ -r "ok refs/for/master/topic"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/master/topic ok
++ remote: proc-receive> ok refs/for/master/topic
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/master/topic ok
++ remote: proc-receive> ok refs/for/master/topic
+ remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
+ To <URL/of/upstream.git>
+ ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive< issue=123
+ remote: proc-receive< reviewer=user1
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/master/topic ok
++ remote: proc-receive> ok refs/for/master/topic
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $B refs/for/master/topic ft"
++ -r "ft refs/for/master/topic"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: pre-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-B> refs/for/master/topic ft
++ remote: proc-receive> ft refs/for/master/topic
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $A refs/for/a/b/c/topic ok" \
-+ -r "$ZERO_OID $A refs/for/next/topic ok\0ref=refs/pull/123/head" \
-+ -r "$B $A refs/for/master/topic ok\0ref=refs/pull/124/head forced-update"
++ -r "ok refs/for/a/b/c/topic" \
++ -r "alt refs/for/next/topic refs/pull/123/head" \
++ -r "alt refs/for/master/topic refs/pull/124/head old-oid=$B forced-update new-oid=$A"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic ok
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/next/topic ok\0ref=refs/pull/123/head
-+ remote: proc-receive> <COMMIT-B> <COMMIT-A> refs/for/master/topic ok\0ref=refs/pull/124/head forced-update
++ remote: proc-receive> ok refs/for/a/b/c/topic
++ remote: proc-receive> alt refs/for/next/topic refs/pull/123/head
++ remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-+ remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+ * [new reference] HEAD -> refs/for/next/topic
+ * [new reference] HEAD -> refs/for/a/b/c/topic
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ test_cmp expect actual
+'
+
++test_expect_success "setup proc-receive hook (multiple responses)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic refs/changes/23/123/1" \
++ -r "alt refs/for/master/topic refs/changes/24/124/2 old-oid=$A new-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: report multiple response" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/changes/23/123/1
++ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/2 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
+test_expect_success "setup proc-receive hook" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$ZERO_OID $A refs/for/next/topic ok" \
-+ -r "$A $B refs/for/master/topic ok"
++ -r "ok refs/for/next/topic" \
++ -r "alt refs/for/master/topic refs/for/master/topic old-oid=$A new-oid=$B"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/next/topic ok
-+ remote: proc-receive> <COMMIT-A> <COMMIT-B> refs/for/master/topic ok
++ remote: proc-receive> ok refs/for/next/topic
++ remote: proc-receive> alt refs/for/master/topic refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
-+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+ <OID-A>..<OID-B> <COMMIT-B> -> master
+ * [new branch] HEAD -> bar
2: a4a1cc1d14 ! 2: d20702291b send-pack: extension for client-side status report
@@ send-pack.c: static int receive_status(struct packet_reader *reader, struct ref
ret = -1;
}
- hint->remote_status = xstrdup_or_null(msg);
-+ if (msg) {
++ if (msg)
+ hint->remote_status = xstrdup(msg);
-+ } else if (extended_status) {
++ else if (extended_status)
+ hint->remote_status = xstrdup(extended_status);
-+ update_ref_from_remote_status(hint);
-+ }
/* start our next search from the next ref */
hint = hint->next;
}
@@ send-pack.c: static int receive_status(struct packet_reader *reader, struct ref
## t/t5411/common-test-cases.sh ##
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report with extended status" '
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
- remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
To <URL/of/upstream.git>
- * [new reference] HEAD -> refs/for/next/topic
+ * [new reference] HEAD -> refs/pull/123/head
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report with ext
EOF
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
+@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report multiple response" '
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * [new reference] HEAD -> refs/for/master/topic
++ * [new reference] HEAD -> refs/changes/23/123/1
++ <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update of mixed refs" '
* [new branch] HEAD -> baz
* [new reference] HEAD -> refs/for/next/topic
@@ transport-helper.c: static int push_update_ref_status(struct strbuf *buf,
}
}
-@@ transport-helper.c: static int push_update_ref_status(struct strbuf *buf,
- (*ref)->status = status;
- (*ref)->forced_update |= forced;
- (*ref)->remote_status = msg;
-+ if (status == REF_STATUS_OK && (*ref)->remote_status)
-+ update_ref_from_remote_status(*ref);
- return !(status == REF_STATUS_OK);
- }
-
## transport.c ##
@@ transport.c: static void print_ref_status(char flag, const char *summary,
struct ref *to, struct ref *from, const char *msg,
int porcelain, int summary_width)
{
-+ char *from_name = NULL;
+ char *to_name = NULL;
+ const char *val;
+ int len;
+
-+ if (from && from->remote_status) {
-+ val = parse_feature_value(from->remote_status, "ref", &len);
-+ if (val && len)
-+ from_name = xmemdupz(val, len);
-+ }
+ if (to && to->remote_status) {
+ val = parse_feature_value(to->remote_status, "ref", &len);
+ if (val && len)
-+ to_name = xmemdupz(val, len);
++ to_name = xmemdupz(val, len);
+ }
+
if (porcelain) {
if (from)
- fprintf(stdout, "%c\t%s:%s\t", flag, from->name, to->name);
-+ fprintf(stdout, "%c\t%s:%s\t", flag,
-+ from_name ? from_name : from->name,
-+ to_name ? to_name: to->name);
++ fprintf(stdout, "%c\t%s:%s\t", flag, from->name,
++ to_name ? to_name : to->name);
else
- fprintf(stdout, "%c\t:%s\t", flag, to->name);
+ fprintf(stdout, "%c\t:%s\t", flag,
-+ to_name ? to_name: to->name);
++ to_name ? to_name : to->name);
if (msg)
fprintf(stdout, "%s (%s)\n", summary, msg);
else
@@ transport.c: static void print_ref_status(char flag, const char *summary,
if (from)
- fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
+ fprintf(stderr, "%s -> %s",
-+ prettify_refname(from_name ? from_name : from->name),
++ prettify_refname(from->name),
+ prettify_refname(to_name ? to_name : to->name));
else
- fputs(prettify_refname(to->name), stderr);
@@ transport.c: static void print_ref_status(char flag, const char *summary,
}
fputc('\n', stderr);
}
-+ if (from_name)
-+ free(from_name);
-+ if (to_name)
-+ free(to_name);
++ free(to_name);
}
static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_width)
+@@ transport.c: static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt
+ }
+ }
+
+-static int print_one_push_status(struct ref *ref, const char *dest, int count,
+- int porcelain, int summary_width)
++static int _print_one_push_status(struct ref *ref, const char *dest, int count,
++ int porcelain, int summary_width)
+ {
+ if (!count) {
+ char *url = transport_anonymize_url(dest);
+@@ transport.c: static int print_one_push_status(struct ref *ref, const char *dest, int count,
+ return 1;
+ }
+
++static int print_one_push_status(struct ref *ref, const char *dest, int count,
++ int porcelain, int summary_width)
++{
++ char *head;
++ char *begin;
++ int n = 0;
++
++ if (!ref->remote_status)
++ return _print_one_push_status(ref, dest, count,
++ porcelain, summary_width);
++
++ head = ref->remote_status;
++ begin = strstr(head, "ref=");
++ if (!begin)
++ begin = ref->remote_status;
++ for (;;) {
++ char *end;
++ struct object_id old_oid;
++ struct object_id new_oid;
++ int forced_update;
++
++ end = strstr(begin + 4, "ref=");
++ if (end)
++ *(end-1) = '\0';
++
++ oidcpy(&old_oid, &ref->old_oid);
++ oidcpy(&new_oid, &ref->new_oid);
++ forced_update = ref->forced_update;
++
++ ref->remote_status = begin;
++ update_ref_from_remote_status(ref);
++ _print_one_push_status(ref, dest, count + n++,
++ porcelain, summary_width);
++
++ oidcpy(&ref->old_oid, &old_oid);
++ oidcpy(&ref->new_oid, &new_oid);
++ ref->forced_update = forced_update;
++
++ if (end) {
++ begin = end;
++ *(end-1) = ' ';
++ } else {
++ break;
++ }
++ }
++ ref->remote_status = head;
++ return n;
++}
++
+ static int measure_abbrev(const struct object_id *oid, int sofar)
+ {
+ char hex[GIT_MAX_HEXSZ + 1];
3: 4e3c383c12 = 3: a8860faa17 refs.c: refactor to reuse ref_is_hidden()
4: dd83569c4e ! 4: 46a839ddf6 receive-pack: new config receive.procReceiveRefs @@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
+ if (proc_receive_refs.nr > 0) {
+ struct strbuf refname_full = STRBUF_INIT;
+ size_t prefix_len;
++
++ strbuf_addstr(&refname_full, get_git_namespace());
++ prefix_len = refname_full.len;
- /* TODO: replace the fixed prefix by looking up git config variables. */
- if (!strncmp(cmd->ref_name, "refs/for/", 9)) {
- cmd->run_proc_receive = RUN_PROC_RECEIVE_SCHEDULED;
- run_proc_receive = 1;
-+ strbuf_addstr(&refname_full, get_git_namespace());
-+ prefix_len = refname_full.len;
-+
+ for (cmd = commands; cmd; cmd = cmd->next) {
+ if (!should_process_cmd(cmd))
+ continue;
@@ t/t5411/common-test-cases.sh: test_expect_success "setup proc-receive hook (with
write_script "$upstream/hooks/proc-receive" <<-EOF
printf >&2 "# proc-receive hook\n"
test-tool proc-receive -v \
-- -r "$ZERO_OID $A refs/for/a/b/c/topic ok" \
-+ -r "$ZERO_OID $A refs/review/a/b/c/topic ok" \
- -r "$ZERO_OID $A refs/for/next/topic ok\0ref=refs/pull/123/head" \
- -r "$B $A refs/for/master/topic ok\0ref=refs/pull/124/head forced-update"
+- -r "ok refs/for/a/b/c/topic" \
++ -r "ok refs/review/a/b/c/topic" \
+ -r "alt refs/for/next/topic refs/pull/123/head" \
+ -r "alt refs/for/master/topic refs/pull/124/head old-oid=$B forced-update new-oid=$A"
EOF
@@ t/t5411/common-test-cases.sh: test_expect_success "setup proc-receive hook (with extended status)" '
@@ t/t5411/common-test-cases.sh: test_expect_success "setup proc-receive hook (with
- remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/review/a/b/c/topic
remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-- remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic ok
-+ remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/review/a/b/c/topic ok
- remote: proc-receive> <ZERO-OID> <COMMIT-A> refs/for/next/topic ok\0ref=refs/pull/123/head
- remote: proc-receive> <COMMIT-B> <COMMIT-A> refs/for/master/topic ok\0ref=refs/pull/124/head forced-update
+- remote: proc-receive> ok refs/for/a/b/c/topic
++ remote: proc-receive> ok refs/review/a/b/c/topic
+ remote: proc-receive> alt refs/for/next/topic refs/pull/123/head
+ remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A>
remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
- remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/a/b/c/topic
- remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
To <URL/of/upstream.git>
* [new reference] HEAD -> refs/pull/123/head
- * [new reference] HEAD -> refs/for/a/b/c/topic
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update o
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "$B $A refs/heads/master ft" \
-+ -r "$A $ZERO_OID refs/heads/foo ft" \
-+ -r "$A $B refs/heads/bar ft" \
-+ -r "$A $B refs/for/master/topic ok\0ref=refs/pull/123/head" \
-+ -r "$B $A refs/for/next/topic ok\0ref=refs/pull/124/head forced-update"
++ -r "ft refs/heads/master" \
++ -r "ft refs/heads/foo" \
++ -r "ft refs/heads/bar" \
++ -r "alt refs/for/master/topic refs/pull/123/head old-oid=$A new-oid=$B " \
++ -r "alt refs/for/next/topic refs/pull/124/head old-oid=$B new-oid=$A forced-update"
+ EOF
+'
+
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update o
+ remote: proc-receive< <COMMIT-B> <COMMIT-A> refs/heads/master
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-+ remote: proc-receive> <COMMIT-B> <COMMIT-A> refs/heads/master ft
-+ remote: proc-receive> <COMMIT-A> <ZERO-OID> refs/heads/foo ft
-+ remote: proc-receive> <COMMIT-A> <COMMIT-B> refs/heads/bar ft
-+ remote: proc-receive> <COMMIT-A> <COMMIT-B> refs/for/master/topic ok\0ref=refs/pull/123/head
-+ remote: proc-receive> <COMMIT-B> <COMMIT-A> refs/for/next/topic ok\0ref=refs/pull/124/head forced-update
++ remote: proc-receive> ft refs/heads/master
++ remote: proc-receive> ft refs/heads/foo
++ remote: proc-receive> ft refs/heads/bar
++ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> alt refs/for/next/topic refs/pull/124/head old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update
+ remote: # post-receive hook
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/bar
+ remote: post-receive< <COMMIT-A> <ZERO-OID> refs/heads/foo
+ remote: post-receive< <COMMIT-B> <COMMIT-A> refs/heads/master
-+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
-+ remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/next/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ To <URL/of/upstream.git>
+ <OID-A>..<OID-B> <COMMIT-B> -> bar
+ - [deleted] foo
5: 2d04f495a3 ! 5: a357234e97 doc: add documentation for the proc-receive hook
@@ Documentation/githooks.txt: The default 'update' hook, when enabled--and with
+
+ # Receive result from the hook.
+ # OK, run this command successfully.
-+ H: PKT-LINE(<old-oid> <new-oid> <ref> ok)
++ H: PKT-LINE(ok <ref>)
+ # NO, I reject it.
-+ H: PKT-LINE(<old-oid> <new-oid> <ref> ng <reason>)
++ H: PKT-LINE(ng <ref> <reason>)
+ # Fall through, let 'receive-pack' to execute it.
-+ H: PKT-LINE(<old-oid> <new-oid> <ref> ft)
++ H: PKT-LINE(ft <ref>)
+ # OK, but has an alternate reference. The alternate reference name
-+ # and other status are given in key=value pairs after the null
-+ # character.
-+ H: PKT-LINE(<old-oid> <new-oid> <ref> ok\0ref=refs/pull/123/head
++ # is given in the third parameter, and other status can be given in
++ # key-value pairs.
++ H: PKT-LINE(alt <ref> <alt-ref> old-oid=<old-oid> new-oid=<new-oid>
+ forced-update)
+ H: ... ...
+ H: flush-pkt
---
Jiang Xin (7):
transport: not report a non-head push as a branch
connect: export parse_feature_value()
receive-pack: add new proc-receive hook
send-pack: extension for client-side status report refs.c: refactor to reuse ref_is_hidden()
receive-pack: new config receive.procReceiveRefs
doc: add documentation for the proc-receive hook
Documentation/config/receive.txt | 14 + Documentation/githooks.txt | 58 ++ Makefile | 1 + builtin/receive-pack.c | 345 ++++++++- connect.c | 3 +- connect.h | 1 + refs.c | 13 +- refs.h | 1 + remote.c | 28 + remote.h | 3 + send-pack.c | 11 +- t/helper/test-proc-receive.c | 178 +++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411-proc-receive-hook.sh | 67 ++ t/t5411/common-functions.sh | 54 ++ t/t5411/common-test-cases.sh | 798 +++++++++++++++++++++ t/t5412-proc-receive-hook-http-protocol.sh | 78 ++ t/t5516-fetch-push.sh | 2 +- transport-helper.c | 64 +- transport.c | 85 ++- 21 files changed, 1749 insertions(+), 57 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/common-test-cases.sh create mode 100755 t/t5412-proc-receive-hook-http-protocol.sh
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v13 1/8 transport: not report a non-head push as a branch
From: Jiang Xin <[email protected]>
When pushing a new reference (not a head or tag), report it as a new reference instead of a new branch.
--- t/t5411-proc-receive-hook.sh | 105 ++++++++++++++++++ t/t5411/common-functions.sh | 56 ++++++++++ t/t5411/test-0000-standard-git-push.sh | 84 ++++++++++++++ .../test-0001-standard-git-push--porcelain.sh | 87 +++++++++++++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++++++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++++++ t/t5516-fetch-push.sh | 2 +- transport.c | 9 +- 8 files changed, 406 insertions(+), 4 deletions(-) create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh
t/t5411-proc-receive-hook.sh new file +105 -0
@@ -0,0 +1,105 @@ +#!/bin/sh +# +# Copyright (c) 2020 Jiang Xin +# + +test_description='Test proc-receive hook' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/t5411/common-functions.sh + +setup_upstream_and_workbench () { + # Refs of upstream : master(A) + # Refs of workbench: master(A) tags/v123 + test_expect_success "setup upstream and workbench" ' + rm -rf upstream.git && + rm -rf workbench && + git init --bare upstream.git && + git init workbench && + create_commits_in workbench A B && + ( + cd workbench && + # Try to make a stable fixed width for abbreviated commit ID, + # this fixed-width oid will be replaced with "<OID>". + git config core.abbrev 7 && + git remote add origin ../upstream.git && + git update-ref refs/heads/master $A && + git tag -m "v123" v123 $A && + git push origin $A:refs/heads/master + ) && + TAG=$(git -C workbench rev-parse v123) && + + # setup pre-receive hook + write_script upstream.git/hooks/pre-receive <<-\EOF && + exec >&2 + echo "# pre-receive hook" + while read old new ref + do + echo "pre-receive< $old $new $ref" + done + EOF + + # setup post-receive hook + write_script upstream.git/hooks/post-receive <<-\EOF && + exec >&2 + echo "# post-receive hook" + while read old new ref + do + echo "post-receive< $old $new $ref" + done + EOF + + upstream=upstream.git + ' +} + +run_proc_receive_hook_test() { + case $1 in + http) + PROTOCOL="HTTP protocol" + URL_PREFIX="http://.*" + ;; + file | local) + PROTOCOL="builtin protocol" + URL_PREFIX="\.\." + ;; + esac + + # Include test cases for both file and HTTP protocol + for t in "$TEST_DIRECTORY"/t5411/test-*.sh + do + . "$t" + done +} + +# Initialize the upstream repository and local workbench. +setup_upstream_and_workbench + +# Run test cases for 'proc-receive' hook on local file protocol. +run_proc_receive_hook_test local + +ROOT_PATH="$PWD" +. "$TEST_DIRECTORY"/lib-gpg.sh +. "$TEST_DIRECTORY"/lib-httpd.sh +. "$TEST_DIRECTORY"/lib-terminal.sh +start_httpd + +# Re-initialize the upstream repository and local workbench. +setup_upstream_and_workbench + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +test_expect_success "setup for HTTP protocol" ' + git -C upstream.git config http.receivepack true && + upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" && + mv upstream.git "$upstream" && + git -C workbench remote set-url origin $HTTPD_URL/smart/upstream.git +' + +setup_askpass_helper + +# Run test cases for 'proc-receive' hook on HTTP protocol. +run_proc_receive_hook_test http + +test_done
t/t5411/common-functions.sh new file +56 -0
56 lines not on this page · raw message
t/t5411/test-0000-standard-git-push.sh new file +84 -0
84 lines not on this page · raw message
t/t5411/test-0001-standard-git-push--porcelain.sh new file +87 -0
87 lines not on this page · raw message
t/t5411/test-0002-pre-receive-declined.sh new file +33 -0
@@ -0,0 +1,33 @@ +test_expect_success "setup pre-receive hook (declined, $PROTOCOL)" ' + mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && + write_script "$upstream/hooks/pre-receive" <<-EOF + exit 1 + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git-push : master(B) next(A) +test_expect_success "git-push is declined ($PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + $B:refs/heads/master \ + HEAD:refs/heads/next \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] <COMMIT-B> -> master (pre-receive hook declined) + ! [remote rejected] HEAD -> next (pre-receive hook declined) + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +' + +test_expect_success "cleanup ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive" +'
t/t5411/test-0003-pre-receive-declined--porcelain.sh new file +34 -0
@@ -0,0 +1,34 @@ +test_expect_success "setup pre-receive hook (declined, $PROTOCOL)" ' + mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && + write_script "$upstream/hooks/pre-receive" <<-EOF + exit 1 + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git-push : master(B) next(A) +test_expect_success "git-push is declined (--porcelain, $PROTOCOL)" ' + test_must_fail git -C workbench push --porcelain origin \ + $B:refs/heads/master \ + HEAD:refs/heads/next \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! <COMMIT-B>:refs/heads/master [remote rejected] (pre-receive hook declined) + ! HEAD:refs/heads/next [remote rejected] (pre-receive hook declined) + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +' + +test_expect_success "cleanup ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive" +'
t/t5516-fetch-push.sh +1 -1
@@ -1039,7 +1039,7 @@ test_force_fetch_tag "annotated tag" "-f -a -m'tag message'" test_expect_success 'push --porcelain' ' mk_empty testrepo && echo >.git/foo "To testrepo" && - echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" && + echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new reference]" && echo >>.git/foo "Done" && git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && (
transport.c +6 -3
@@ -500,9 +500,12 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt porcelain, summary_width); else if (is_null_oid(&ref->old_oid))print_ref_status ('*' , - (starts_with (ref->name,"refs/tags/" ) ?"[new tag]" : -"[new branch]" ), - ref, ref->peer_ref,NULL , porcelain, summary_width); + (starts_with (ref->name,"refs/tags/" ) + ?"[new tag]" + : (starts_with (ref->name,"refs/heads/" ) + ?"[new branch]" + :"[new reference]" )), + ref, ref->peer_ref,NULL , porcelain, summary_width); else {struct strbuf quickref =STRBUF_INIT ;char type;
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
v13 cover New proc-receive hook for centralized workflow
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Note: This patches series is based on topic branch jx/atomic-push,
for there are overlap changes between these two topics.
## Changes since v12
1. test: Remove t5412, and move HTTP test cases into t5411.
2. test: Split test cases into multiple files as t/t5411/test-*.sh.
3. test: Add test cases for porcelain git-push output for pro-receive hook. See files 't/t5411/test-*--porcelain.sh'.
4. New patch 5/8 to feed proper commands to post-receive hook.
5. Use flag PACKET_READ_GENTLE_ON_EOF instead of PACKET_READ_DIE_ON_ERR_PACKET for packet_reader_init() when reading result from the 'proc-receive' hook. So 'receive-pack' won't die with the proc-receive hook.
6. Add two new options (--die-version and --die-readline) for 't/helper/test-proc-receive.c', so we can test unexpected crash of 'proc-receive' hook.
7. Apply the "SQUASH???" commit.
## Range-diff v12...v13
1: 77a731c151 < -: ---------- transport: not report a non-head push as a branch
-: ---------- > 1: 312ee17e84 transport: not report a non-head push as a branch
2: 4c4f7cffff = 2: e86a3c5a4e connect: export parse_feature_value()
3: b76900cb0f ! 3: 5adc60e9d1 receive-pack: add new proc-receive hook
@@ Makefile: TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
TEST_BUILTINS_OBJS += test-read-cache.o
## builtin/receive-pack.c ##
-@@
- #include "remote.h"
- #include "connect.h"
- #include "string-list.h"
-+#include "string.h"
- #include "sha1-array.h"
- #include "connected.h"
- #include "argv-array.h"
@@ builtin/receive-pack.c: static void write_head_info(void)
packet_flush(1);
}
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+
+ for (;;) {
+ struct object_id old_oid, new_oid;
-+ char *status;
++ const char *status;
+ char *refname;
+ char *remains = NULL;
+
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
+ break;
-+ status = (char *)reader->line;
++ status = reader->line;
+ refname = strchr(status, ' ');
+ if (refname) {
+ *refname++ = '\0';
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ /* Reset "run_proc_receive" field, and continue to run in "receive-pack" */
+ hint->run_proc_receive = 0;
+ } else if (!strcmp("alt", status)) {
-+ char *alt_ref;
++ char *alt_ref = NULL;
++ char *p1, *p2;
+
-+ alt_ref = remains;
-+ remains = strchr(alt_ref, ' ');
-+ if (remains)
-+ *remains++ = '\0';
++ if (!remains) {
++ strbuf_addf(errmsg, "proc-receive expected 'alt <ref> <alt-ref> ...', got 'alt %s'\n",
++ refname);
++ continue;
++ }
++ p1 = strchr(remains, '=');
++ p2 = strchr(remains, ' ');
++ if (!p1) {
++ /*
++ * "alt <ref> <alt-ref>", or
++ * "alt <ref> <alt-ref> forced-update"
++ */
++ alt_ref = remains;
++ remains = p2;
++ if (remains)
++ *remains++ = '\0';
++ } else if (!p2) {
++ /* "alt <ref> old-oid=<oid>" */
++ alt_ref = NULL;
++ } else if (p1 > p2) {
++ /* "alt <ref> <alt-ref> old-oid=<oid>" */
++ alt_ref = remains;
++ remains = p2;
++ if (remains)
++ *remains++ = '\0';
++ } else {
++ /* "alt <ref> old-oid=<oid1> new-oid=<oid2>" */
++ alt_ref = NULL;
++ }
+
+ if (hint->extended_status)
+ strbuf_addstr(&extended_status, hint->extended_status);
+
-+ strbuf_addf(&extended_status, "%sref=%s",
-+ extended_status.len > 0 ? " ": "",
-+ alt_ref);
++ /*
++ * Already received an "ok <ref>" response, add an
++ * additional "ref=<ref>" field.
++ */
++ if (extended_status.len == 0 &&
++ hint->run_proc_receive & RUN_PROC_RECEIVE_RETURNED)
++ strbuf_addf(&extended_status, "ref=%s", refname);
++
++ if (alt_ref)
++ strbuf_addf(&extended_status, "%sref=%s",
++ extended_status.len > 0 ? " ": "",
++ alt_ref);
++ else if (extended_status.len > 0)
++ /*
++ * Start new extended status for refname, if it
++ * is not the first report for this reference.
++ */
++ strbuf_addf(&extended_status, " ref=%s", refname);
+
+ if (remains) {
+ const char *val;
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ /* Version negotiaton */
+ packet_reader_init(&reader, proc.out, NULL, 0,
+ PACKET_READ_CHOMP_NEWLINE |
-+ PACKET_READ_DIE_ON_ERR_PACKET);
++ PACKET_READ_GENTLE_ON_EOF);
+ if (use_atomic)
+ strbuf_addstr(&cap, " atomic");
+ if (use_push_options)
@@ t/helper/test-proc-receive.c (new)
+ NULL
+};
+
-+static int version = 1;
-+static int verbose = 0;
++static int die_version = 0;
++static int die_readline = 0;
+static int no_push_options = 0;
+static int use_atomic = 0;
+static int use_push_options = 0;
++static int verbose = 0;
++static int version = 1;
+static struct string_list returns = STRING_LIST_INIT_NODUP;
+
+struct command {
@@ t/helper/test-proc-receive.c (new)
+ }
+ }
+
-+ if (server_version != 1)
++ if (server_version != 1 || die_version)
+ die("bad protocol version: %d", server_version);
+
+ packet_write_fmt(1, "version=%d%c%s\n",
@@ t/helper/test-proc-receive.c (new)
+ if (parse_oid_hex(reader->line, &old_oid, &p) ||
+ *p++ != ' ' ||
+ parse_oid_hex(p, &new_oid, &p) ||
-+ *p++ != ' ')
++ *p++ != ' ' ||
++ die_readline)
+ die("protocol error: expected 'old new ref', got '%s'",
+ reader->line);
+ refname = p;
@@ t/helper/test-proc-receive.c (new)
+ struct option options[] = {
+ OPT_BOOL(0, "no-push-options", &no_push_options,
+ "disable push options"),
++ OPT_BOOL(0, "die-version", &die_version,
++ "die during version negotiation"),
++ OPT_BOOL(0, "die-readline", &die_readline,
++ "die when readline"),
+ OPT_STRING_LIST('r', "return", &returns, "old/new/ref/status/msg",
+ "return of results"),
+ OPT__VERBOSE(&verbose, "be verbose"),
@@ t/helper/test-proc-receive.c (new)
+ }
+
+ if (returns.nr)
-+ for_each_string_list_item(item, &returns) {
-+ char *p;
-+
-+ p = strstr(item->string, "\\0");
-+ if (p) {
-+ *p = '\0';
-+ p += 2;
-+ packet_write_fmt(1, "%s%c%s\n", item->string, '\0', p);
-+ } else {
-+ packet_write_fmt(1, "%s\n", item->string);
-+ }
-+ }
++ for_each_string_list_item(item, &returns)
++ packet_write_fmt(1, "%s\n", item->string);
+ packet_flush(1);
+ sigchain_pop(SIGPIPE);
+
@@ t/helper/test-tool.h: int cmd__parse_pathspec_file(int argc, const char** argv);
int cmd__reach(int argc, const char **argv);
int cmd__read_cache(int argc, const char **argv);
- ## t/t5411/common-functions.sh ##
-@@ t/t5411/common-functions.sh: create_commits_in () {
- # Format the output of git-push, git-show-ref and other commands to make a
- # user-friendly and stable text. We can easily prepare the expect text
- # without having to worry about future changes of the commit ID and spaces
--# of the output. We also replce single quotes with double quotes, because
--# it is boring to prepare unquoted single quotes in expect text.
-+# of the output. Single quotes are replaced with double quotes, because
-+# it is boring to prepare unquoted single quotes in expect text. We also
-+# remove some locale error messages, which break test if we turn on
-+# `GIT_TEST_GETTEXT_POISON=true` in order to test unintentional translations
-+# on plumbing commands.
- make_user_friendly_and_stable_output_common () {
- sed \
- -e "s/ *\$//" \
-@@ t/t5411/common-functions.sh: make_user_friendly_and_stable_output_common () {
- -e "s/$TAG/<TAG-v123>/g" \
- -e "s/$ZERO_OID/<ZERO-OID>/g" \
- -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
-- -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g"
-+ -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
-+ -e "/^error: / d"
- }
-
- ## t/t5411/common-test-cases.sh ##
-@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
- EOF
- test_cmp expect actual
- '
-+
-+# Refs of upstream : master(A) tags/v123 refs/review/master/topic(A) a/b/c(A)
-+# Refs of workbench: master(A) tags/v123
-+test_expect_success "cleanup" '
-+ (
-+ cd "$upstream" &&
-+ git update-ref -d refs/review/master/topic &&
-+ git update-ref -d refs/tags/v123 &&
-+ git update-ref -d refs/heads/a/b/c
-+ )
-+'
-+
+ ## t/t5411/test-0011-no-hook-error.sh (new) ##
+@@
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : next(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: no hook, fail to push special ref" '
++test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)" '
+ test_must_fail git -C workbench push origin \
+ HEAD:next \
+ HEAD:refs/for/master/topic \
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+
+# Refs of upstream : master(A) next(A)
+# Refs of workbench: master(A) tags/v123
-+test_expect_success "cleanup" '
++test_expect_success "cleanup ($PROTOCOL)" '
+ git -C "$upstream" update-ref -d refs/heads/next
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push --atomic: (B) next(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: no hook, fail all for atomic push" '
++test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCOL)" '
+ test_must_fail git -C workbench push --atomic origin \
+ $B:master \
+ HEAD:next \
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ <COMMIT-A> refs/heads/master
+ EOF
+ test_cmp expect actual
++'
+
+ ## t/t5411/test-0012-no-hook-error--porcelain.sh (new) ##
+@@
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : next(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: no hook, fail to push special ref (--porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ HEAD:next \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: error: cannot find hook "proc-receive"
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ To <URL/of/upstream.git>
++ * HEAD:refs/heads/next [new branch]
++ ! HEAD:refs/for/master/topic [remote rejected] (fail to run proc-receive hook)
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ <COMMIT-A> refs/heads/next
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(A) next(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ git -C "$upstream" update-ref -d refs/heads/next
+'
+
-+test_expect_success "setup proc-receive hook (unknown version)" '
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push --atomic: (B) next(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: no hook, all failed for atomic push (--porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain --atomic origin \
++ $B:master \
++ HEAD:next \
++ HEAD:refs/for/master/topic >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: error: cannot find hook "proc-receive"
++ To <URL/of/upstream.git>
++ ! <COMMIT-B>:refs/heads/master [remote rejected] (fail to run proc-receive hook)
++ ! HEAD:refs/heads/next [remote rejected] (fail to run proc-receive hook)
++ ! HEAD:refs/for/master/topic [remote rejected] (fail to run proc-receive hook)
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0013-bad-protocol.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v --version 2
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: bad protocol (unknown version)" '
++test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" '
+ test_must_fail git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+
+ # Check status report for git-push
+ sed -n \
-+ -e "/^To / { s/ */ /g; p; }" \
-+ -e "/^ / { s/ */ /g; p; }" \
++ -e "/^To / { p; n; p; }" \
+ <actual >actual-report &&
+ cat >expect <<-EOF &&
+ To <URL/of/upstream.git>
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ # Check error message from "receive-pack", but ignore unstable fatal error
+ # message ("remote: fatal: the remote end hung up unexpectedly") which
+ # is different from the remote HTTP server with different locale settings.
-+ sed -n -e "/^remote: error:/ { s/ */ /g; p; }" \
-+ <actual >actual-error &&
++ grep "^remote: error:" <actual >actual-error &&
+ cat >expect <<-EOF &&
+ remote: error: proc-receive version "2" is not supported
+ EOF
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (no report)" '
++test_expect_success "setup proc-receive hook (hook --die-version, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v --die-version
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" '
++ test_must_fail git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: fatal: bad protocol version: 1
++ remote: error: proc-receive version "0" is not supported
++ To <URL/of/upstream.git>
++ ! [remote rejected] HEAD -> refs/for/master/topic (fail to run proc-receive hook)
++ EOF
++ test_cmp expect actual &&
++
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (hook --die-readline, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v --die-readline
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" '
++ test_must_fail git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: fatal: protocol error: expected "old new ref", got "<ZERO-OID> <COMMIT-A> refs/for/master/topic"
++ To <URL/of/upstream.git>
++ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
++ EOF
++ test_cmp expect actual &&
++
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : next(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: bad protocol (no report)" '
++test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
+ test_must_fail git -C workbench push origin \
+ HEAD:refs/heads/next \
+ HEAD:refs/for/master/topic >out 2>&1 &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+
+# Refs of upstream : master(A) next(A)
+# Refs of workbench: master(A) tags/v123
-+test_expect_success "cleanup" '
++test_expect_success "cleanup ($PROTOCOL)" '
+ git -C "$upstream" update-ref -d refs/heads/next
+
+'
+
-+test_expect_success "setup proc-receive hook (no ref)" '
++test_expect_success "setup proc-receive hook (no ref, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: bad protocol (no ref)" '
++test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
+ test_must_fail git -C workbench push origin \
+ HEAD:refs/for/master/topic\
+ >out 2>&1 &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (unknown status)" '
++test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: bad protocol (unknown status)" '
++test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
+ test_must_fail git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ EOF
+ test_cmp expect actual
+'
-+
-+test_expect_success "setup proc-receive hook (ng)" '
+
+ ## t/t5411/test-0014-bad-protocol--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
-+ test-tool proc-receive -v \
-+ -r "ng refs/for/master/topic"
++ test-tool proc-receive -v --version 2
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: fail to update (ng)" '
-+ test_must_fail git -C workbench push origin \
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: bad protocol (unknown version, --porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
++
++ # Check status report for git-push
++ sed -n \
++ -e "/^To / { p; n; p; n; p; }" \
++ <actual >actual-report &&
+ cat >expect <<-EOF &&
-+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> ng refs/for/master/topic
+ To <URL/of/upstream.git>
-+ ! [remote rejected] HEAD -> refs/for/master/topic (failed)
++ ! HEAD:refs/for/master/topic [remote rejected] (fail to run proc-receive hook)
++ Done
+ EOF
-+ test_cmp expect actual &&
++ test_cmp expect actual-report &&
++
++ # Check error message from "receive-pack", but ignore unstable fatal error
++ # message ("remote: fatal: the remote end hung up unexpectedly") which
++ # is different from the remote HTTP server with different locale settings.
++ grep "^remote: error:" <actual >actual-error &&
++ cat >expect <<-EOF &&
++ remote: error: proc-receive version "2" is not supported
++ EOF
++ test_cmp expect actual-error &&
++
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (ng message)" '
++test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
-+ test-tool proc-receive -v \
-+ -r "ng refs/for/master/topic error msg"
++ test-tool proc-receive -v
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: fail to update (ng message)" '
-+ test_must_fail git -C workbench push origin \
-+ HEAD:refs/for/master/topic \
-+ >out 2>&1 &&
++# git push : next(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: bad protocol (no report, --porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ HEAD:refs/heads/next \
++ HEAD:refs/for/master/topic >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> ng refs/for/master/topic error msg
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
+ To <URL/of/upstream.git>
-+ ! [remote rejected] HEAD -> refs/for/master/topic (error msg)
++ * HEAD:refs/heads/next [new branch]
++ ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
++ Done
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/master
++ <COMMIT-A> refs/heads/next
+ EOF
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (unexpected ref)" '
++# Refs of upstream : master(A) next(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ git -C "$upstream" update-ref -d refs/heads/next
++
++'
++
++test_expect_success "setup proc-receive hook (no ref, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ok refs/heads/master"
++ -r "ok"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+# git push : (B) refs/for/master/topic
-+test_expect_success "proc-receive: report on unexpected ref" '
-+ test_must_fail git -C workbench push origin \
-+ $B:refs/heads/master \
-+ HEAD:refs/for/master/topic \
++# git push : refs/for/master/topic
++test_expect_success "proc-receive: bad protocol (no ref, --porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic\
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ remote: # pre-receive hook
-+ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> ok refs/heads/master
-+ remote: error: proc-receive reported status on unexpected ref: refs/heads/master
-+ remote: # post-receive hook
-+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ remote: proc-receive> ok
++ remote: error: proc-receive expected "<status> <ref> ...", got "ok"
+ To <URL/of/upstream.git>
-+ <OID-A>..<OID-B> <COMMIT-B> -> master
-+ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
++ ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
++ Done
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
-+ <COMMIT-B> refs/heads/master
++ <COMMIT-A> refs/heads/master
+ EOF
+ test_cmp expect actual
+'
+
-+# Refs of upstream : master(B)
-+# Refs of workbench: master(A) tags/v123
-+test_expect_success "cleanup" '
-+ git -C "$upstream" update-ref refs/heads/master $A
-+'
-+
-+test_expect_success "setup proc-receive hook (ok)" '
++test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ok refs/for/master/topic"
++ -r "xx refs/for/master/topic"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: ok" '
-+ git -C workbench push origin \
-+ HEAD:refs/for/master/topic \
-+ >out 2>&1 &&
++test_expect_success "proc-receive: bad protocol (unknown status, --porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ remote: # pre-receive hook
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> ok refs/for/master/topic
-+ remote: # post-receive hook
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> xx refs/for/master/topic
++ remote: error: proc-receive reported bad status "xx" on ref "refs/for/master/topic"
+ To <URL/of/upstream.git>
-+ * [new reference] HEAD -> refs/for/master/topic
++ ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
++ Done
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ <COMMIT-A> refs/heads/master
+ EOF
+ test_cmp expect actual
++'
+
+ ## t/t5411/test-0020-report-ng.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ng refs/for/master/topic"
++ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+# git push : refs/for/a/b/c/my/topic
-+test_expect_success "proc-receive: failed to report status" '
++# git push : refs/for/master/topic
++test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" '
+ test_must_fail git -C workbench push origin \
-+ HEAD:refs/for/a/b/c/my/topic \
++ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
-+ remote: proc-receive> ok refs/for/master/topic
-+ remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ng refs/for/master/topic
+ To <URL/of/upstream.git>
-+ ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
++ ! [remote rejected] HEAD -> refs/for/master/topic (failed)
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ test_cmp expect actual
+'
+
-+# Refs of upstream : master(A)
-+# Refs of workbench: master(A) tags/v123
-+# git push -o ... : refs/for/master/topic
-+test_expect_success "proc-receive: not support push options" '
-+ test_must_fail git -C workbench push \
++test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ng refs/for/master/topic error msg"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic
++test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)" '
++ test_must_fail git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ng refs/for/master/topic error msg
++ To <URL/of/upstream.git>
++ ! [remote rejected] HEAD -> refs/for/master/topic (error msg)
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0021-report-ng--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ng refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic
++test_expect_success "proc-receive: fail to update (ng, no message, --porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ng refs/for/master/topic
++ To <URL/of/upstream.git>
++ ! HEAD:refs/for/master/topic [remote rejected] (failed)
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ng refs/for/master/topic error msg"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic
++test_expect_success "proc-receive: fail to update (ng, with message, --porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ng refs/for/master/topic error msg
++ To <URL/of/upstream.git>
++ ! HEAD:refs/for/master/topic [remote rejected] (error msg)
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0022-report-unexpect-ref.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/heads/master"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : (B) refs/for/master/topic
++test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
++ test_must_fail git -C workbench push origin \
++ $B:refs/heads/master \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/heads/master
++ remote: error: proc-receive reported status on unexpected ref: refs/heads/master
++ remote: # post-receive hook
++ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ To <URL/of/upstream.git>
++ <OID-A>..<OID-B> <COMMIT-B> -> master
++ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-B> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(B)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ git -C "$upstream" update-ref refs/heads/master $A
++'
+
+ ## t/t5411/test-0023-report-unexpect-ref--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/heads/master"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : (B) refs/for/master/topic
++test_expect_success "proc-receive: report unexpected ref (--porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ $B:refs/heads/master \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/heads/master
++ remote: error: proc-receive reported status on unexpected ref: refs/heads/master
++ remote: # post-receive hook
++ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ To <URL/of/upstream.git>
++ <COMMIT-B>:refs/heads/master <OID-A>..<OID-B>
++ ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-B> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(B)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ git -C "$upstream" update-ref refs/heads/master $A
++'
+
+ ## t/t5411/test-0024-report-unknown-ref.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/a/b/c/my/topic
++test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
++ test_must_fail git -C workbench push origin \
++ HEAD:refs/for/a/b/c/my/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
++ remote: proc-receive> ok refs/for/master/topic
++ remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
++ To <URL/of/upstream.git>
++ ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0025-report-unknown-ref--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/a/b/c/my/topic
++test_expect_success "proc-receive: report unknown reference (--porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ HEAD:refs/for/a/b/c/my/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
++ remote: proc-receive> ok refs/for/master/topic
++ remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
++ To <URL/of/upstream.git>
++ ! HEAD:refs/for/a/b/c/my/topic [remote rejected] (proc-receive failed to report status)
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0026-push-options.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL)" '
++ git -C "$upstream" config receive.advertisePushOptions false &&
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push -o ... : refs/for/master/topic
++test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
++ test_must_fail git -C workbench push \
+ -o issue=123 \
+ -o reviewer=user1 \
+ origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
-+ test_i18ngrep "fatal: the receiving end does not support push options" \
-+ actual &&
++ test_i18ngrep "fatal: the receiving end does not support push options" \
++ actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "enable push options ($PROTOCOL)" '
++ git -C "$upstream" config receive.advertisePushOptions true
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push -o ... : next(A) refs/for/master/topic
++test_expect_success "proc-receive: push with options ($PROTOCOL)" '
++ git -C workbench push \
++ --atomic \
++ -o issue=123 \
++ -o reviewer=user1 \
++ origin \
++ HEAD:refs/heads/next \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive: atomic push_options
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive< issue=123
++ remote: proc-receive< reviewer=user1
++ remote: proc-receive> ok refs/for/master/topic
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new branch] HEAD -> next
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ <COMMIT-A> refs/heads/next
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(A) next(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ git -C "$upstream" update-ref -d refs/heads/next
++'
+
+ ## t/t5411/test-0027-push-options--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL)" '
++ git -C "$upstream" config receive.advertisePushOptions false &&
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push -o ... : refs/for/master/topic
++test_expect_success "proc-receive: not support push options (--porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push \
++ --porcelain \
++ -o issue=123 \
++ -o reviewer=user1 \
++ origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ test_i18ngrep "fatal: the receiving end does not support push options" \
++ actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "enable push options ($PROTOCOL)" '
++ git -C "$upstream" config receive.advertisePushOptions true
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push -o ... : next(A) refs/for/master/topic
++test_expect_success "proc-receive: push with options (--porcelain, $PROTOCOL)" '
++ git -C workbench push \
++ --porcelain \
++ --atomic \
++ -o issue=123 \
++ -o reviewer=user1 \
++ origin \
++ HEAD:refs/heads/next \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive: atomic push_options
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive< issue=123
++ remote: proc-receive< reviewer=user1
++ remote: proc-receive> ok refs/for/master/topic
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/heads/next [new branch]
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ <COMMIT-A> refs/heads/next
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(A) next(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ git -C "$upstream" update-ref -d refs/heads/next
++'
+
+ ## t/t5411/test-0030-report-ok.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic
++test_expect_success "proc-receive: ok ($PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/for/master/topic
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0031-report-ok--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic
++test_expect_success "proc-receive: ok (--porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/for/master/topic
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0032-report-alt.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (alt <ref>, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref>, $PROTOCOL)" '
++ test_must_fail git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic
++ remote: error: proc-receive expected "alt <ref> <alt-ref> ...", got "alt refs/for/master/topic"
++ To <URL/of/upstream.git>
++ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> <alt-ref>, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic refs/pull/123/head"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, $PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> <alt-ref> forced-update, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic refs/pull/123/head forced-update"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update, $PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head forced-update
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> <alt-ref> old-oid=X, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic refs/pull/123/head old-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, $PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> old-oid=X, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic old-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, $PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> old-oid=X new-oid=Y, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic old-oid=$A new-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, $PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (with multiple alt reports, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/a/b/c/topic" \
++ -r "alt refs/for/next/topic refs/pull/123/head" \
++ -r "alt refs/for/master/topic refs/pull/124/head old-oid=$B forced-update new-oid=$A"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: with multiple alt reports ($PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/next/topic \
++ HEAD:refs/for/a/b/c/topic \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/for/a/b/c/topic
++ remote: proc-receive> alt refs/for/next/topic refs/pull/123/head
++ remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/next/topic
++ * [new reference] HEAD -> refs/for/a/b/c/topic
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual &&
++
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0033-report-alt--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (alt <ref>, --porcelain, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref>, --porcelain, $PROTOCOL)" '
++ test_must_fail git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic
++ remote: error: proc-receive expected "alt <ref> <alt-ref> ...", got "alt refs/for/master/topic"
++ To <URL/of/upstream.git>
++ ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
++ Done
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> <alt-ref>, --porcelain, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic refs/pull/123/head"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, --porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> <alt-ref> forced-update, --porcelain, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic refs/pull/123/head forced-update"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update, --porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head forced-update
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> <alt-ref> old-oid=X, --porcelain, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic refs/pull/123/head old-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, --porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> old-oid=X, --porcelain, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic old-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, --porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (alt <ref> old-oid=X new-oid=Y, --porcelain, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic old-oid=$A new-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, --porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (with multiple alt reports, --porcelain, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/a/b/c/topic" \
++ -r "alt refs/for/next/topic refs/pull/123/head" \
++ -r "alt refs/for/master/topic refs/pull/124/head old-oid=$B forced-update new-oid=$A"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: with multiple alt reports (--porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/next/topic \
++ HEAD:refs/for/a/b/c/topic \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/for/a/b/c/topic
++ remote: proc-receive> alt refs/for/next/topic refs/pull/123/head
++ remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/next/topic [new reference]
++ * HEAD:refs/for/a/b/c/topic [new reference]
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual &&
++
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
+
+ ## t/t5411/test-0034-report-ft.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (ft, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ft refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic(B)
++test_expect_success "proc-receive: fall throught, let receive-pack to execute ($PROTOCOL)" '
++ git -C workbench push origin \
++ $B:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
++ remote: proc-receive> ft refs/for/master/topic
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] <COMMIT-B> -> refs/for/master/topic
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-B> refs/for/master/topic
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(A) refs/for/master/topic(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ git -C "$upstream" update-ref -d refs/for/master/topic
++'
+
+ ## t/t5411/test-0035-report-ft--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (ft, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ft refs/for/master/topic"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic(B)
++test_expect_success "proc-receive: fall throught, let receive-pack to execute (--porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ $B:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
++ remote: proc-receive> ft refs/for/master/topic
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * <COMMIT-B>:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-B> refs/for/master/topic
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(A) refs/for/master/topic(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ git -C "$upstream" update-ref -d refs/for/master/topic
++'
+
+ ## t/t5411/test-0036-report-multi-alt-for-one-ref.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (multiple alt, no alt-ref for the 1st resp, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic old-oid=$A new-oid=$B" \
++ -r "alt refs/for/master/topic refs/changes/24/124/1 old-oid=$ZERO_OID new-oid=$A" \
++ -r "alt refs/for/master/topic refs/changes/25/125/1 old-oid=$A new-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st resp ($PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A>
++ remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ test_cmp expect actual
+'
+
-+test_expect_success "enable push options" '
-+ git -C "$upstream" config receive.advertisePushOptions true
++test_expect_success "setup proc-receive hook (multiple alt, no alt-ref for the 2nd resp, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic refs/changes/24/124/1 old-oid=$ZERO_OID new-oid=$A" \
++ -r "alt refs/for/master/topic old-oid=$A new-oid=$B" \
++ -r "alt refs/for/master/topic refs/changes/25/125/1 old-oid=$B new-oid=$A forced-update"
++ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+# git push -o ... : next(A) refs/for/master/topic
-+test_expect_success "proc-receive: push with options" '
-+ git -C workbench push \
-+ --atomic \
-+ -o issue=123 \
-+ -o reviewer=user1 \
-+ origin \
-+ HEAD:refs/heads/next \
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd resp ($PROTOCOL)" '
++ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
-+ remote: proc-receive: atomic push_options
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive< issue=123
-+ remote: proc-receive< reviewer=user1
-+ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A>
++ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update
+ remote: # post-receive hook
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
-+ * [new branch] HEAD -> next
+ * [new reference] HEAD -> refs/for/master/topic
+ EOF
+ test_cmp expect actual &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/master
-+ <COMMIT-A> refs/heads/next
+ EOF
+ test_cmp expect actual
+'
+
-+# Refs of upstream : master(A) next(A)
++test_expect_success "setup proc-receive hook (ok and alt for the same ref, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic" \
++ -r "alt refs/for/master/topic refs/changes/24/124/1 new-oid=$B old-oid=$A"
++ EOF
++'
++
++# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+test_expect_success "cleanup" '
-+ git -C "$upstream" update-ref -d refs/heads/next
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: report ok and alt for the same ref ($PROTOCOL)" '
++ git -C workbench push origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 new-oid=<COMMIT-B> old-oid=<COMMIT-A>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * [new reference] HEAD -> refs/for/master/topic
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (ft)" '
++test_expect_success "setup proc-receive hook (multiple responses, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ft refs/for/master/topic"
++ -r "alt refs/for/master/topic refs/changes/23/123/1" \
++ -r "alt refs/for/master/topic refs/changes/24/124/2 old-oid=$A new-oid=$B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+# git push : refs/for/master/topic(B)
-+test_expect_success "proc-receive: fall throught, let receive-pack to execute" '
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: report multiple response ($PROTOCOL)" '
+ git -C workbench push origin \
-+ $B:refs/for/master/topic \
++ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
-+ remote: proc-receive> ft refs/for/master/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/changes/23/123/1
++ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/2 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
+ remote: # post-receive hook
-+ remote: post-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
-+ * [new reference] <COMMIT-B> -> refs/for/master/topic
++ * [new reference] HEAD -> refs/for/master/topic
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
-+ <COMMIT-B> refs/for/master/topic
+ <COMMIT-A> refs/heads/master
+ EOF
+ test_cmp expect actual
++'
+
+ ## t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook (multiple alt, no alt-ref for the 1st resp, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "alt refs/for/master/topic old-oid=$A new-oid=$B" \
++ -r "alt refs/for/master/topic refs/changes/24/124/1 old-oid=$ZERO_OID new-oid=$A" \
++ -r "alt refs/for/master/topic refs/changes/25/125/1 old-oid=$A new-oid=$B"
++ EOF
+'
+
-+# Refs of upstream : master(A) refs/for/master/topic(A)
++# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+test_expect_success "cleanup" '
-+ git -C "$upstream" update-ref -d refs/for/master/topic
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st resp (--porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A>
++ remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (with extended status)" '
++test_expect_success "setup proc-receive hook (multiple alt, no alt-ref for the 2nd resp, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ok refs/for/a/b/c/topic" \
-+ -r "alt refs/for/next/topic refs/pull/123/head" \
-+ -r "alt refs/for/master/topic refs/pull/124/head old-oid=$B forced-update new-oid=$A"
++ -r "alt refs/for/master/topic refs/changes/24/124/1 old-oid=$ZERO_OID new-oid=$A" \
++ -r "alt refs/for/master/topic old-oid=$A new-oid=$B" \
++ -r "alt refs/for/master/topic refs/changes/25/125/1 old-oid=$B new-oid=$A forced-update"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
-+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report with extended status" '
-+ git -C workbench push origin \
-+ HEAD:refs/for/next/topic \
-+ HEAD:refs/for/a/b/c/topic \
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd resp (--porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> ok refs/for/a/b/c/topic
-+ remote: proc-receive> alt refs/for/next/topic refs/pull/123/head
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A>
++ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A>
++ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update
+ remote: # post-receive hook
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
-+ * [new reference] HEAD -> refs/for/next/topic
-+ * [new reference] HEAD -> refs/for/a/b/c/topic
-+ * [new reference] HEAD -> refs/for/master/topic
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook (ok and alt for the same ref, $PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic" \
++ -r "alt refs/for/master/topic refs/changes/24/124/1 new-oid=$B old-oid=$A"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : refs/for/master/topic(A)
++test_expect_success "proc-receive: report ok and alt for the same ref (--porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 new-oid=<COMMIT-B> old-oid=<COMMIT-A>
++ remote: # post-receive hook
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ * HEAD:refs/for/master/topic [new reference]
++ Done
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (multiple responses)" '
++test_expect_success "setup proc-receive hook (multiple responses, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report multiple response" '
-+ git -C workbench push origin \
++test_expect_success "proc-receive: report multiple response (--porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
-+ * [new reference] HEAD -> refs/for/master/topic
++ * HEAD:refs/for/master/topic [new reference]
++ Done
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ EOF
+ test_cmp expect actual
+'
-+
-+test_expect_success "setup proc-receive hook" '
+
+ ## t/t5411/test-0038-report-mixed-refs.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook ($PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : (B) bar(A) baz(A) refs/for/next/topic(A) foo(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report update of mixed refs" '
++test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
+ git -C workbench push origin \
+ $B:refs/heads/master \
+ HEAD:refs/heads/bar \
@@ t/t5411/common-test-cases.sh: test_expect_success "normal git-push command" '
+ EOF
+ test_cmp expect actual
+'
++
++# Refs of upstream : master(B) foo(A) bar(A)) baz(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ (
++ cd "$upstream" &&
++ git update-ref refs/heads/master $A &&
++ git update-ref -d refs/heads/foo &&
++ git update-ref -d refs/heads/bar &&
++ git update-ref -d refs/heads/baz
++ )
++
++'
+
+ ## t/t5411/test-0039-report-mixed-refs--porcelain.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook ($PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/next/topic" \
++ -r "alt refs/for/master/topic refs/for/master/topic old-oid=$A new-oid=$B"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : (B) bar(A) baz(A) refs/for/next/topic(A) foo(A) refs/for/master/topic(A)
++test_expect_success "proc-receive: report update of mixed refs (--porcelain, $PROTOCOL)" '
++ git -C workbench push --porcelain origin \
++ $B:refs/heads/master \
++ HEAD:refs/heads/bar \
++ HEAD:refs/heads/baz \
++ HEAD:refs/for/next/topic \
++ HEAD:refs/heads/foo \
++ HEAD:refs/for/master/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive> ok refs/for/next/topic
++ remote: proc-receive> alt refs/for/master/topic refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: # post-receive hook
++ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ To <URL/of/upstream.git>
++ <COMMIT-B>:refs/heads/master <OID-A>..<OID-B>
++ * HEAD:refs/heads/bar [new branch]
++ * HEAD:refs/heads/baz [new branch]
++ * HEAD:refs/for/next/topic [new reference]
++ * HEAD:refs/heads/foo [new branch]
++ * HEAD:refs/for/master/topic [new reference]
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/bar
++ <COMMIT-A> refs/heads/baz
++ <COMMIT-A> refs/heads/foo
++ <COMMIT-B> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(B) foo(A) bar(A)) baz(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ (
++ cd "$upstream" &&
++ git update-ref refs/heads/master $A &&
++ git update-ref -d refs/heads/foo &&
++ git update-ref -d refs/heads/bar &&
++ git update-ref -d refs/heads/baz
++ )
++
++'4: d20702291b ! 4: f03038c82f send-pack: extension for client-side status report
@@ remote.c: void apply_push_cas(struct push_cas_option *cas,
+void update_ref_from_remote_status(struct ref *ref)
+{
+ char *val;
-+ char c;
+ int len;
+
+ if (!ref->remote_status)
+ return;
+
+ val = (char *)parse_feature_value(ref->remote_status, "old-oid", &len);
-+ if (val && len) {
-+ c = *(val+len);
-+ *(val+len) = '\0';
++ if (val && len)
+ get_oid_hex(val, &ref->old_oid);
-+ *(val+len) = c;
-+ }
++
+ val = (char *)parse_feature_value(ref->remote_status, "new-oid", &len);
-+ if (val && len) {
-+ c = *(val+len);
-+ *(val+len) = '\0';
++ if (val && len)
+ get_oid_hex(val, &ref->new_oid);
-+ *(val+len) = c;
-+ }
++
+ if (parse_feature_request(ref->remote_status, "forced-update"))
+ ref->forced_update = 1;
+}
@@ send-pack.c: static int receive_status(struct packet_reader *reader, struct ref
/* first try searching at our hint, falling back to all refs */ if (hint)
@@ send-pack.c: static int receive_status(struct packet_reader *reader, struct ref *refs)
+ hint->status = REF_STATUS_OK;
+ else
hint->status = REF_STATUS_REMOTE_REJECT;
- ret = -1;
- }
- hint->remote_status = xstrdup_or_null(msg);
+ if (msg)
+ hint->remote_status = xstrdup(msg);
+ else if (extended_status)
-+ hint->remote_status = xstrdup(extended_status);
++ hint->remote_status = xstrdup_or_null(extended_status);
/* start our next search from the next ref */
hint = hint->next;
}
- ## t/t5411/common-test-cases.sh ##
-@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report with extended status" '
+ ## t/t5411/test-0032-report-alt.sh ##
+@@ t/t5411/test-0032-report-alt.sh: test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, $PROTOCOL)"
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * [new reference] HEAD -> refs/for/master/topic
++ * [new reference] HEAD -> refs/pull/123/head
+ EOF
+ test_cmp expect actual
+ '
+@@ t/t5411/test-0032-report-alt.sh: test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * [new reference] HEAD -> refs/for/master/topic
++ * [new reference] HEAD -> refs/pull/123/head
+ EOF
+ test_cmp expect actual
+ '
+@@ t/t5411/test-0032-report-alt.sh: test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, $P
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * [new reference] HEAD -> refs/for/master/topic
++ <OID-B>..<OID-A> HEAD -> refs/pull/123/head
+ EOF
+ test_cmp expect actual
+ '
+@@ t/t5411/test-0032-report-alt.sh: test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, $PROTOCOL)"
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * [new reference] HEAD -> refs/for/master/topic
++ <OID-B>..<OID-A> HEAD -> refs/for/master/topic
+ EOF
+ test_cmp expect actual
+ '
+@@ t/t5411/test-0032-report-alt.sh: test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, $P
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * [new reference] HEAD -> refs/for/master/topic
++ <OID-A>..<OID-B> HEAD -> refs/for/master/topic
+ EOF
+ test_cmp expect actual
+ '
+@@ t/t5411/test-0032-report-alt.sh: test_expect_success "proc-receive: with multiple alt reports ($PROTOCOL)" '
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
To <URL/of/upstream.git>
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report with ext
+ + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
EOF
test_cmp expect actual &&
+
+
+ ## t/t5411/test-0033-report-alt--porcelain.sh ##
+@@ t/t5411/test-0033-report-alt--porcelain.sh: test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, --porcelain,
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/master/topic [new reference]
++ * HEAD:refs/pull/123/head [new reference]
+ Done
+ EOF
+ test_cmp expect actual
+@@ t/t5411/test-0033-report-alt--porcelain.sh: test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/master/topic [new reference]
++ * HEAD:refs/pull/123/head [new reference]
+ Done
+ EOF
+ test_cmp expect actual
+@@ t/t5411/test-0033-report-alt--porcelain.sh: test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, --
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/master/topic [new reference]
++ HEAD:refs/pull/123/head <OID-B>..<OID-A>
+ Done
+ EOF
+ test_cmp expect actual
+@@ t/t5411/test-0033-report-alt--porcelain.sh: test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, --porcelain,
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/master/topic [new reference]
++ HEAD:refs/for/master/topic <OID-B>..<OID-A>
+ Done
+ EOF
+ test_cmp expect actual
+@@ t/t5411/test-0033-report-alt--porcelain.sh: test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, --
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/master/topic [new reference]
++ HEAD:refs/for/master/topic <OID-A>..<OID-B>
+ Done
+ EOF
+ test_cmp expect actual
+@@ t/t5411/test-0033-report-alt--porcelain.sh: test_expect_success "proc-receive: with multiple alt reports (--porcelain, $PROT
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/next/topic [new reference]
++ * HEAD:refs/pull/123/head [new reference]
+ * HEAD:refs/for/a/b/c/topic [new reference]
+- * HEAD:refs/for/master/topic [new reference]
++ + HEAD:refs/pull/124/head <OID-B>...<OID-A> (forced update)
+ Done
+ EOF
+ test_cmp expect actual &&
+
+ ## t/t5411/test-0036-report-multi-alt-for-one-ref.sh ##
+@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh: test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st r
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * [new reference] HEAD -> refs/for/master/topic
++ <OID-A>..<OID-B> HEAD -> refs/for/master/topic
++ * [new reference] HEAD -> refs/changes/24/124/1
++ <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
+ EOF
+ test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
-@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report multiple response" '
+@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh: test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd r
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * [new reference] HEAD -> refs/for/master/topic
++ * [new reference] HEAD -> refs/changes/24/124/1
++ <OID-A>..<OID-B> HEAD -> refs/for/master/topic
++ + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
+@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh: test_expect_success "proc-receive: report ok and alt for the same ref ($PROTOCOL
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+ * [new reference] HEAD -> refs/for/master/topic
++ <OID-A>..<OID-B> HEAD -> refs/changes/24/124/1
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
+@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh: test_expect_success "proc-receive: report multiple response ($PROTOCOL)" '
remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
To <URL/of/upstream.git>
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report multiple
EOF
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
-@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update of mixed refs" '
+
+ ## t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh ##
+@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh: test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st r
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/master/topic [new reference]
++ HEAD:refs/for/master/topic <OID-A>..<OID-B>
++ * HEAD:refs/changes/24/124/1 [new reference]
++ HEAD:refs/changes/25/125/1 <OID-A>..<OID-B>
+ Done
+ EOF
+ test_cmp expect actual &&
+@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh: test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd r
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/master/topic [new reference]
++ * HEAD:refs/changes/24/124/1 [new reference]
++ HEAD:refs/for/master/topic <OID-A>..<OID-B>
++ + HEAD:refs/changes/25/125/1 <OID-B>...<OID-A> (forced update)
+ Done
+ EOF
+ test_cmp expect actual &&
+@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh: test_expect_success "proc-receive: report ok and alt for the same ref (--porcela
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+ * HEAD:refs/for/master/topic [new reference]
++ HEAD:refs/changes/24/124/1 <OID-A>..<OID-B>
+ Done
+ EOF
+ test_cmp expect actual &&
+@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh: test_expect_success "proc-receive: report multiple response (--porcelain, $PROTO
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+- * HEAD:refs/for/master/topic [new reference]
++ * HEAD:refs/changes/23/123/1 [new reference]
++ HEAD:refs/changes/24/124/2 <OID-A>..<OID-B>
+ Done
+ EOF
+ test_cmp expect actual &&
+
+ ## t/t5411/test-0038-report-mixed-refs.sh ##
+@@ t/t5411/test-0038-report-mixed-refs.sh: test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
* [new branch] HEAD -> baz
* [new reference] HEAD -> refs/for/next/topic
* [new branch] HEAD -> foo
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update o
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
+ ## t/t5411/test-0039-report-mixed-refs--porcelain.sh ##
+@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh: test_expect_success "proc-receive: report update of mixed refs (--porcelain, $PR
+ * HEAD:refs/heads/baz [new branch]
+ * HEAD:refs/for/next/topic [new reference]
+ * HEAD:refs/heads/foo [new branch]
+- * HEAD:refs/for/master/topic [new reference]
++ HEAD:refs/for/master/topic <OID-A>..<OID-B>
+ Done
+ EOF
+ test_cmp expect actual &&
+
## transport-helper.c ##
@@ transport-helper.c: static int push_update_ref_status(struct strbuf *buf,
msg = xstrdup(msg);
@@ transport.c: static void print_ref_status(char flag, const char *summary,
+ if (to && to->remote_status) {
+ val = parse_feature_value(to->remote_status, "ref", &len);
+ if (val && len)
-+ to_name = xmemdupz(val, len);
++ to_name = xmemdupz(val, len);
+ }
+
if (porcelain) {
@@ transport.c: static int print_one_push_status(struct ref *ref, const char *dest,
+ porcelain, summary_width);
+
+ head = ref->remote_status;
-+ begin = strstr(head, "ref=");
-+ if (!begin)
-+ begin = ref->remote_status;
++ begin = head;
+ for (;;) {
+ char *end;
+ struct object_id old_oid;
-: ---------- > 5: c3ad1ab5a4 receive-pack: feed extended_status to post-receive
5: a8860faa17 = 6: d9226a4898 refs.c: refactor to reuse ref_is_hidden()
6: 46a839ddf6 ! 7: 7143e2c501 receive-pack: new config receive.procReceiveRefs
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
+ if (proc_receive_refs.nr > 0) {
+ struct strbuf refname_full = STRBUF_INIT;
+ size_t prefix_len;
-+
-+ strbuf_addstr(&refname_full, get_git_namespace());
-+ prefix_len = refname_full.len;
- /* TODO: replace the fixed prefix by looking up git config variables. */
- if (!strncmp(cmd->ref_name, "refs/for/", 9)) {
- cmd->run_proc_receive = RUN_PROC_RECEIVE_SCHEDULED;
- run_proc_receive = 1;
++ strbuf_addstr(&refname_full, get_git_namespace());
++ prefix_len = refname_full.len;
++
+ for (cmd = commands; cmd; cmd = cmd->next) {
+ if (!should_process_cmd(cmd))
+ continue;
@@ builtin/receive-pack.c: int cmd_receive_pack(int argc, const char **argv, const
return 0;
}
- ## t/t5411/common-test-cases.sh ##
-@@ t/t5411/common-test-cases.sh: test_expect_success "cleanup" '
- )
- '
-
+ ## t/t5411/test-0010-proc-receive-settings.sh (new) ##
+@@
+test_expect_success "add two receive.procReceiveRefs settings" '
+ (
+ cd "$upstream" &&
+ git config --add receive.procReceiveRefs refs/for &&
+ git config --add receive.procReceiveRefs refs/review/
+ )
++'
+
+ ## t/t5411/test-0040-process-all-refs.sh (new) ##
+@@
++test_expect_success "config receive.procReceiveRefs = refs ($PROTOCOL)" '
++ git -C "$upstream" config --unset-all receive.procReceiveRefs &&
++ git -C "$upstream" config --add receive.procReceiveRefs refs
+'
+
- # Refs of upstream : master(A)
- # Refs of workbench: master(A) tags/v123
- # git push : next(A) refs/for/master/topic(A)
-@@ t/t5411/common-test-cases.sh: test_expect_success "setup proc-receive hook (with extended status)" '
- write_script "$upstream/hooks/proc-receive" <<-EOF
- printf >&2 "# proc-receive hook\n"
- test-tool proc-receive -v \
-- -r "ok refs/for/a/b/c/topic" \
-+ -r "ok refs/review/a/b/c/topic" \
- -r "alt refs/for/next/topic refs/pull/123/head" \
- -r "alt refs/for/master/topic refs/pull/124/head old-oid=$B forced-update new-oid=$A"
- EOF
-@@ t/t5411/common-test-cases.sh: test_expect_success "setup proc-receive hook (with extended status)" '
-
- # Refs of upstream : master(A)
- # Refs of workbench: master(A) tags/v123
--# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+# git push : refs/for/next/topic(A) refs/review/a/b/c/topic(A) refs/for/master/topic(A)
- test_expect_success "proc-receive: report with extended status" '
- git -C workbench push origin \
- HEAD:refs/for/next/topic \
-- HEAD:refs/for/a/b/c/topic \
-+ HEAD:refs/review/a/b/c/topic \
- HEAD:refs/for/master/topic \
- >out 2>&1 &&
- make_user_friendly_and_stable_output <out >actual &&
- cat >expect <<-EOF &&
- remote: # pre-receive hook
- remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-- remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/review/a/b/c/topic
- remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
- remote: # proc-receive hook
- remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-- remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/review/a/b/c/topic
- remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-- remote: proc-receive> ok refs/for/a/b/c/topic
-+ remote: proc-receive> ok refs/review/a/b/c/topic
- remote: proc-receive> alt refs/for/next/topic refs/pull/123/head
- remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A>
- remote: # post-receive hook
- remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-- remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/a/b/c/topic
- remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
- To <URL/of/upstream.git>
- * [new reference] HEAD -> refs/pull/123/head
-- * [new reference] HEAD -> refs/for/a/b/c/topic
-+ * [new reference] HEAD -> refs/review/a/b/c/topic
- + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
- EOF
- test_cmp expect actual &&
-@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update of mixed refs" '
- EOF
- test_cmp expect actual
- '
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "setup upstream branches ($PROTOCOL)" '
++ (
++ cd "$upstream" &&
++ git update-ref refs/heads/master $B &&
++ git update-ref refs/heads/foo $A &&
++ git update-ref refs/heads/bar $A &&
++ git update-ref refs/heads/baz $A
++ )
+
-+test_expect_success "config add receive.procReceiveRefs = refs" '
-+ git -C "$upstream" config --add receive.procReceiveRefs refs
+'
+
-+test_expect_success "setup proc-receive hook" '
++test_expect_success "setup proc-receive hook ($PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update o
+# Refs of upstream : master(B) foo(A) bar(A)) baz(A)
+# Refs of workbench: master(A) tags/v123
+# git push -f : master(A) (NULL) (B) refs/for/master/topic(A) refs/for/next/topic(A)
-+test_expect_success "proc-receive: process all refs" '
++test_expect_success "proc-receive: process all refs ($PROTOCOL)" '
+ git -C workbench push -f origin \
+ HEAD:refs/heads/master \
+ :refs/heads/foo \
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update o
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/bar
+ remote: post-receive< <COMMIT-A> <ZERO-OID> refs/heads/foo
+ remote: post-receive< <COMMIT-B> <COMMIT-A> refs/heads/master
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head
++ remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
+ To <URL/of/upstream.git>
+ <OID-A>..<OID-B> <COMMIT-B> -> bar
+ - [deleted] foo
@@ t/t5411/common-test-cases.sh: test_expect_success "proc-receive: report update o
+ EOF
+ test_cmp expect actual
+'
++
++# Refs of upstream : master(A) bar(A) baz(B)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ (
++ cd "$upstream" &&
++ git update-ref -d refs/heads/bar &&
++ git update-ref -d refs/heads/baz
++ )
++'
+
+ ## t/t5411/test-0041-process-all-refs--porcelain.sh (new) ##
+@@
++test_expect_success "config receive.procReceiveRefs = refs ($PROTOCOL)" '
++ git -C "$upstream" config --unset-all receive.procReceiveRefs &&
++ git -C "$upstream" config --add receive.procReceiveRefs refs
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "setup upstream branches ($PROTOCOL)" '
++ (
++ cd "$upstream" &&
++ git update-ref refs/heads/master $B &&
++ git update-ref refs/heads/foo $A &&
++ git update-ref refs/heads/bar $A &&
++ git update-ref refs/heads/baz $A
++ )
++
++'
++
++test_expect_success "setup proc-receive hook ($PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ft refs/heads/master" \
++ -r "ft refs/heads/foo" \
++ -r "ft refs/heads/bar" \
++ -r "alt refs/for/master/topic refs/pull/123/head old-oid=$A new-oid=$B " \
++ -r "alt refs/for/next/topic refs/pull/124/head old-oid=$B new-oid=$A forced-update"
++ EOF
++'
++
++# Refs of upstream : master(B) foo(A) bar(A)) baz(A)
++# Refs of workbench: master(A) tags/v123
++# git push -f : master(A) (NULL) (B) refs/for/master/topic(A) refs/for/next/topic(A)
++test_expect_success "proc-receive: process all refs (--porcelain) ($PROTOCOL)" '
++ git -C workbench push --porcelain -f origin \
++ HEAD:refs/heads/master \
++ :refs/heads/foo \
++ $B:refs/heads/bar \
++ HEAD:refs/for/master/topic \
++ HEAD:refs/for/next/topic \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/bar
++ remote: pre-receive< <COMMIT-A> <ZERO-OID> refs/heads/foo
++ remote: pre-receive< <COMMIT-B> <COMMIT-A> refs/heads/master
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: # proc-receive hook
++ remote: proc-receive< <COMMIT-A> <COMMIT-B> refs/heads/bar
++ remote: proc-receive< <COMMIT-A> <ZERO-OID> refs/heads/foo
++ remote: proc-receive< <COMMIT-B> <COMMIT-A> refs/heads/master
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: proc-receive> ft refs/heads/master
++ remote: proc-receive> ft refs/heads/foo
++ remote: proc-receive> ft refs/heads/bar
++ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> alt refs/for/next/topic refs/pull/124/head old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update
++ remote: # post-receive hook
++ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/bar
++ remote: post-receive< <COMMIT-A> <ZERO-OID> refs/heads/foo
++ remote: post-receive< <COMMIT-B> <COMMIT-A> refs/heads/master
++ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head
++ remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
++ To <URL/of/upstream.git>
++ <COMMIT-B>:refs/heads/bar <OID-A>..<OID-B>
++ - :refs/heads/foo [deleted]
++ + HEAD:refs/heads/master <OID-B>...<OID-A> (forced update)
++ HEAD:refs/pull/123/head <OID-A>..<OID-B>
++ + HEAD:refs/pull/124/head <OID-B>...<OID-A> (forced update)
++ Done
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-B> refs/heads/bar
++ <COMMIT-A> refs/heads/baz
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(A) bar(A) baz(B)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup ($PROTOCOL)" '
++ (
++ cd "$upstream" &&
++ git update-ref -d refs/heads/bar &&
++ git update-ref -d refs/heads/baz
++ )
++'7: a357234e97 = 8: 98702cf3e9 doc: add documentation for the proc-receive hook
---
Jiang Xin (8):
transport: not report a non-head push as a branch
connect: export parse_feature_value()
receive-pack: add new proc-receive hook
send-pack: extension for client-side status report
receive-pack: feed extended_status to post-receive refs.c: refactor to reuse ref_is_hidden()
receive-pack: new config receive.procReceiveRefs
doc: add documentation for the proc-receive hook
Documentation/config/receive.txt | 14 + Documentation/githooks.txt | 58 +++ Makefile | 1 + builtin/receive-pack.c | 442 +++++++++++++++++- connect.c | 3 +- connect.h | 1 + refs.c | 13 +- refs.h | 1 + remote.c | 21 + remote.h | 3 + send-pack.c | 11 +- t/helper/test-proc-receive.c | 175 +++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411-proc-receive-hook.sh | 105 +++++ t/t5411/common-functions.sh | 56 +++ t/t5411/test-0000-standard-git-push.sh | 84 ++++ .../test-0001-standard-git-push--porcelain.sh | 87 ++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++ t/t5411/test-0010-proc-receive-settings.sh | 7 + t/t5411/test-0011-no-hook-error.sh | 64 +++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 +++ t/t5411/test-0013-bad-protocol.sh | 225 +++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 +++++++ t/t5411/test-0020-report-ng.sh | 67 +++ t/t5411/test-0021-report-ng--porcelain.sh | 69 +++ t/t5411/test-0022-report-unexpect-ref.sh | 45 ++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 ++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 ++++ t/t5411/test-0027-push-options--porcelain.sh | 82 ++++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-alt.sh | 229 +++++++++ t/t5411/test-0033-report-alt--porcelain.sh | 236 ++++++++++ t/t5411/test-0034-report-ft.sh | 42 ++ t/t5411/test-0035-report-ft--porcelain.sh | 43 ++ .../test-0036-report-multi-alt-for-one-ref.sh | 167 +++++++ ...report-multi-alt-for-one-ref--porcelain.sh | 171 +++++++ t/t5411/test-0038-report-mixed-refs.sh | 74 +++ .../test-0039-report-mixed-refs--porcelain.sh | 75 +++ t/t5411/test-0040-process-all-refs.sh | 93 ++++ .../test-0041-process-all-refs--porcelain.sh | 94 ++++ t/t5516-fetch-push.sh | 2 +- transport-helper.c | 64 +-- transport.c | 83 +++- 48 files changed, 3506 insertions(+), 61 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-alt.sh create mode 100644 t/t5411/test-0033-report-alt--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-alt-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh
PATCH v13 2/8 connect: export parse_feature_value()
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Export parse_feature_value() to parse extended status of report for "proc-receive" and "receive-pack".
--- connect.c | 3 +-- connect.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)
connect.c +1 -2
@@ -18,7 +18,6 @@static char *server_capabilities_v1;static struct argv_array server_capabilities_v2 =ARGV_ARRAY_INIT ; -static const char *parse_feature_value (const char *,const char *,int *);static int check_ref (const char *name,unsigned int flags) {
@@ -447,7 +446,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,return list; } -static const char *parse_feature_value (const char *feature_list,const char *feature,int *lenp) +const char *parse_feature_value (const char *feature_list,const char *feature,int *lenp) {int len;
connect.h +1 -0
@@ -12,6 +12,7 @@ int finish_connect(struct child_process *conn);int git_connection_is_socket (struct child_process *conn);int server_supports (const char *feature);int parse_feature_request (const char *features,const char *feature); +const char *parse_feature_value (const char *feature_list,const char *feature,int *len_ret);const char *server_feature_value (const char *feature,int *len_ret);int url_is_local_not_ssh (const char *url);
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v13 3/8 receive-pack: add new proc-receive hook
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Git calls an internal execute_commands function to handle commands sent from client to git-receive-pack. Regardless of what references the user pushes, git creates or updates the corresponding references if the user has write-permission. A contributor who has no write-permission, cannot push to the repository directly. So, the contributor has to write commits to an alternate location, and sends pull request by emails or by other ways. We call this workflow as a distributed workflow.
It would be more convenient to work in a centralized workflow like what Gerrit provided for some cases. For example, a read-only user who cannot push to a branch directly can run the following git push command to push commits to a pseudo reference (has a prefix "refs/for/", not "refs/heads/") to create a code review.
git push origin \
HEAD:refs/for/<branch-name>/<session>The <branch-name> in the above example can be as simple as "master", or a more complicated branch name like "foo/bar". The <session> in the above example command can be the local branch name of the client side, such as "my/topic".
We cannot implement a centralized workflow elegantly by using "pre-receive" + "post-receive", because Git will call the internal function "execute_commands" to create references (even the special pseudo reference) between these two hooks. Even though we can delete the temporarily created pseudo reference via the "post-receive" hook, having a temporary reference is not safe for concurrent pushes.
So, add a filter and a new handler to support this kind of workflow. The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (run_proc_receive) on for the command. Commands with this filed turned on will be executed by a new handler (an hook named "proc-receive") instead of the internal execute_commands function. We can use this "proc-receive" command to create pull requests or send emails for code review.
Suggested by Junio, this "proc-receive" hook reads the commands, push-options (optional), and send result using a protocol in pkt-line format. In the following example, The letter "S" stands for "receive-pack" and letter "H" stands for the hook.
# Version and features negotiation.
S: PKT-LINE(version=1\0push-options atomic...)
S: flush-pkt
H: PKT-LINE(version=1\0push-options...)
H: flush-pkt
# Send commands from server to the hook.
S: PKT-LINE(<old-oid> <new-oid> <ref>)
S: ... ...
S: flush-pkt
# Send push-options only if the 'push-options' feature is enabled.
S: PKT-LINE(push-option)
S: ... ...
S: flush-pkt
# Receive result from the hook.
# OK, run this command successfully.
H: PKT-LINE(ok <ref>)
# NO, I reject it.
H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
H: PKT-LINE(ft <ref>)
# OK, but has an alternate reference. The alternate reference name # is given in the third parameter, and other status can be given in # key-value pairs.
H: PKT-LINE(alt <ref> <alt-ref> old-oid=<old-oid> new-oid=<new-oid>
forced-update)
H: ... ...
H: flush-pkt
After receiving a command, the hook will execute the command, and may create/update different reference. For example, a command for a pseudo reference "refs/for/master/topic" may create/update different reference such as "refs/pull/123/head". The alternate reference name and other status are given in key-value pairs as extended status of the report line.
The list of commands returned from "proc-receive" will replace the relevant commands that are sent from user to "receive-pack", and "receive-pack" will continue to run the "execute_commands" function and other routines. Finally, the result of the execution of these commands will be reported to end user.
The reporting function from "receive-pack" to "send-pack" is extended using a backward compatible way by adding key-value pairs after an null character, like:
# OK, run this command successfully with optional extended-status. ok <reference>\0ref=refs/pull/123/head old-oid=...
# NO, I reject it.
ng <reference> <error message>
Parsing the extended status of the report lines for "send-pack" is not implemented in this commit, so we can make a compatible test on old version of a Git client.
--- Makefile | 1 + builtin/receive-pack.c | 356 +++++++++++++++++- t/helper/test-proc-receive.c | 175 +++++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411/test-0011-no-hook-error.sh | 64 ++++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 ++++ t/t5411/test-0013-bad-protocol.sh | 225 +++++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++++ t/t5411/test-0020-report-ng.sh | 67 ++++ t/t5411/test-0021-report-ng--porcelain.sh | 69 ++++ t/t5411/test-0022-report-unexpect-ref.sh | 45 +++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 +++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 ++++ t/t5411/test-0027-push-options--porcelain.sh | 82 ++++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-alt.sh | 229 +++++++++++ t/t5411/test-0033-report-alt--porcelain.sh | 236 ++++++++++++ t/t5411/test-0034-report-ft.sh | 42 +++ t/t5411/test-0035-report-ft--porcelain.sh | 43 +++ .../test-0036-report-multi-alt-for-one-ref.sh | 155 ++++++++ ...report-multi-alt-for-one-ref--porcelain.sh | 159 ++++++++ t/t5411/test-0038-report-mixed-refs.sh | 74 ++++ .../test-0039-report-mixed-refs--porcelain.sh | 75 ++++ 27 files changed, 2581 insertions(+), 9 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-alt.sh create mode 100644 t/t5411/test-0033-report-alt--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-alt-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh
Makefile +1 -0
@@ -725,6 +725,7 @@ TEST_BUILTINS_OBJS += test-parse-pathspec-file.o TEST_BUILTINS_OBJS += test-path-utils.o TEST_BUILTINS_OBJS += test-pkt-line.o TEST_BUILTINS_OBJS += test-prio-queue.o +TEST_BUILTINS_OBJS += test-proc-receive.o TEST_BUILTINS_OBJS += test-progress.o TEST_BUILTINS_OBJS += test-reach.o TEST_BUILTINS_OBJS += test-read-cache.o
builtin/receive-pack.c +347 -9
408 lines not on this page · raw message
t/helper/test-proc-receive.c new file +175 -0
175 lines not on this page · raw message
t/helper/test-tool.c +1 -0
@@ -44,6 +44,7 @@ static struct test_cmd cmds[] = { { "path-utils", cmd__path_utils }, { "pkt-line", cmd__pkt_line }, { "prio-queue", cmd__prio_queue }, + { "proc-receive", cmd__proc_receive}, { "progress", cmd__progress }, { "reach", cmd__reach }, { "read-cache", cmd__read_cache },
t/helper/test-tool.h +1 -0
@@ -34,6 +34,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);int cmd__path_utils (int argc,const char **argv);int cmd__pkt_line (int argc,const char **argv);int cmd__prio_queue (int argc,const char **argv); +int cmd__proc_receive (int argc,const char **argv);int cmd__progress (int argc,const char **argv);int cmd__reach (int argc,const char **argv);int cmd__read_cache (int argc,const char **argv);
t/t5411/test-0011-no-hook-error.sh new file +64 -0
64 lines not on this page · raw message
t/t5411/test-0012-no-hook-error--porcelain.sh new file +66 -0
66 lines not on this page · raw message
t/t5411/test-0013-bad-protocol.sh new file +225 -0
225 lines not on this page · raw message
t/t5411/test-0014-bad-protocol--porcelain.sh new file +160 -0
160 lines not on this page · raw message
t/t5411/test-0020-report-ng.sh new file +67 -0
67 lines not on this page · raw message
t/t5411/test-0021-report-ng--porcelain.sh new file +69 -0
69 lines not on this page · raw message
t/t5411/test-0022-report-unexpect-ref.sh new file +45 -0
45 lines not on this page · raw message
t/t5411/test-0023-report-unexpect-ref--porcelain.sh new file +46 -0
46 lines not on this page · raw message
t/t5411/test-0024-report-unknown-ref.sh new file +34 -0
@@ -0,0 +1,34 @@ +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/a/b/c/my/topic +test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/a/b/c/my/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: proc-receive> ok refs/for/master/topic + remote: error: proc-receive reported status on unknown ref: refs/for/master/topic + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status) + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0025-report-unknown-ref--porcelain.sh new file +35 -0
@@ -0,0 +1,35 @@ +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/a/b/c/my/topic +test_expect_success "proc-receive: report unknown reference (--porcelain, $PROTOCOL)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/a/b/c/my/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: proc-receive> ok refs/for/master/topic + remote: error: proc-receive reported status on unknown ref: refs/for/master/topic + To <URL/of/upstream.git> + ! HEAD:refs/for/a/b/c/my/topic [remote rejected] (proc-receive failed to report status) + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0026-push-options.sh new file +79 -0
79 lines not on this page · raw message
t/t5411/test-0027-push-options--porcelain.sh new file +82 -0
82 lines not on this page · raw message
t/t5411/test-0030-report-ok.sh new file +35 -0
@@ -0,0 +1,35 @@ +test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/master/topic +test_expect_success "proc-receive: ok ($PROTOCOL)" ' + git -C workbench push origin \ + HEAD:refs/for/master/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: proc-receive> ok refs/for/master/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + To <URL/of/upstream.git> + * [new reference] HEAD -> refs/for/master/topic + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0031-report-ok--porcelain.sh new file +36 -0
@@ -0,0 +1,36 @@ +test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/master/topic +test_expect_success "proc-receive: ok (--porcelain, $PROTOCOL)" ' + git -C workbench push --porcelain origin \ + HEAD:refs/for/master/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: proc-receive> ok refs/for/master/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + To <URL/of/upstream.git> + * HEAD:refs/for/master/topic [new reference] + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0032-report-alt.sh new file +229 -0
229 lines not on this page · raw message
t/t5411/test-0033-report-alt--porcelain.sh new file +236 -0
236 lines not on this page · raw message
t/t5411/test-0034-report-ft.sh new file +42 -0
42 lines not on this page · raw message
t/t5411/test-0035-report-ft--porcelain.sh new file +43 -0
43 lines not on this page · raw message
t/t5411/test-0036-report-multi-alt-for-one-ref.sh new file +155 -0
155 lines not on this page · raw message
t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh new file +159 -0
159 lines not on this page · raw message
t/t5411/test-0038-report-mixed-refs.sh new file +74 -0
74 lines not on this page · raw message
t/t5411/test-0039-report-mixed-refs--porcelain.sh new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v13 4/8 send-pack: extension for client-side status report
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
This is the client-side extension for status report of git-push.
The "proc-receive" hook may receive a command for a pseudo-reference with a zero-old as its old-oid, while the result of the hook may point to an alternate reference and the reference may exist already with a non-zero old-oid. Git client may receive a report with extened status as the following example:
ok refs/for/master/topic\0ref=refs/pull/123/head old-oid=...
Parse the key-value pairs in the extended status after the null character of the report, and show the proper reference name, old-oid and new-oid to the user.
--- remote.c | 21 ++++++ remote.h | 3 + send-pack.c | 11 ++- t/t5411/test-0032-report-alt.sh | 14 ++-- t/t5411/test-0033-report-alt--porcelain.sh | 14 ++-- .../test-0036-report-multi-alt-for-one-ref.sh | 12 ++- ...report-multi-alt-for-one-ref--porcelain.sh | 12 ++- t/t5411/test-0038-report-mixed-refs.sh | 2 +- .../test-0039-report-mixed-refs--porcelain.sh | 2 +- transport-helper.c | 64 ++++++++-------- transport.c | 74 +++++++++++++++++-- 11 files changed, 169 insertions(+), 60 deletions(-)
remote.c +21 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "config.h" +#include "connect.h" #include "remote.h" #include "refs.h" #include "refspec.h"
@@ -2311,3 +2312,23 @@ void apply_push_cas(struct push_cas_option *cas,for (ref = remote_refs; ref; ref = ref->next)apply_cas (cas, remote, ref); } + +void update_ref_from_remote_status (struct ref *ref) +{ +char *val; +int len; + +if (!ref->remote_status) +return ; + + val = (char *)parse_feature_value (ref->remote_status,"old-oid" , &len); +if (val && len) +get_oid_hex (val, &ref->old_oid); + + val = (char *)parse_feature_value (ref->remote_status,"new-oid" , &len); +if (val && len) +get_oid_hex (val, &ref->new_oid); + +if (parse_feature_request (ref->remote_status,"forced-update" )) + ref->forced_update =1 ; +}
remote.h +3 -0
@@ -345,4 +345,7 @@ int parseopt_push_cas_option(const struct option *, const char *arg, int unset);int is_empty_cas (const struct push_cas_option *);void apply_push_cas (struct push_cas_option *,struct remote *,struct ref *); +/* Parse key-value pairs of remote_status and update the reference accordingly */ +void update_ref_from_remote_status (struct ref *ref); +#endif
send-pack.c +10 -1
@@ -159,6 +159,9 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)while (1 ) {const char *refname;char *msg; +char *extended_status =NULL ; +int len; +if (packet_reader_read (reader) !=PACKET_READ_NORMAL )break ;if (!starts_with (reader->line,"ok " ) && !starts_with (reader->line,"ng " )) {
@@ -167,10 +170,13 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)break ; } + len =strlen (reader->line); refname = reader->line +3 ; msg =strchr (refname,' ' );if (msg) *msg++ ='\0' ; +if (reader->pktlen > len) + extended_status = (char *)reader->line + len +1 ;/* first try searching at our hint, falling back to all refs */ if (hint)
@@ -192,7 +198,10 @@ static int receive_status(struct packet_reader *reader, struct ref *refs) hint->status =REF_STATUS_OK ; else hint->status = REF_STATUS_REMOTE_REJECT; - hint->remote_status =xstrdup_or_null (msg); +if (msg) + hint->remote_status =xstrdup (msg); +else if (extended_status) + hint->remote_status =xstrdup_or_null (extended_status);/* start our next search from the next ref */ hint = hint->next; }
t/t5411/test-0032-report-alt.sh +7 -7
@@ -52,7 +52,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, $PROTOCOL)" remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/pull/123/head EOF test_cmp expect actual '
@@ -82,7 +82,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/pull/123/head EOF test_cmp expect actual '
@@ -112,7 +112,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, $P remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + <OID-B>..<OID-A> HEAD -> refs/pull/123/head EOF test_cmp expect actual '
@@ -142,7 +142,7 @@ test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, $PROTOCOL)" remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + <OID-B>..<OID-A> HEAD -> refs/for/master/topic EOF test_cmp expect actual '
@@ -172,7 +172,7 @@ test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, $P remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + <OID-A>..<OID-B> HEAD -> refs/for/master/topic EOF test_cmp expect actual '
@@ -214,9 +214,9 @@ test_expect_success "proc-receive: with multiple alt reports ($PROTOCOL)" ' remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/next/topic + * [new reference] HEAD -> refs/pull/123/head * [new reference] HEAD -> refs/for/a/b/c/topic - * [new reference] HEAD -> refs/for/master/topic + + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update) EOF test_cmp expect actual &&
t/t5411/test-0033-report-alt--porcelain.sh +7 -7
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, --porcelain, remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + * HEAD:refs/pull/123/head [new reference] Done EOF test_cmp expect actual
@@ -84,7 +84,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + * HEAD:refs/pull/123/head [new reference] Done EOF test_cmp expect actual
@@ -115,7 +115,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, -- remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/pull/123/head <OID-B>..<OID-A> Done EOF test_cmp expect actual
@@ -146,7 +146,7 @@ test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, --porcelain, remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/for/master/topic <OID-B>..<OID-A> Done EOF test_cmp expect actual
@@ -177,7 +177,7 @@ test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, -- remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/for/master/topic <OID-A>..<OID-B> Done EOF test_cmp expect actual
@@ -220,9 +220,9 @@ test_expect_success "proc-receive: with multiple alt reports (--porcelain, $PROT remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/next/topic [new reference] + * HEAD:refs/pull/123/head [new reference] * HEAD:refs/for/a/b/c/topic [new reference] - * HEAD:refs/for/master/topic [new reference] + + HEAD:refs/pull/124/head <OID-B>...<OID-A> (forced update) Done EOF test_cmp expect actual &&
t/t5411/test-0036-report-multi-alt-for-one-ref.sh +9 -3
@@ -27,7 +27,9 @@ test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st r remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + <OID-A>..<OID-B> HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/changes/24/124/1 + <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1 EOF test_cmp expect actual && git -C "$upstream" show-ref >out &&
@@ -67,7 +69,9 @@ test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd r remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/changes/24/124/1 + <OID-A>..<OID-B> HEAD -> refs/for/master/topic + + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update) EOF test_cmp expect actual && git -C "$upstream" show-ref >out &&
@@ -106,6 +110,7 @@ test_expect_success "proc-receive: report ok and alt for the same ref ($PROTOCOL remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> * [new reference] HEAD -> refs/for/master/topic + <OID-A>..<OID-B> HEAD -> refs/changes/24/124/1 EOF test_cmp expect actual && git -C "$upstream" show-ref >out &&
@@ -143,7 +148,8 @@ test_expect_success "proc-receive: report multiple response ($PROTOCOL)" ' remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/changes/23/123/1 + <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2 EOF test_cmp expect actual && git -C "$upstream" show-ref >out &&
t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh +9 -3
@@ -27,7 +27,9 @@ test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st r remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/for/master/topic <OID-A>..<OID-B> + * HEAD:refs/changes/24/124/1 [new reference] + HEAD:refs/changes/25/125/1 <OID-A>..<OID-B> Done EOF test_cmp expect actual &&
@@ -68,7 +70,9 @@ test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd r remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + * HEAD:refs/changes/24/124/1 [new reference] + HEAD:refs/for/master/topic <OID-A>..<OID-B> + + HEAD:refs/changes/25/125/1 <OID-B>...<OID-A> (forced update) Done EOF test_cmp expect actual &&
@@ -108,6 +112,7 @@ test_expect_success "proc-receive: report ok and alt for the same ref (--porcela remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> * HEAD:refs/for/master/topic [new reference] + HEAD:refs/changes/24/124/1 <OID-A>..<OID-B> Done EOF test_cmp expect actual &&
@@ -146,7 +151,8 @@ test_expect_success "proc-receive: report multiple response (--porcelain, $PROTO remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + * HEAD:refs/changes/23/123/1 [new reference] + HEAD:refs/changes/24/124/2 <OID-A>..<OID-B> Done EOF test_cmp expect actual &&
t/t5411/test-0038-report-mixed-refs.sh +1 -1
@@ -46,7 +46,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" ' * [new branch] HEAD -> baz * [new reference] HEAD -> refs/for/next/topic * [new branch] HEAD -> foo - * [new reference] HEAD -> refs/for/master/topic + <OID-A>..<OID-B> HEAD -> refs/for/master/topic EOF test_cmp expect actual && git -C "$upstream" show-ref >out &&
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
@@ -46,7 +46,7 @@ test_expect_success "proc-receive: report update of mixed refs (--porcelain, $PR * HEAD:refs/heads/baz [new branch] * HEAD:refs/for/next/topic [new reference] * HEAD:refs/heads/foo [new branch] - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/for/master/topic <OID-A>..<OID-B> Done EOF test_cmp expect actual &&
transport-helper.c +33 -31
70 lines not on this page · raw message
transport.c +68 -6
108 lines not on this page · raw message
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v13 5/8 receive-pack: feed extended_status to post-receive
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
When commands are fed to the "post-receive" hook, extended_status will be parsed and the real old-oid, new-oid, reference name will feed to the "post-receive" hook.
--- builtin/receive-pack.c | 57 +++++++++++++++++-- t/t5411/test-0032-report-alt.sh | 14 ++--- t/t5411/test-0033-report-alt--porcelain.sh | 14 ++--- .../test-0036-report-multi-alt-for-one-ref.sh | 12 +++- ...report-multi-alt-for-one-ref--porcelain.sh | 12 +++- t/t5411/test-0038-report-mixed-refs.sh | 2 +- .../test-0039-report-mixed-refs--porcelain.sh | 2 +- 7 files changed, 87 insertions(+), 26 deletions(-)
builtin/receive-pack.c +53 -4
@@ -754,17 +754,66 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) {struct receive_hook_feed_state *state = state_;struct command *cmd = state->cmd; +static char *extended_status =NULL ;while (cmd && state->skip_broken && (cmd->error_string || cmd->did_not_exist)) cmd = cmd->next;if (!cmd)return -1 ;/* EOF */ +if (!bufp) +return 0 ;/* OK, can feed something. */ strbuf_reset (&state->buf); -strbuf_addf (&state->buf,"%s %s %s\n" , -oid_to_hex (&cmd->old_oid),oid_to_hex (&cmd->new_oid), - cmd->ref_name); - state->cmd = cmd->next; +if (cmd->extended_status && extended_status ==NULL ) + extended_status = (char *)cmd->extended_status; +if (extended_status) { +struct object_id old_oid; +struct object_id new_oid; +char *end; +char *val; +int len; + + end =strstr (extended_status +4 ,"ref=" ); +if (end) + *(end-1 ) ='\0' ; + + val = (char *)parse_feature_value (extended_status,"old-oid" , &len); +if (val && len && !get_oid_hex (val, &old_oid)) +strbuf_addf (&state->buf,"%s " , +oid_to_hex (&old_oid)); +else +strbuf_addf (&state->buf,"%s " , +oid_to_hex (&cmd->old_oid)); + + val = (char *)parse_feature_value (extended_status,"new-oid" , &len); +if (val && len && !get_oid_hex (val, &new_oid)) +strbuf_addf (&state->buf,"%s " , +oid_to_hex (&new_oid)); +else +strbuf_addf (&state->buf,"%s " , +oid_to_hex (&cmd->new_oid)); + + val = (char *)parse_feature_value (extended_status,"ref" , &len); +if (val && len) +strbuf_add (&state->buf, val, len); +else +strbuf_addstr (&state->buf, cmd->ref_name); + +strbuf_addch (&state->buf,'\n' ); + +if (end) { + extended_status = end; + *(end-1 ) =' ' ; + }else { + extended_status =NULL ; + state->cmd = cmd->next; + } + }else { +strbuf_addf (&state->buf,"%s %s %s\n" , +oid_to_hex (&cmd->old_oid),oid_to_hex (&cmd->new_oid), + cmd->ref_name); + state->cmd = cmd->next; + }if (bufp) { *bufp = state->buf.buf; *sizep = state->buf.len;
t/t5411/test-0032-report-alt.sh +7 -7
@@ -50,7 +50,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, $PROTOCOL)" remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic refs/pull/123/head remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> * [new reference] HEAD -> refs/pull/123/head EOF
@@ -80,7 +80,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic refs/pull/123/head forced-update remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> * [new reference] HEAD -> refs/pull/123/head EOF
@@ -110,7 +110,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, $P remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> <OID-B>..<OID-A> HEAD -> refs/pull/123/head EOF
@@ -140,7 +140,7 @@ test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, $PROTOCOL)" remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> <OID-B>..<OID-A> HEAD -> refs/for/master/topic EOF
@@ -170,7 +170,7 @@ test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, $P remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic To <URL/of/upstream.git> <OID-A>..<OID-B> HEAD -> refs/for/master/topic EOF
@@ -210,9 +210,9 @@ test_expect_success "proc-receive: with multiple alt reports ($PROTOCOL)" ' remote: proc-receive> alt refs/for/next/topic refs/pull/123/head remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head To <URL/of/upstream.git> * [new reference] HEAD -> refs/pull/123/head * [new reference] HEAD -> refs/for/a/b/c/topic
t/t5411/test-0033-report-alt--porcelain.sh +7 -7
@@ -51,7 +51,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, --porcelain, remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic refs/pull/123/head remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> * HEAD:refs/pull/123/head [new reference] Done
@@ -82,7 +82,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic refs/pull/123/head forced-update remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> * HEAD:refs/pull/123/head [new reference] Done
@@ -113,7 +113,7 @@ test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, -- remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> HEAD:refs/pull/123/head <OID-B>..<OID-A> Done
@@ -144,7 +144,7 @@ test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, --porcelain, remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> HEAD:refs/for/master/topic <OID-B>..<OID-A> Done
@@ -175,7 +175,7 @@ test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, -- remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic To <URL/of/upstream.git> HEAD:refs/for/master/topic <OID-A>..<OID-B> Done
@@ -216,9 +216,9 @@ test_expect_success "proc-receive: with multiple alt reports (--porcelain, $PROT remote: proc-receive> alt refs/for/next/topic refs/pull/123/head remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head To <URL/of/upstream.git> * HEAD:refs/pull/123/head [new reference] * HEAD:refs/for/a/b/c/topic [new reference]
t/t5411/test-0036-report-multi-alt-for-one-ref.sh +9 -3
@@ -25,7 +25,9 @@ test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st r remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A> remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-A> new-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1 To <URL/of/upstream.git> <OID-A>..<OID-B> HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/changes/24/124/1
@@ -67,7 +69,9 @@ test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd r remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B> remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1 To <URL/of/upstream.git> * [new reference] HEAD -> refs/changes/24/124/1 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
@@ -108,6 +112,7 @@ test_expect_success "proc-receive: report ok and alt for the same ref ($PROTOCOL remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 new-oid=<COMMIT-B> old-oid=<COMMIT-A> remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/1 To <URL/of/upstream.git> * [new reference] HEAD -> refs/for/master/topic <OID-A>..<OID-B> HEAD -> refs/changes/24/124/1
@@ -146,7 +151,8 @@ test_expect_success "proc-receive: report multiple response ($PROTOCOL)" ' remote: proc-receive> alt refs/for/master/topic refs/changes/23/123/1 remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/2 old-oid=<COMMIT-A> new-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2 To <URL/of/upstream.git> * [new reference] HEAD -> refs/changes/23/123/1 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh +9 -3
@@ -25,7 +25,9 @@ test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st r remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A> remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-A> new-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1 To <URL/of/upstream.git> HEAD:refs/for/master/topic <OID-A>..<OID-B> * HEAD:refs/changes/24/124/1 [new reference]
@@ -68,7 +70,9 @@ test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd r remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B> remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1 To <URL/of/upstream.git> * HEAD:refs/changes/24/124/1 [new reference] HEAD:refs/for/master/topic <OID-A>..<OID-B>
@@ -110,6 +114,7 @@ test_expect_success "proc-receive: report ok and alt for the same ref (--porcela remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 new-oid=<COMMIT-B> old-oid=<COMMIT-A> remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/1 To <URL/of/upstream.git> * HEAD:refs/for/master/topic [new reference] HEAD:refs/changes/24/124/1 <OID-A>..<OID-B>
@@ -149,7 +154,8 @@ test_expect_success "proc-receive: report multiple response (--porcelain, $PROTO remote: proc-receive> alt refs/for/master/topic refs/changes/23/123/1 remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/2 old-oid=<COMMIT-A> new-oid=<COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2 To <URL/of/upstream.git> * HEAD:refs/changes/23/123/1 [new reference] HEAD:refs/changes/24/124/2 <OID-A>..<OID-B>
t/t5411/test-0038-report-mixed-refs.sh +1 -1
@@ -39,7 +39,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" ' remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic To <URL/of/upstream.git> <OID-A>..<OID-B> <COMMIT-B> -> master * [new branch] HEAD -> bar
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
@@ -39,7 +39,7 @@ test_expect_success "proc-receive: report update of mixed refs (--porcelain, $PR remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic To <URL/of/upstream.git> <COMMIT-B>:refs/heads/master <OID-A>..<OID-B> * HEAD:refs/heads/bar [new branch]
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v13 6/8 refs.c: refactor to reuse ref_is_hidden()
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Add new function ref_is_matched() to reuse ref_is_hidden(). Will use this function for receive-pack to check commands with specific prefixes.
Test case t5512 covered this change.
--- refs.c | 13 +++++++++---- refs.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-)
refs.c +9 -4
@@ -1388,14 +1388,14 @@ int parse_hide_refs_config(const char *var, const char *value, const char *sectireturn 0 ; } -int ref_is_hidden (const char *refname,const char *refname_full) +int ref_matches (struct string_list *match_refs,const char *refname,const char *refname_full) {int i; -if (!hide_refs) +if (!match_refs)return 0 ; -for (i = hide_refs->nr -1 ; i >=0 ; i--) { -const char *match = hide_refs->items[i].string; +for (i = match_refs->nr -1 ; i >=0 ; i--) { +const char *match = match_refs->items[i].string;const char *subject;int neg =0 ;const char *p;
@@ -1421,6 +1421,11 @@ int ref_is_hidden(const char *refname, const char *refname_full)return 0 ; } +int ref_is_hidden (const char *refname,const char *refname_full) +{ +return ref_matches (hide_refs, refname, refname_full); +} +const char *find_descendant_ref (const char *dirname,const struct string_list *extras,const struct string_list *skip)
refs.h +1 -0
@@ -739,6 +739,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *);* parameter always points to the full ref name. */ int ref_is_hidden (const char *,const char *); +int ref_matches (struct string_list *,const char *,const char *);enum ref_type {REF_TYPE_PER_WORKTREE ,/* refs inside refs/ but not shared */
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v13 7/8 receive-pack: new config receive.procReceiveRefs
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Add a new multi-valued config variable "receive.procReceiveRefs" for receive-pack command, like the follows:
git config --system --add receive.procReceiveRefs refs/for
git config --system --add receive.procReceiveRefs refs/draftsIf the specific prefix strings match the reference names of the commands which are sent from git client to receive-pack, these commands will be executed by an external hook (named "proc-receive"), instead of the internal execute_commands function.
For example, if it is set to "refs/for", pushing to a reference such as "refs/for/master" will not create or update reference "refs/for/master", but may create or update a pull request directly by running the hook "proc-receive".
--- Documentation/config/receive.txt | 14 +++ builtin/receive-pack.c | 43 +++++++-- t/t5411/test-0010-proc-receive-settings.sh | 7 ++ t/t5411/test-0040-process-all-refs.sh | 93 ++++++++++++++++++ .../test-0041-process-all-refs--porcelain.sh | 94 +++++++++++++++++++ 5 files changed, 244 insertions(+), 7 deletions(-) create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh
Documentation/config/receive.txt +14 -0
@@ -114,6 +114,20 @@ receive.hideRefs:: An attempt to update or delete a hidden ref by `git push` is rejected. +receive.procReceiveRefs:: + This is a multi-valued variable that defines reference prefixes + to match the commands in `receive-pack`. Commands matching the + prefixes will be executed by an external hook "proc-receive", + instead of the internal `execute_commands` function. If this + variable is not defined, the "proc-receive" hook will never be + used, and all commands will be executed by the internal + `execute_commands` function. + + For example, if this variable is set to "refs/for", pushing to + reference such as "refs/for/master" will not create or update a + reference named "refs/for/master", but may create or update a + pull request directly by running the hook "proc-receive". + receive.updateServerInfo:: If set to true, git-receive-pack will run git-update-server-info after receiving data from git-push and updating refs.
builtin/receive-pack.c +36 -7
74 lines not on this page · raw message
t/t5411/test-0010-proc-receive-settings.sh new file +7 -0
@@ -0,0 +1,7 @@ +test_expect_success "add two receive.procReceiveRefs settings" ' + ( + cd "$upstream" && + git config --add receive.procReceiveRefs refs/for && + git config --add receive.procReceiveRefs refs/review/ + ) +'
t/t5411/test-0040-process-all-refs.sh new file +93 -0
93 lines not on this page · raw message
t/t5411/test-0041-process-all-refs--porcelain.sh new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v13 8/8 doc: add documentation for the proc-receive hook
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Add documentation for the new "proc-receive" hook.
--- Documentation/githooks.txt | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
Documentation/githooks.txt +58 -0
@@ -333,6 +333,64 @@ The default 'update' hook, when enabled--and with `hooks.allowunannotated` config option unset or set to false--prevents unannotated tags to be pushed. +proc-receive +~~~~~~~~~~~~ + +This hook is invoked by linkgit:git-receive-pack[1]. If the server has +set the multi-valued config variable `receive.procReceiveRefs`, and the +commands sent to 'receive-pack' have matching reference names, these +commands will be executed by this hook, instead of by the internal +`execute_commands()` function. This hook is responsible for updating +the relevant references and reporting the results back to 'receive-pack'. + +This hook executes once for the receive operation. It takes no +arguments, but uses a pkt-line format protocol to communicate with +'receive-pack' to read commands, push-options and send results. In the +following example for the protocol, the letter 'S' stands for +'receive-pack' and the letter 'H' stands for this hook. + + # Version and features negotiation. + S: PKT-LINE(version=1\0push-options atomic...) + S: flush-pkt + H: PKT-LINE(version=1\0push-options...) + H: flush-pkt + + # Send commands from server to the hook. + S: PKT-LINE(<old-oid> <new-oid> <ref>) + S: ... ... + S: flush-pkt + # Send push-options only if the 'push-options' feature is enabled. + S: PKT-LINE(push-option) + S: ... ... + S: flush-pkt + + # Receive result from the hook. + # OK, run this command successfully. + H: PKT-LINE(ok <ref>) + # NO, I reject it. + H: PKT-LINE(ng <ref> <reason>) + # Fall through, let 'receive-pack' to execute it. + H: PKT-LINE(ft <ref>) + # OK, but has an alternate reference. The alternate reference name + # is given in the third parameter, and other status can be given in + # key-value pairs. + H: PKT-LINE(alt <ref> <alt-ref> old-oid=<old-oid> new-oid=<new-oid> + forced-update) + H: ... ... + H: flush-pkt + +Each command for the 'proc-receive' hook may point to a pseudo-reference +and always has a zero-old as its old-oid, while the 'proc-receive' hook +may update an alternate reference and the alternate reference may exist +already with a non-zero old-oid. For this case, this hook may return +different OID and different reference name as extended status of the +report line. + +The report of the commands of this hook should have the same order as +the input. The exit status of the 'proc-receive' hook only determines +the success or failure of the group of commands sent to it, unless +atomic push is in use. + [[post-receive]] post-receive ~~~~~~~~~~~~
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v12 2/7 connect: export parse_feature_value()
In reply to Junio C HamanoFrom: Jiang Xin <[email protected]>
Export parse_feature_value() to parse extended status of report for "proc-receive" and "receive-pack".
--- connect.c | 3 +-- connect.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)
connect.c +1 -2
@@ -18,7 +18,6 @@static char *server_capabilities_v1;static struct argv_array server_capabilities_v2 =ARGV_ARRAY_INIT ; -static const char *parse_feature_value (const char *,const char *,int *);static int check_ref (const char *name,unsigned int flags) {
@@ -447,7 +446,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,return list; } -static const char *parse_feature_value (const char *feature_list,const char *feature,int *lenp) +const char *parse_feature_value (const char *feature_list,const char *feature,int *lenp) {int len;
connect.h +1 -0
@@ -12,6 +12,7 @@ int finish_connect(struct child_process *conn);int git_connection_is_socket (struct child_process *conn);int server_supports (const char *feature);int parse_feature_request (const char *features,const char *feature); +const char *parse_feature_value (const char *feature_list,const char *feature,int *len_ret);const char *server_feature_value (const char *feature,int *len_ret);int url_is_local_not_ssh (const char *url);
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
PATCH v12 3/7 receive-pack: add new proc-receive hook
In reply to Junio C HamanoFrom: Jiang Xin <[email protected]>
Git calls an internal execute_commands function to handle commands sent from client to git-receive-pack. Regardless of what references the user pushes, git creates or updates the corresponding references if the user has write-permission. A contributor who has no write-permission, cannot push to the repository directly. So, the contributor has to write commits to an alternate location, and sends pull request by emails or by other ways. We call this workflow as a distributed workflow.
It would be more convenient to work in a centralized workflow like what Gerrit provided for some cases. For example, a read-only user who cannot push to a branch directly can run the following git push command to push commits to a pseudo reference (has a prefix "refs/for/", not "refs/heads/") to create a code review.
git push origin \
HEAD:refs/for/<branch-name>/<session>The <branch-name> in the above example can be as simple as "master", or a more complicated branch name like "foo/bar". The <session> in the above example command can be the local branch name of the client side, such as "my/topic".
We cannot implement a centralized workflow elegantly by using "pre-receive" + "post-receive", because Git will call the internal function "execute_commands" to create references (even the special pseudo reference) between these two hooks. Even though we can delete the temporarily created pseudo reference via the "post-receive" hook, having a temporary reference is not safe for concurrent pushes.
So, add a filter and a new handler to support this kind of workflow. The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (run_proc_receive) on for the command. Commands with this filed turned on will be executed by a new handler (an hook named "proc-receive") instead of the internal execute_commands function. We can use this "proc-receive" command to create pull requests or send emails for code review.
Suggested by Junio, this "proc-receive" hook reads the commands, push-options (optional), and send result using a protocol in pkt-line format. In the following example, The letter "S" stands for "receive-pack" and letter "H" stands for the hook.
# Version and features negotiation.
S: PKT-LINE(version=1\0push-options atomic...)
S: flush-pkt
H: PKT-LINE(version=1\0push-options...)
H: flush-pkt
# Send commands from server to the hook.
S: PKT-LINE(<old-oid> <new-oid> <ref>)
S: ... ...
S: flush-pkt
# Send push-options only if the 'push-options' feature is enabled.
S: PKT-LINE(push-option)
S: ... ...
S: flush-pkt
# Receive result from the hook.
# OK, run this command successfully.
H: PKT-LINE(ok <ref>)
# NO, I reject it.
H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
H: PKT-LINE(ft <ref>)
# OK, but has an alternate reference. The alternate reference name # is given in the third parameter, and other status can be given in # key-value pairs.
H: PKT-LINE(alt <ref> <alt-ref> old-oid=<old-oid> new-oid=<new-oid>
forced-update)
H: ... ...
H: flush-pkt
After receiving a command, the hook will execute the command, and may create/update different reference. For example, a command for a pseudo reference "refs/for/master/topic" may create/update different reference such as "refs/pull/123/head". The alternate reference name and other status are given in key-value pairs as extended status of the report line.
The list of commands returned from "proc-receive" will replace the relevant commands that are sent from user to "receive-pack", and "receive-pack" will continue to run the "execute_commands" function and other routines. Finally, the result of the execution of these commands will be reported to end user.
The reporting function from "receive-pack" to "send-pack" is extended using a backward compatible way by adding key-value pairs after an null character, like:
# OK, run this command successfully with optional extended-status. ok <reference>\0ref=refs/pull/123/head old-oid=...
# NO, I reject it.
ng <reference> <error message>
Parsing the extended status of the report lines for "send-pack" is not implemented in this commit, so we can make a compatible test on old version of a Git client.
--- Makefile | 1 + builtin/receive-pack.c | 316 +++++++++++++++- t/helper/test-proc-receive.c | 178 +++++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411/common-functions.sh | 10 +- t/t5411/common-test-cases.sh | 676 +++++++++++++++++++++++++++++++++++ 7 files changed, 1171 insertions(+), 12 deletions(-) create mode 100644 t/helper/test-proc-receive.c
Makefile +1 -0
@@ -725,6 +725,7 @@ TEST_BUILTINS_OBJS += test-parse-pathspec-file.o TEST_BUILTINS_OBJS += test-path-utils.o TEST_BUILTINS_OBJS += test-pkt-line.o TEST_BUILTINS_OBJS += test-prio-queue.o +TEST_BUILTINS_OBJS += test-proc-receive.o TEST_BUILTINS_OBJS += test-progress.o TEST_BUILTINS_OBJS += test-reach.o TEST_BUILTINS_OBJS += test-read-cache.o
builtin/receive-pack.c +307 -9
374 lines not on this page · raw message
t/helper/test-proc-receive.c new file +178 -0
178 lines not on this page · raw message
t/helper/test-tool.c +1 -0
@@ -44,6 +44,7 @@ static struct test_cmd cmds[] = { { "path-utils", cmd__path_utils }, { "pkt-line", cmd__pkt_line }, { "prio-queue", cmd__prio_queue }, + { "proc-receive", cmd__proc_receive}, { "progress", cmd__progress }, { "reach", cmd__reach }, { "read-cache", cmd__read_cache },
t/helper/test-tool.h +1 -0
@@ -34,6 +34,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);int cmd__path_utils (int argc,const char **argv);int cmd__pkt_line (int argc,const char **argv);int cmd__prio_queue (int argc,const char **argv); +int cmd__proc_receive (int argc,const char **argv);int cmd__progress (int argc,const char **argv);int cmd__reach (int argc,const char **argv);int cmd__read_cache (int argc,const char **argv);
t/t5411/common-functions.sh +7 -3
@@ -34,8 +34,11 @@ create_commits_in () { # Format the output of git-push, git-show-ref and other commands to make a # user-friendly and stable text. We can easily prepare the expect text # without having to worry about future changes of the commit ID and spaces -# of the output. We also replce single quotes with double quotes, because -# it is boring to prepare unquoted single quotes in expect text. +# of the output. Single quotes are replaced with double quotes, because +# it is boring to prepare unquoted single quotes in expect text. We also +# remove some locale error messages, which break test if we turn on +# `GIT_TEST_GETTEXT_POISON=true` in order to test unintentional translations +# on plumbing commands. make_user_friendly_and_stable_output_common () { sed \ -e "s/ *\$//" \
@@ -46,5 +49,6 @@ make_user_friendly_and_stable_output_common () { -e "s/$TAG/<TAG-v123>/g" \ -e "s/$ZERO_OID/<ZERO-OID>/g" \ -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \ - -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" + -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \ + -e "/^error: / d" }
t/t5411/common-test-cases.sh +676 -0
679 lines not on this page · raw message
Signature · 1 line
2.24.1.15.g448c31058d.agit.4.5
Re: [PATCH v12 3/7] receive-pack: add new proc-receive hook
builtin/receive-pack.c line 19
Quoted 12 lines · Jiang Xin
builtin/receive-pack.c +1
-0@@ -13,6 +13,7 @@#include "remote.h" #include "connect.h" #include "string-list.h" +#include "string.h" #include "sha1-array.h" #include "connected.h" #include "argv-array.h"
What are you using from the system <string.h>, that is not covered by existing inclusion of "git-compat-util.h"?
Don't include any system header directly in our *.c code (unless it is a platform-specific compat/ thing).
Re: [PATCH v12 3/7] receive-pack: add new proc-receive hook
Quoted 19 lines · Junio C Hamano <[email protected]> 于2020年4月15日周三 下午11:48写道:
builtin/receive-pack.c line 19
Quoted 12 lines · Jiang Xin
builtin/receive-pack.c +1
-0@@ -13,6 +13,7 @@#include "remote.h" #include "connect.h" #include "string-list.h" +#include "string.h" #include "sha1-array.h" #include "connected.h" #include "argv-array.h" What are you using from the system <
string.h>, that is not covered by existing inclusion of "git-compat-util.h"?
Quoted 2 lines
Don't include any system header directly in our *.c code (unless it is a platform-specific compat/ thing).
Will correct it.
What I am working on for reroll v13:
* Add new commit "receive-pack: feed extended_status to post-receive“
When commands are fed to the "post-receive" hook, extended_status will be parsed and the real old-oid, new-oid, reference name will feed to the "post-receive" hook.
* Add test cases for "git push --porcelain".
I found some changes not covered by test. So I decide add some test cases for "git push --porcelain". I will split the test cases into multiple files inside "t5411/" like:
t5411/test-0000-normal-push.sh
t5411/test-0001-normal-push--porcelain.sh* Other minor fixes.
Re: [PATCH v12 3/7] receive-pack: add new proc-receive hook
Quoted 12 lines · Jiang Xin
Will correct it.
What I am working on for reroll v13:
* Add new commit "receive-pack: feed
extended_statusto post-receive“When commands are fed to the "post-receive" hook,
extended_statuswill be parsed and the real old-oid, new-oid, reference name will feed to the "post-receive" hook.* Add test cases for "git push --porcelain".
Quoted 8 lines
I found some changes not covered by test. So I decide add some test cases for "git push --porcelain". I will split the test cases into multiple files inside "t5411/" like:
t5411/test-0000-normal-push.sh t5411/test-0001-normal-push--porcelain.sh* Other minor fixes.
Thanks for a heads-up, but given that nobody seems to be reading your patches and commenting on them, you might want to slow down a bit.
Re: [PATCH v12 3/7] receive-pack: add new proc-receive hook
Quoted 19 lines · Junio C Hamano <[email protected]> 于2020年4月16日周四 上午2:34写道:
Quoted 16 lines · Jiang Xin
Will correct it.
What I am working on for reroll v13:
* Add new commit "receive-pack: feed
extended_statusto post-receive“When commands are fed to the "post-receive" hook,
extended_statuswill be parsed and the real old-oid, new-oid, reference name will feed to the "post-receive" hook.* Add test cases for "git push --porcelain".
I found some changes not covered by test. So I decide add some test cases for "git push --porcelain". I will split the test cases into multiple files inside "t5411/" like:
Quoted 8 lines
Quoted 4 lines
t5411/test-0000-normal-push.sh t5411/test-0001-normal-push--porcelain.sh* Other minor fixes.
Thanks for a heads-up, but given that nobody seems to be reading your patches and commenting on them, you might want to slow down a bit.
For over a week, I have not received more comments on reroll v13 on this topic ("jx/proc-receive-hook"). Therefore, I invite Peff and Couder to review because I think it would be very interesting to add a centralized workflow to Github and Gitlab.
* [PATCH v13 3/8]:
https://public-inbox.org/git/[email protected]/
This patch introduces a new hook "proc-receive" on the server side. It won't break anything except GitHub's "spokes" architecture (I guess). Because in Alibaba, we have such issue when we implement our own "spokes" architecture. In order to make this special push operation (on a special ref such as "refs/for/master/topic") idempotently on multiple replicas, we extended the protocol of "receive-pack" and let "spokes" to send a request with a flag, which specifies one replica as master replica to execute the "proc-receive" hook.
* [PATCH v13 4/8]:
https://public-inbox.org/git/[email protected]/
* [PATCH v13 5/8]:
https://public-inbox.org/git/[email protected]/
Patch 4/8 and patch 5/8 extends status report for both server and client sides. The extension is backward compatible. When user push like this:
git push origin HEAD:refs/for/master/topic
Old version of git may report like:
To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic
But new version of git may report like:
To <URL/of/upstream.git>
+ <OID-B>...<OID-A> HEAD -> refs/pull/123/head (forced update)
As for how to use this "proc-receive" hook to implement a centralized git workflow, please refer to my blog as a reference:
* https://git-repo.info/en/2020/03/agit-flow-and-git-repo/
--
Jiang Xin
Re: [PATCH v12 3/7] receive-pack: add new proc-receive hook
Quoted 8 lines · Jiang Xin
For over a week, I have not received more comments on reroll v13 on this topic ("jx/proc-receive-hook"). Therefore, I invite Peff and Couder to review because I think it would be very interesting to add a centralized workflow to Github and Gitlab.
* [PATCH v13 3/8]:
https://public-inbox.org/git/[email protected]/
Quoted 8 lines
This patch introduces a new hook "proc-receive" on the server side. It won't break anything except GitHub's "spokes" architecture (I guess). Because in Alibaba, we have such issue when we implement our own "spokes" architecture. In order to make this special push operation (on a special ref such as "refs/for/master/topic") idempotently on multiple replicas, we extended the protocol of "receive-pack" and let "spokes" to send a request with a flag, which specifies one replica as master replica to execute the "proc-receive" hook.
We don't do any magic ref-rewriting like this, so we wouldn't turn such a hook on. Presumably without such a hook, the protocol would remain the same (i.e., if there was no rewrite, then the report-status response wouldn't have the extra field).
And I'm not sure if you're proposing to also use it as the trigger point to coordinate the ref update across replicas. That wouldn't be helpful for our architecture. All Git client connections to GitHub terminate at a proxy layer that handles load balancing, authentication, and routing. For pushes, that's the layer that multiplexes the packfile to each replica, and it drives the ref update through an out-of-band procedure. So there is no master replica at all; they're all talking equally to the proxy layer which coordinates things (and the same is true for non-push updates; they're coordinated by whichever entity is trying to perform the update).
We do run receive-pack on each replica backend. We have a hacky patch for a config option that tells receive-pack to just skip the actual ref-transaction, leaving it up to the proxy layer to do. I've been pushing for us to actually abandon receive-pack entirely, since most of its heavy lifting can be done by sub-programs (for-each-ref for the advertisement, index-pack to receive the pack, and update-ref to update refs). But it's a non-trivial change, and the benefits are only moderate, so it hasn't quite been worth the effort yet.
So I don't really have much of an opinion on it either way.
Reading the commit message for patch 3, I do have one small comment. I see this:
The reporting function from "receive-pack" to "send-pack" is extended using a backward compatible way by adding key-value pairs after an null character, like:
# OK, run this command successfully with optional extended-status. ok <reference>\0ref=refs/pull/123/head old-oid=...
# NO, I reject it.
ng <reference> <error message>
but we should probably avoid trickery like stuffing extra data after a NUL byte. We could quite easily extend the protocol with a new capability here. The server advertises "report-status-v2" or something, and the client responds with the appropriate capability to indicate that it understands. And then the new format can be something more extensible, like:
pktline(ref=refs/heads/master)
pktline(status=ok)
pktline(old-oid=...)
pktline(rewrite=refs/pull/123/head)
delim-pkt(0001)
pktline(ref=refs/heads/other)
pktline(status=error)
pktline(message=<error message>
flush-pkt(0000)
which would give us room for more keys later, but without worrying about parsing issues after the NUL, running out of room in a pktline if you have too many keys, etc.
I don't have any real thoughts on the hook interface itself. It seems like the ok/no/ft/alt responses would allow just about any hook you'd want. It does seems to also use NUL trickery in the early part. If we're designing from scratch, I think we should strive for a cleaner protocol.
-Peff
Re: [PATCH v12 3/7] receive-pack: add new proc-receive hook
Quoted 36 lines · Jeff King <[email protected]> 于2020年4月29日周三 下午3:56写道:
Quoted 8 lines · Jiang Xin
For over a week, I have not received more comments on reroll v13 on this topic ("jx/proc-receive-hook"). Therefore, I invite Peff and Couder to review because I think it would be very interesting to add a centralized workflow to Github and Gitlab.
* [PATCH v13 3/8]:
https://public-inbox.org/git/[email protected]/Quoted 8 lines
This patch introduces a new hook "proc-receive" on the server side. It won't break anything except GitHub's "spokes" architecture (I guess). Because in Alibaba, we have such issue when we implement our own "spokes" architecture. In order to make this special push operation (on a special ref such as "refs/for/master/topic") idempotently on multiple replicas, we extended the protocol of "receive-pack" and let "spokes" to send a request with a flag, which specifies one replica as master replica to execute the "proc-receive" hook.
We don't do any magic ref-rewriting like this, so we wouldn't turn such a hook on. Presumably without such a hook, the protocol would remain the same (i.e., if there was no rewrite, then the report-status response wouldn't have the extra field).
And I'm not sure if you're proposing to also use it as the trigger point to coordinate the ref update across replicas. That wouldn't be helpful for our architecture. All Git client connections to GitHub terminate at a proxy layer that handles load balancing, authentication, and routing. For pushes, that's the layer that multiplexes the packfile to each replica, and it drives the ref update through an out-of-band procedure. So there is no master replica at all; they're all talking equally to the proxy layer which coordinates things (and the same is true for non-push updates; they're coordinated by whichever entity is trying to perform the update).
Quoted 9 lines
We do run receive-pack on each replica backend. We have a hacky patch for a config option that tells receive-pack to just skip the actual ref-transaction, leaving it up to the proxy layer to do. I've been pushing for us to actually abandon receive-pack entirely, since most of its heavy lifting can be done by sub-programs (for-each-ref for the advertisement, index-pack to receive the pack, and update-ref to update refs). But it's a non-trivial change, and the benefits are only moderate, so it hasn't quite been worth the effort yet.
Thanks to Peff for providing technical details of the architecture. I understand that "receive-pack" of GitHub backend is not involved in references update (executing the commands), so the "proc-receive" hook won't be turned on for GitHub's architecture. While in our architecture (inspired by "spokes" of GitHub), the proxy will deliver not only packfile, but also commands to all three replicas. The proxy will execute "receive-pack" on the replica with a special argument, so the proxy can talk with "receive-pack" with an extended protocol. After running pre-receive hook and release the packfile from quarantine, the replica will stop and wait for the proxy to coordinate. After creating a distributed lock, the proxy will tell all the replicas continue to update the references. One problem we met is the proc-receive and the post-receive hook must be executed once. We can make the execution of the hooks idempotent, or let only one of the replica run the hook. We choose the latter.
Quoted 22 lines
So I don't really have much of an opinion on it either way.
Reading the commit message for patch 3, I do have one small comment. I see this:
The reporting function from "receive-pack" to "send-pack" is extended using a backward compatible way by adding key-value pairs after an null character, like:
# OK, run this command successfully with optional extended-status. ok <reference>\0ref=refs/pull/123/head old-oid=...
# NO, I reject it.
ng <reference> <error message>but we should probably avoid trickery like stuffing extra data after a NUL byte. We could quite easily extend the protocol with a new capability here. The server advertises "report-status-v2" or something, and the client responds with the appropriate capability to indicate that it understands. And then the new format can be something more extensible, like:
Quoted 9 lines
pktline(ref=refs/heads/master)
pktline(status=ok)
pktline(old-oid=...)
pktline(rewrite=refs/pull/123/head)
delim-pkt(0001)
pktline(ref=refs/heads/other)
pktline(status=error)
pktline(message=<error message>
flush-pkt(0000)
The above status report is from "receive-pack" to "send-pack", and another place that we need to extend is in print_helper_status() of builtin/send-pack.c, which will send report status in the following format from "send-pack" to remote-helper (such as remote-curl.c):
ok <ref>
error <ref> <error message>
BTW, I don't know why not use "ng", but use "error" here.
I agree that adding new capability (report-status-v2) is a better solution, but I think the above extension is a bit wordy. We add additional 18 characters for each "ok <ref>" status, and add additional 32 characters for each "ng <ref> <msg>" status. Can we extend it like this:
ok <ref>
[optional key-value pairs]
ng <ref> <error message>
[optional key-value pairs]
E.g.:
ok refs/heads/master # no extensions
ok refs/for/master/topic # send 2 commits, and create 2 changes rewrite=refs/changes/123/1
new-oid=...
# use rewrite key-value pair as delimiter,
# because plain text is in use from "send-pack" to remote-helper. rewrite=refs/changes/124/1
new-oid=...
ok refs/heads/next
ng refs/heads/release non-fast forward
--
Jiang Xin
v14 cover New proc-receive hook for centralized workflow
From: Jiang Xin <[email protected]>
This topic introduces a new hook named "proc-receive" for "receive-pack". We can use this hook to implement a Gerrit-like centralized workflow.
## Changes since v13
1. Patch 3/7 introduced a new capability "report-status-v2" for git-push
Add new capability "report-status-v2" and new report protocol which is not backward compatible for report of git-push.
If a user pushes to a pseudo-reference "refs/for/master/topic", and "receive-pack" creates two new references "refs/changes/23/123/1" and "refs/changes/24/124/1", for client without the knowledge of "report-status-v2", "receive-pack" will only send "ok/ng" directives in the report, such as:
ok ref/for/master/topic
But for client which has the knowledge of "report-status-v2", "receive-pack" will use "option" directives to report more attributes for the reference given by the above "ok/ng" directive.
ok refs/for/master/topic
option refname refs/changes/23/123/1
option new-oid <new-oid>
ok refs/for/master/topic
option refname refs/changes/24/124/1
option new-oid <new-oid>
The client will report two new created references to the end user.
2. Patch 2/7: the "proc-receive" reports status using the same way like "report-status-v2" to "receive-pack".
## Range-diff v13...v14
1: dc7f1d044d ! 1: 9a19919552 transport: not report a non-head push as a branch
@@ t/t5411-proc-receive-hook.sh (new)
+ git -C upstream.git config http.receivepack true &&
+ upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
+ mv upstream.git "$upstream" &&
++ set_askpass user@host pass@host &&
+ git -C workbench remote set-url origin $HTTPD_URL/smart/upstream.git
+'
+
@@ t/t5411/test-0000-standard-git-push.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git-push : master(B) next(A)
-+test_expect_success "non-force git-push ($PROTOCOL)" '
++test_expect_success "git-push ($PROTOCOL)" '
+ git -C workbench push origin \
+ $B:refs/heads/master \
+ HEAD:refs/heads/next \
@@ t/t5411/test-0000-standard-git-push.sh (new)
+# Refs of upstream : master(B) next(A)
+# Refs of workbench: master(A) tags/v123
+# git-push -f : master(A) NULL tags/v123 refs/review/master/topic(A) a/b/c(A)
-+test_expect_success "force git-push ($PROTOCOL)" '
++test_expect_success "git-push -f ($PROTOCOL)" '
+ git -C workbench push -f origin \
+ refs/tags/v123 \
+ :refs/heads/next \
@@ t/t5411/test-0001-standard-git-push--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git-push : master(B) next(A)
-+test_expect_success "non-force git-push (--porcelain, $PROTOCOL)" '
++test_expect_success "git-push ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ $B:refs/heads/master \
+ HEAD:refs/heads/next \
@@ t/t5411/test-0001-standard-git-push--porcelain.sh (new)
+# Refs of upstream : master(B) next(A)
+# Refs of workbench: master(A) tags/v123
+# git-push -f : master(A) NULL tags/v123 refs/review/master/topic(A) a/b/c(A)
-+test_expect_success "force git-push (--porcelain, $PROTOCOL)" '
++test_expect_success "git-push -f ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain -f origin \
+ refs/tags/v123 \
+ :refs/heads/next \
@@ t/t5411/test-0001-standard-git-push--porcelain.sh (new)
+ git update-ref -d refs/heads/a/b/c
+ )
+'
-+
## t/t5411/test-0002-pre-receive-declined.sh (new) ##
@@
-+test_expect_success "setup pre-receive hook (declined, $PROTOCOL)" '
++test_expect_success "setup pre-receive hook ($PROTOCOL)" '
+ mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" &&
+ write_script "$upstream/hooks/pre-receive" <<-EOF
+ exit 1
@@ t/t5411/test-0002-pre-receive-declined.sh (new)
## t/t5411/test-0003-pre-receive-declined--porcelain.sh (new) ##
@@
-+test_expect_success "setup pre-receive hook (declined, $PROTOCOL)" '
++test_expect_success "setup pre-receive hook ($PROTOCOL)" '
+ mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" &&
+ write_script "$upstream/hooks/pre-receive" <<-EOF
+ exit 1
@@ t/t5411/test-0003-pre-receive-declined--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git-push : master(B) next(A)
-+test_expect_success "git-push is declined (--porcelain, $PROTOCOL)" '
++test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ $B:refs/heads/master \
+ HEAD:refs/heads/next \
2: 673f44599f < -: ---------- connect: export parse_feature_value()
3: 43647b379a ! 2: f1a3ca9cda receive-pack: add new proc-receive hook
@@ Commit message
# NO, I reject it.
H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
- H: PKT-LINE(ft <ref>)
+ H: PKT-LINE(ok <ref>)
+ H: PKT-LINE(option fall-through)
# OK, but has an alternate reference. The alternate reference name
- # is given in the third parameter, and other status can be given in
- # key-value pairs.
- H: PKT-LINE(alt <ref> <alt-ref> old-oid=<old-oid> new-oid=<new-oid>
- forced-update)
+ # and other status can be given in options
+ H: PKT-LINE(ok <ref>)
+ H: PKT-LINE(option refname <refname>)
+ H: PKT-LINE(option old-oid <old-oid>)
+ H: PKT-LINE(option new-oid <new-oid>)
+ H: PKT-LINE(option forced-update)
H: ... ...
H: flush-pkt
@@ Commit message
create/update different reference. For example, a command for a pseudo
reference "refs/for/master/topic" may create/update different reference
such as "refs/pull/123/head". The alternate reference name and other
- status are given in key-value pairs as extended status of the report
- line.
+ status are given in option lines.
The list of commands returned from "proc-receive" will replace the
relevant commands that are sent from user to "receive-pack", and
@@ Commit message
other routines. Finally, the result of the execution of these commands
will be reported to end user.
- The reporting function from "receive-pack" to "send-pack" is extended
- using a backward compatible way by adding key-value pairs after an null
- character, like:
-
- # OK, run this command successfully with optional extended-status.
- ok <reference>\0ref=refs/pull/123/head old-oid=...
-
- # NO, I reject it.
- ng <reference> <error message>
-
- Parsing the extended status of the report lines for "send-pack" is not
- implemented in this commit, so we can make a compatible test on old
- version of a Git client.
+ The reporting function from "receive-pack" to "send-pack" will be
+ extended in latter commit just like what the "proc-receive" hook reports
+ to "receive-pack".
Suggested-by: Junio C Hamano <[email protected]>
Signed-off-by: Jiang Xin <[email protected]>
@@ builtin/receive-pack.c: static void write_head_info(void)
+#define RUN_PROC_RECEIVE_RETURNED 2
struct command {
struct command *next;
- const char *error_string;
-+ const char *extended_status;
+- const char *error_string;
++ struct ref_push_report report;
unsigned int skip_update:1,
- did_not_exist:1;
+ did_not_exist:1,
@@ builtin/receive-pack.c: static void write_head_info(void)
int index;
struct object_id old_oid;
struct object_id new_oid;
+@@ builtin/receive-pack.c: static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
+ struct command *cmd = state->cmd;
+
+ while (cmd &&
+- state->skip_broken && (cmd->error_string || cmd->did_not_exist))
++ state->skip_broken && (cmd->report.error_message || cmd->did_not_exist))
+ cmd = cmd->next;
+ if (!cmd)
+ return -1; /* EOF */
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
return finish_command(&proc);
}
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+{
+ struct command *cmd;
+ struct command *hint = NULL;
-+ struct strbuf extended_status = STRBUF_INIT;
+ int code = 0;
++ int new_options = 1;
+
+ for (;;) {
+ struct object_id old_oid, new_oid;
-+ const char *status;
-+ char *refname;
-+ char *remains = NULL;
++ const char *head;
++ const char *refname;
++ char *p;
+
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
+ break;
-+ status = reader->line;
-+ refname = strchr(status, ' ');
-+ if (refname) {
-+ *refname++ = '\0';
-+ remains = strchr(refname, ' ');
-+ if (remains)
-+ *remains++ = '\0';
++
++ head = reader->line;
++ p = strchr(head, ' ');
++ if (!p) {
++ strbuf_addf(errmsg, "proc-receive reported incomplete status line: '%s'\n", head);
++ code = -1;
++ continue;
+ }
-+ if (!refname || strlen(refname) == 0) {
-+ strbuf_addf(errmsg, "proc-receive expected '<status> <ref> ...', got '%s'\n",
-+ reader->line);
++ *p++ = '\0';
++ if (!strcmp(head, "option")) {
++ struct ref_push_report_options *options;
++ const char *key, *val;
++
++ if (!hint) {
++ if (new_options) {
++ strbuf_addstr(errmsg, "proc-receive reported 'option' without a matching 'ok/ng' directive\n");
++ new_options = 0;
++ }
++ code = -1;
++ continue;
++ }
++ options = hint->report.options;
++ while (options && options->next)
++ options = options->next;
++ if (new_options) {
++ if (!options) {
++ hint->report.options = xcalloc(1, sizeof(struct ref_push_report_options));
++ options = hint->report.options;
++ } else {
++ options->next = xcalloc(1, sizeof(struct ref_push_report_options));
++ options = options->next;
++ }
++ new_options = 0;
++ }
++ assert(options);
++ key = p;
++ p = strchr(key, ' ');
++ if (p)
++ *p++ = '\0';
++ val = p;
++ if (!strcmp(key, "refname"))
++ options->ref_name = xstrdup_or_null(val);
++ else if (!strcmp(key, "old-oid") && val &&
++ !parse_oid_hex(val, &old_oid, &val))
++ options->old_oid = oiddup(&old_oid);
++ else if (!strcmp(key, "new-oid") && val &&
++ !parse_oid_hex(val, &new_oid, &val))
++ options->new_oid = oiddup(&new_oid);
++ else if (!strcmp(key, "forced-update"))
++ options->forced_update = 1;
++ else if (!strcmp(key, "fall-through"))
++ /* Fall through, let 'receive-pack' to execute it. */
++ hint->run_proc_receive = 0;
++ continue;
++ }
++
++ refname = p;
++ p = strchr(refname, ' ');
++ if (p)
++ *p++ = '\0';
++ if (strcmp(head, "ok") && strcmp(head, "ng")) {
++ strbuf_addf(errmsg, "proc-receive reported bad status '%s' on ref '%s'\n",
++ head, refname);
+ code = -1;
+ continue;
+ }
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ if (!hint) {
+ strbuf_addf(errmsg, "proc-receive reported status on unknown ref: %s\n",
+ refname);
++ code = -1;
+ continue;
+ }
+ if (!hint->run_proc_receive) {
+ strbuf_addf(errmsg, "proc-receive reported status on unexpected ref: %s\n",
+ refname);
++ code = -1;
+ continue;
+ }
-+ if (!strcmp(status, "ng")) {
-+ if (remains)
-+ hint->error_string = xstrdup(remains);
++ if (!strcmp(head, "ng")) {
++ if (p)
++ hint->report.error_message = xstrdup(p);
+ else
-+ hint->error_string = "failed";
++ hint->report.error_message = "failed";
+ code = -1;
-+ } else if (!strcmp("ft", status)) {
-+ /* Reset "run_proc_receive" field, and continue to run in "receive-pack" */
-+ hint->run_proc_receive = 0;
-+ } else if (!strcmp("alt", status)) {
-+ char *alt_ref = NULL;
-+ char *p1, *p2;
-+
-+ if (!remains) {
-+ strbuf_addf(errmsg, "proc-receive expected 'alt <ref> <alt-ref> ...', got 'alt %s'\n",
-+ refname);
-+ continue;
-+ }
-+ p1 = strchr(remains, '=');
-+ p2 = strchr(remains, ' ');
-+ if (!p1) {
-+ /*
-+ * "alt <ref> <alt-ref>", or
-+ * "alt <ref> <alt-ref> forced-update"
-+ */
-+ alt_ref = remains;
-+ remains = p2;
-+ if (remains)
-+ *remains++ = '\0';
-+ } else if (!p2) {
-+ /* "alt <ref> old-oid=<oid>" */
-+ alt_ref = NULL;
-+ } else if (p1 > p2) {
-+ /* "alt <ref> <alt-ref> old-oid=<oid>" */
-+ alt_ref = remains;
-+ remains = p2;
-+ if (remains)
-+ *remains++ = '\0';
-+ } else {
-+ /* "alt <ref> old-oid=<oid1> new-oid=<oid2>" */
-+ alt_ref = NULL;
-+ }
-+
-+ if (hint->extended_status)
-+ strbuf_addstr(&extended_status, hint->extended_status);
-+
-+ /*
-+ * Already received an "ok <ref>" response, add an
-+ * additional "ref=<ref>" field.
-+ */
-+ if (extended_status.len == 0 &&
-+ hint->run_proc_receive & RUN_PROC_RECEIVE_RETURNED)
-+ strbuf_addf(&extended_status, "ref=%s", refname);
-+
-+ if (alt_ref)
-+ strbuf_addf(&extended_status, "%sref=%s",
-+ extended_status.len > 0 ? " ": "",
-+ alt_ref);
-+ else if (extended_status.len > 0)
-+ /*
-+ * Start new extended status for refname, if it
-+ * is not the first report for this reference.
-+ */
-+ strbuf_addf(&extended_status, " ref=%s", refname);
-+
-+ if (remains) {
-+ const char *val;
-+ int len;
-+
-+ val = parse_feature_value(remains, "old-oid", &len);
-+ if (val && len > 0)
-+ if (!parse_oid_hex(val, &old_oid, &val))
-+ strbuf_addf(&extended_status, "%sold-oid=%s",
-+ extended_status.len > 0 ? " ": "",
-+ oid_to_hex(&old_oid));
-+
-+ val = parse_feature_value(remains, "new-oid", &len);
-+ if (val && len > 0)
-+ if (!parse_oid_hex(val, &new_oid, &val))
-+ strbuf_addf(&extended_status, "%snew-oid=%s",
-+ extended_status.len > 0 ? " ": "",
-+ oid_to_hex(&new_oid));
-+
-+ if (parse_feature_request(remains, "forced-update"))
-+ strbuf_addf(&extended_status, "%sforced-update",
-+ extended_status.len > 0 ? " ": "");
-+ }
-+
-+ if (extended_status.len > 0) {
-+ free((void *)hint->extended_status);
-+ hint->extended_status = strbuf_detach(&extended_status, NULL);
-+ }
-+ } else if (strcmp("ok", status)) {
-+ strbuf_addf(errmsg, "proc-receive reported bad status '%s' on ref '%s'\n",
-+ status, refname);
-+ code = -1;
-+ /* Skip marking it as RUN_PROC_RECEIVE_RETURNED */
-+ continue;
+ }
-+
+ if (hint->run_proc_receive)
+ hint->run_proc_receive |= RUN_PROC_RECEIVE_RETURNED;
++ new_options = 1;
+ }
+
+ for (cmd = commands; cmd; cmd = cmd->next)
-+ if (cmd->run_proc_receive && !cmd->error_string &&
++ if (cmd->run_proc_receive && !cmd->report.error_message &&
+ !(cmd->run_proc_receive & RUN_PROC_RECEIVE_RETURNED)) {
-+ cmd->error_string = "proc-receive failed to report status";
++ cmd->report.error_message = "proc-receive failed to report status";
+ code = -1;
+ }
-+
+ return code;
+}
+
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ struct packet_reader reader;
+ struct strbuf cap = STRBUF_INIT;
+ struct strbuf errmsg = STRBUF_INIT;
-+ int pr_use_push_options = 0;
++ int hook_use_push_options = 0;
+ int version = 0;
+ int code;
+
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ if (linelen < reader.pktlen) {
+ const char *feature_list = reader.line + linelen + 1;
+ if (parse_feature_request(feature_list, "push-options"))
-+ pr_use_push_options = 1;
++ hook_use_push_options = 1;
+ }
+ }
+ }
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+
+ /* Send commands */
+ for (cmd = commands; cmd; cmd = cmd->next) {
-+ if (!cmd->run_proc_receive || cmd->skip_update || cmd->error_string)
++ if (!cmd->run_proc_receive || cmd->skip_update || cmd->report.error_message)
+ continue;
+ packet_write_fmt(proc.in, "%s %s %s",
+ oid_to_hex(&cmd->old_oid),
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ packet_flush(proc.in);
+
+ /* Send push options */
-+ if (pr_use_push_options) {
++ if (hook_use_push_options) {
+ struct string_list_item *item;
+
+ for_each_string_list_item(item, push_options)
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
static char *refuse_unconfigured_deny_msg =
N_("By default, updating the current branch in a non-bare repository\n"
"is denied, because it will make the index and work tree inconsistent\n"
+@@ builtin/receive-pack.c: static void run_update_post_hook(struct command *commands)
+ return;
+
+ for (cmd = commands; cmd; cmd = cmd->next) {
+- if (cmd->error_string || cmd->did_not_exist)
++ if (cmd->report.error_message || cmd->did_not_exist)
+ continue;
+ if (!proc.args.argc)
+ argv_array_push(&proc.args, hook);
+@@ builtin/receive-pack.c: static void check_aliased_update_internal(struct command *cmd,
+ if (!dst_name) {
+ rp_error("refusing update to broken symref '%s'", cmd->ref_name);
+ cmd->skip_update = 1;
+- cmd->error_string = "broken symref";
++ cmd->report.error_message = "broken symref";
+ return;
+ }
+ dst_name = strip_namespace(dst_name);
+@@ builtin/receive-pack.c: static void check_aliased_update_internal(struct command *cmd,
+ find_unique_abbrev(&dst_cmd->old_oid, DEFAULT_ABBREV),
+ find_unique_abbrev(&dst_cmd->new_oid, DEFAULT_ABBREV));
+
+- cmd->error_string = dst_cmd->error_string =
++ cmd->report.error_message = dst_cmd->report.error_message =
+ "inconsistent aliased update";
+ }
+
+@@ builtin/receive-pack.c: static void check_aliased_updates(struct command *commands)
+ string_list_sort(&ref_list);
+
+ for (cmd = commands; cmd; cmd = cmd->next) {
+- if (!cmd->error_string)
++ if (!cmd->report.error_message)
+ check_aliased_update(cmd, &ref_list);
+ }
+
+@@ builtin/receive-pack.c: static void set_connectivity_errors(struct command *commands,
+ &opt))
+ continue;
+
+- cmd->error_string = "missing necessary objects";
++ cmd->report.error_message = "missing necessary objects";
+ }
+ }
+
+@@ builtin/receive-pack.c: static void reject_updates_to_hidden(struct command *commands)
+ prefix_len = refname_full.len;
+
+ for (cmd = commands; cmd; cmd = cmd->next) {
+- if (cmd->error_string)
++ if (cmd->report.error_message)
+ continue;
+
+ strbuf_setlen(&refname_full, prefix_len);
+@@ builtin/receive-pack.c: static void reject_updates_to_hidden(struct command *commands)
+ if (!ref_is_hidden(cmd->ref_name, refname_full.buf))
+ continue;
+ if (is_null_oid(&cmd->new_oid))
+- cmd->error_string = "deny deleting a hidden ref";
++ cmd->report.error_message = "deny deleting a hidden ref";
+ else
+- cmd->error_string = "deny updating a hidden ref";
++ cmd->report.error_message = "deny updating a hidden ref";
+ }
+
+ strbuf_release(&refname_full);
+@@ builtin/receive-pack.c: static void reject_updates_to_hidden(struct command *commands)
+
+ static int should_process_cmd(struct command *cmd)
+ {
+- return !cmd->error_string && !cmd->skip_update;
++ return !cmd->report.error_message && !cmd->skip_update;
+ }
+
+ static void warn_if_skipped_connectivity_check(struct command *commands,
@@ builtin/receive-pack.c: static void execute_commands_non_atomic(struct command *commands,
struct strbuf err = STRBUF_INIT;
@@ builtin/receive-pack.c: static void execute_commands_non_atomic(struct command *
continue;
transaction = ref_transaction_begin(&err);
+ if (!transaction) {
+ rp_error("%s", err.buf);
+ strbuf_reset(&err);
+- cmd->error_string = "transaction failed to start";
++ cmd->report.error_message = "transaction failed to start";
+ continue;
+ }
+
+- cmd->error_string = update(cmd, si);
++ cmd->report.error_message = update(cmd, si);
+
+- if (!cmd->error_string
++ if (!cmd->report.error_message
+ && ref_transaction_commit(transaction, &err)) {
+ rp_error("%s", err.buf);
+ strbuf_reset(&err);
+- cmd->error_string = "failed to update ref";
++ cmd->report.error_message = "failed to update ref";
+ }
+ ref_transaction_free(transaction);
+ }
@@ builtin/receive-pack.c: static void execute_commands_atomic(struct command *commands,
}
@@ builtin/receive-pack.c: static void execute_commands_atomic(struct command *comm
+ if (!should_process_cmd(cmd) || cmd->run_proc_receive)
continue;
- cmd->error_string = update(cmd, si);
+- cmd->error_string = update(cmd, si);
++ cmd->report.error_message = update(cmd, si);
+
+- if (cmd->error_string)
++ if (cmd->report.error_message)
+ goto failure;
+ }
+
+@@ builtin/receive-pack.c: static void execute_commands_atomic(struct command *commands,
+
+ failure:
+ for (cmd = commands; cmd; cmd = cmd->next)
+- if (!cmd->error_string)
+- cmd->error_string = reported_error;
++ if (!cmd->report.error_message)
++ cmd->report.error_message = reported_error;
+
+ cleanup:
+ ref_transaction_free(transaction);
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
struct iterate_data data;
struct async muxer;
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
if (unpacker_error) {
for (cmd = commands; cmd; cmd = cmd->next)
+- cmd->error_string = "unpacker error";
++ cmd->report.error_message = "unpacker error";
+ return;
+ }
+
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
reject_updates_to_hidden(commands);
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
+
if (run_receive_hook(commands, "pre-receive", 0, push_options)) {
for (cmd = commands; cmd; cmd = cmd->next) {
- if (!cmd->error_string)
+- if (!cmd->error_string)
+- cmd->error_string = "pre-receive hook declined";
++ if (!cmd->report.error_message)
++ cmd->report.error_message = "pre-receive hook declined";
+ }
+ return;
+ }
+@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
+ */
+ if (tmp_objdir_migrate(tmp_objdir) < 0) {
+ for (cmd = commands; cmd; cmd = cmd->next) {
+- if (!cmd->error_string)
+- cmd->error_string = "unable to migrate objects to permanent storage";
++ if (!cmd->report.error_message)
++ cmd->report.error_message = "unable to migrate objects to permanent storage";
+ }
+ return;
+ }
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
free(head_name_to_free);
head_name = head_name_to_free = resolve_refdup("HEAD", 0, NULL, NULL);
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
+ if (run_proc_receive &&
+ run_proc_receive_hook(commands, push_options))
+ for (cmd = commands; cmd; cmd = cmd->next)
-+ if (!cmd->error_string && (cmd->run_proc_receive || use_atomic))
-+ cmd->error_string = "fail to run proc-receive hook";
++ if (!cmd->report.error_message && (cmd->run_proc_receive || use_atomic))
++ cmd->report.error_message = "fail to run proc-receive hook";
+
if (use_atomic)
execute_commands_atomic(commands, si);
else
+@@ builtin/receive-pack.c: static void update_shallow_info(struct command *commands,
+ if (is_null_oid(&cmd->new_oid))
+ continue;
+ if (ref_status[cmd->index]) {
+- cmd->error_string = "shallow update not allowed";
++ cmd->report.error_message = "shallow update not allowed";
+ cmd->skip_update = 1;
+ }
+ }
@@ builtin/receive-pack.c: static void report(struct command *commands, const char *unpack_status)
packet_buf_write(&buf, "unpack %s\n",
unpack_status ? unpack_status : "ok");
for (cmd = commands; cmd; cmd = cmd->next) {
- if (!cmd->error_string)
-- packet_buf_write(&buf, "ok %s\n",
++ if (!cmd->report.error_message)
+ packet_buf_write(&buf, "ok %s\n",
- cmd->ref_name);
-- else
-- packet_buf_write(&buf, "ng %s %s\n",
-- cmd->ref_name, cmd->error_string);
-+ if (!cmd->error_string) {
-+ if (cmd->extended_status)
-+ packet_buf_write(&buf, "ok %s%c%s\n",
-+ cmd->ref_name, '\0',
-+ cmd->extended_status);
-+ else
-+ packet_buf_write(&buf, "ok %s\n",
+ cmd->ref_name);
-+ } else {
-+ if (cmd->extended_status)
-+ packet_buf_write(&buf, "ng %s %s%c%s\n",
-+ cmd->ref_name, cmd->error_string,
-+ '\0', cmd->extended_status);
-+ else
-+ packet_buf_write(&buf, "ng %s %s\n",
-+ cmd->ref_name, cmd->error_string);
-+ }
+ else
+ packet_buf_write(&buf, "ng %s %s\n",
+- cmd->ref_name, cmd->error_string);
++ cmd->ref_name, cmd->report.error_message);
}
packet_buf_flush(&buf);
+@@ builtin/receive-pack.c: int cmd_receive_pack(int argc, const char **argv, const char *prefix)
+ if (!check_cert_push_options(&push_options)) {
+ struct command *cmd;
+ for (cmd = commands; cmd; cmd = cmd->next)
+- cmd->error_string = "inconsistent push options";
++ cmd->report.error_message = "inconsistent push options";
+ }
+
+ prepare_shallow_info(&si, &shallow);
+
+ ## remote.h ##
+@@ remote.h: int for_each_remote(each_remote_fn fn, void *priv);
+
+ int remote_has_url(struct remote *remote, const char *url);
+
++struct ref_push_report_options {
++ char *ref_name;
++ struct object_id *old_oid;
++ struct object_id *new_oid;
++ unsigned int forced_update:1;
++ struct ref_push_report_options *next;
++};
++
++struct ref_push_report {
++ const char *message;
++ const char *error_message;
++ struct ref_push_report_options *options;
++};
++
+ struct ref {
+ struct ref *next;
+ struct object_id old_oid;
## t/helper/test-proc-receive.c (new) ##
@@
@@ t/t5411/test-0012-no-hook-error--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : next(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: no hook, fail to push special ref (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:next \
+ HEAD:refs/for/master/topic \
@@ t/t5411/test-0012-no-hook-error--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push --atomic: (B) next(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: no hook, all failed for atomic push (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain --atomic origin \
+ $B:master \
+ HEAD:next \
@@ t/t5411/test-0013-bad-protocol.sh (new)
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive> ok
-+ remote: error: proc-receive expected "<status> <ref> ...", got "ok"
++ remote: error: proc-receive reported incomplete status line: "ok"
+ To <URL/of/upstream.git>
+ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
+ EOF
@@ t/t5411/test-0014-bad-protocol--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: bad protocol (unknown version, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0014-bad-protocol--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : next(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: bad protocol (no report, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/heads/next \
+ HEAD:refs/for/master/topic >out 2>&1 &&
@@ t/t5411/test-0014-bad-protocol--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: bad protocol (no ref, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic\
+ >out 2>&1 &&
@@ t/t5411/test-0014-bad-protocol--porcelain.sh (new)
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive> ok
-+ remote: error: proc-receive expected "<status> <ref> ...", got "ok"
++ remote: error: proc-receive reported incomplete status line: "ok"
+ To <URL/of/upstream.git>
+ ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
+ Done
@@ t/t5411/test-0014-bad-protocol--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: bad protocol (unknown status, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0021-report-ng--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: fail to update (ng, no message, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0021-report-ng--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: fail to update (ng, with message, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0023-report-unexpect-ref--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : (B) refs/for/master/topic
-+test_expect_success "proc-receive: report unexpected ref (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ $B:refs/heads/master \
+ HEAD:refs/for/master/topic \
@@ t/t5411/test-0025-report-unknown-ref--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/a/b/c/my/topic
-+test_expect_success "proc-receive: report unknown reference (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/for/a/b/c/my/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0027-push-options--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push -o ... : refs/for/master/topic
-+test_expect_success "proc-receive: not support push options (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push \
+ --porcelain \
+ -o issue=123 \
@@ t/t5411/test-0027-push-options--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push -o ... : next(A) refs/for/master/topic
-+test_expect_success "proc-receive: push with options (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: push with options ($PROTOCOL/porcelain)" '
+ git -C workbench push \
+ --porcelain \
+ --atomic \
@@ t/t5411/test-0031-report-ok--porcelain.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic
-+test_expect_success "proc-receive: ok (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0031-report-ok--porcelain.sh (new)
+ test_cmp expect actual
+'
- ## t/t5411/test-0032-report-alt.sh (new) ##
+ ## t/t5411/test-0032-report-with-options.sh (new) ##
@@
-+test_expect_success "setup proc-receive hook (alt <ref>, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic"
++ -r "option refname refs/pull/123/head" \
++ -r "option old-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref>, $PROTOCOL)" '
++test_expect_success "proc-receive: report option without matching ok ($PROTOCOL)" '
+ test_must_fail git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0032-report-alt.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic
-+ remote: error: proc-receive expected "alt <ref> <alt-ref> ...", got "alt refs/for/master/topic"
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option old-oid <COMMIT-B>
++ remote: error: proc-receive reported "option" without a matching "ok/ng" directive
+ To <URL/of/upstream.git>
+ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
+ EOF
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> <alt-ref>, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option refname, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/pull/123/head"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/123/head"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, $PROTOCOL)" '
++test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0032-report-alt.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/123/head
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0032-report-alt.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> <alt-ref> forced-update, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/pull/123/head forced-update"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/123/head" \
++ -r "option forced-update"
+ EOF
+'
-+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update, $PROTOCOL)" '
++test_expect_success "proc-receive: report option refname and forced-update ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0032-report-alt.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head forced-update
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option forced-update
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0032-report-alt.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> <alt-ref> old-oid=X, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/pull/123/head old-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/123/head" \
++ -r "option old-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, $PROTOCOL)" '
++test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0032-report-alt.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option old-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0032-report-alt.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> old-oid=X, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic old-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option old-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, $PROTOCOL)" '
++test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0032-report-alt.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0032-report-alt.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> old-oid=X new-oid=Y, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic old-oid=$A new-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, $PROTOCOL)" '
++test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0032-report-alt.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0032-report-alt.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (with multiple alt reports, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
+ -r "ok refs/for/a/b/c/topic" \
-+ -r "alt refs/for/next/topic refs/pull/123/head" \
-+ -r "alt refs/for/master/topic refs/pull/124/head old-oid=$B forced-update new-oid=$A"
++ -r "ok refs/for/next/topic" \
++ -r "option refname refs/pull/123/head" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/124/head" \
++ -r "option old-oid $B" \
++ -r "option forced-update" \
++ -r "option new-oid $A"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: with multiple alt reports ($PROTOCOL)" '
++test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/next/topic \
+ HEAD:refs/for/a/b/c/topic \
@@ t/t5411/test-0032-report-alt.sh (new)
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive> ok refs/for/a/b/c/topic
-+ remote: proc-receive> alt refs/for/next/topic refs/pull/123/head
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A>
++ remote: proc-receive> ok refs/for/next/topic
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/124/head
++ remote: proc-receive> option old-oid <COMMIT-B>
++ remote: proc-receive> option forced-update
++ remote: proc-receive> option new-oid <COMMIT-A>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
@@ t/t5411/test-0032-report-alt.sh (new)
+ test_cmp expect actual
+'
- ## t/t5411/test-0033-report-alt--porcelain.sh (new) ##
+ ## t/t5411/test-0033-report-with-options--porcelain.sh (new) ##
@@
-+test_expect_success "setup proc-receive hook (alt <ref>, --porcelain, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic"
++ -r "option refname refs/pull/123/head" \
++ -r "option old-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref>, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report option without matching ok ($PROTOCOL/porcelain)" '
+ test_must_fail git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic
-+ remote: error: proc-receive expected "alt <ref> <alt-ref> ...", got "alt refs/for/master/topic"
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option old-oid <COMMIT-B>
++ remote: error: proc-receive reported "option" without a matching "ok/ng" directive
+ To <URL/of/upstream.git>
+ ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
+ Done
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> <alt-ref>, --porcelain, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option refname, $PROTOCOL/porcelain)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/pull/123/head"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/123/head"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> <alt-ref>, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/123/head
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> <alt-ref> forced-update, --porcelain, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/pull/123/head forced-update"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/123/head" \
++ -r "option forced-update"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> forced-update, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report option refname and forced-update ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head forced-update
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option forced-update
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> <alt-ref> old-oid=X, --porcelain, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/pull/123/head old-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/123/head" \
++ -r "option old-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> <alt-ref> old-oid=X, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option old-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> old-oid=X, --porcelain, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic old-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option old-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> old-oid=X, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (alt <ref> old-oid=X new-oid=Y, --porcelain, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL/porcelain)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic old-oid=$A new-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report alt (alt <ref> old-oid=X new-oid=Y, --porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (with multiple alt reports, --porcelain, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL/porcelain)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
+ -r "ok refs/for/a/b/c/topic" \
-+ -r "alt refs/for/next/topic refs/pull/123/head" \
-+ -r "alt refs/for/master/topic refs/pull/124/head old-oid=$B forced-update new-oid=$A"
++ -r "ok refs/for/next/topic" \
++ -r "option refname refs/pull/123/head" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/124/head" \
++ -r "option old-oid $B" \
++ -r "option forced-update" \
++ -r "option new-oid $A"
++
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: with multiple alt reports (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/next/topic \
+ HEAD:refs/for/a/b/c/topic \
@@ t/t5411/test-0033-report-alt--porcelain.sh (new)
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive> ok refs/for/a/b/c/topic
-+ remote: proc-receive> alt refs/for/next/topic refs/pull/123/head
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/124/head old-oid=<COMMIT-B> forced-update new-oid=<COMMIT-A>
++ remote: proc-receive> ok refs/for/next/topic
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/124/head
++ remote: proc-receive> option old-oid <COMMIT-B>
++ remote: proc-receive> option forced-update
++ remote: proc-receive> option new-oid <COMMIT-A>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
@@ t/t5411/test-0034-report-ft.sh (new)
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ft refs/for/master/topic"
++ -r "ok refs/for/master/topic" \
++ -r "option fall-through"
+ EOF
+'
+
@@ t/t5411/test-0034-report-ft.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
-+ remote: proc-receive> ft refs/for/master/topic
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option fall-through
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0034-report-ft.sh (new)
## t/t5411/test-0035-report-ft--porcelain.sh (new) ##
@@
-+test_expect_success "setup proc-receive hook (ft, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (fall-through, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ft refs/for/master/topic"
++ -r "ok refs/for/master/topic" \
++ -r "option fall-through"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(B)
-+test_expect_success "proc-receive: fall throught, let receive-pack to execute (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: fall throught, let receive-pack to execute ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ $B:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0035-report-ft--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
-+ remote: proc-receive> ft refs/for/master/topic
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option fall-through
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0035-report-ft--porcelain.sh (new)
+ git -C "$upstream" update-ref -d refs/for/master/topic
+'
- ## t/t5411/test-0036-report-multi-alt-for-one-ref.sh (new) ##
+ ## t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh (new) ##
@@
-+test_expect_success "setup proc-receive hook (multiple alt, no alt-ref for the 1st resp, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic old-oid=$A new-oid=$B" \
-+ -r "alt refs/for/master/topic refs/changes/24/124/1 old-oid=$ZERO_OID new-oid=$A" \
-+ -r "alt refs/for/master/topic refs/changes/25/125/1 old-oid=$A new-oid=$B"
-+ EOF
-+'
-+
-+# Refs of upstream : master(A)
-+# Refs of workbench: master(A) tags/v123
-+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st resp ($PROTOCOL)" '
-+ git -C workbench push origin \
-+ HEAD:refs/for/master/topic \
-+ >out 2>&1 &&
-+ make_user_friendly_and_stable_output <out >actual &&
-+ cat >expect <<-EOF &&
-+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A>
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
-+ remote: # post-receive hook
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ To <URL/of/upstream.git>
-+ * [new reference] HEAD -> refs/for/master/topic
-+ EOF
-+ test_cmp expect actual &&
-+ git -C "$upstream" show-ref >out &&
-+ make_user_friendly_and_stable_output <out >actual &&
-+ cat >expect <<-EOF &&
-+ <COMMIT-A> refs/heads/master
-+ EOF
-+ test_cmp expect actual
-+'
-+
-+test_expect_success "setup proc-receive hook (multiple alt, no alt-ref for the 2nd resp, $PROTOCOL)" '
-+ write_script "$upstream/hooks/proc-receive" <<-EOF
-+ printf >&2 "# proc-receive hook\n"
-+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/changes/24/124/1 old-oid=$ZERO_OID new-oid=$A" \
-+ -r "alt refs/for/master/topic old-oid=$A new-oid=$B" \
-+ -r "alt refs/for/master/topic refs/changes/25/125/1 old-oid=$B new-oid=$A forced-update"
++ -r "ok refs/for/master/topic" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/24/124/1" \
++ -r "option old-oid $ZERO_OID" \
++ -r "option new-oid $A" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/25/125/1" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd resp ($PROTOCOL)" '
++test_expect_success "proc-receive: multiple rewrite for one ref, no refname for the 1st rewrite ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A>
-+ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/24/124/1
++ remote: proc-receive> option old-oid <ZERO-OID>
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/25/125/1
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (ok and alt for the same ref, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
+ -r "ok refs/for/master/topic" \
-+ -r "alt refs/for/master/topic refs/changes/24/124/1 new-oid=$B old-oid=$A"
++ -r "option refname refs/changes/24/124/1" \
++ -r "option old-oid $ZERO_OID" \
++ -r "option new-oid $A" \
++ -r "ok refs/for/master/topic" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/25/125/1" \
++ -r "option old-oid $B" \
++ -r "option new-oid $A" \
++ -r "option forced-update"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report ok and alt for the same ref ($PROTOCOL)" '
++test_expect_success "proc-receive: multiple rewrites for one ref, no refname for the 2nd rewrite ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh (new)
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive> ok refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 new-oid=<COMMIT-B> old-oid=<COMMIT-A>
++ remote: proc-receive> option refname refs/changes/24/124/1
++ remote: proc-receive> option old-oid <ZERO-OID>
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/25/125/1
++ remote: proc-receive> option old-oid <COMMIT-B>
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: proc-receive> option forced-update
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (multiple responses, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/changes/23/123/1" \
-+ -r "alt refs/for/master/topic refs/changes/24/124/2 old-oid=$A new-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/23/123/1" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/24/124/2" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report multiple response ($PROTOCOL)" '
++test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
+ git -C workbench push origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/23/123/1
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/2 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/23/123/1
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/24/124/2
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0036-report-multi-alt-for-one-ref.sh (new)
+ test_cmp expect actual
+'
- ## t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh (new) ##
+ ## t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh (new) ##
@@
-+test_expect_success "setup proc-receive hook (multiple alt, no alt-ref for the 1st resp, $PROTOCOL)" '
-+ write_script "$upstream/hooks/proc-receive" <<-EOF
-+ printf >&2 "# proc-receive hook\n"
-+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic old-oid=$A new-oid=$B" \
-+ -r "alt refs/for/master/topic refs/changes/24/124/1 old-oid=$ZERO_OID new-oid=$A" \
-+ -r "alt refs/for/master/topic refs/changes/25/125/1 old-oid=$A new-oid=$B"
-+ EOF
-+'
-+
-+# Refs of upstream : master(A)
-+# Refs of workbench: master(A) tags/v123
-+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report multiple alt, no alt-ref for the 1st resp (--porcelain, $PROTOCOL)" '
-+ git -C workbench push --porcelain origin \
-+ HEAD:refs/for/master/topic \
-+ >out 2>&1 &&
-+ make_user_friendly_and_stable_output <out >actual &&
-+ cat >expect <<-EOF &&
-+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A>
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
-+ remote: # post-receive hook
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ To <URL/of/upstream.git>
-+ * HEAD:refs/for/master/topic [new reference]
-+ Done
-+ EOF
-+ test_cmp expect actual &&
-+ git -C "$upstream" show-ref >out &&
-+ make_user_friendly_and_stable_output <out >actual &&
-+ cat >expect <<-EOF &&
-+ <COMMIT-A> refs/heads/master
-+ EOF
-+ test_cmp expect actual
-+'
-+
-+test_expect_success "setup proc-receive hook (multiple alt, no alt-ref for the 2nd resp, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/changes/24/124/1 old-oid=$ZERO_OID new-oid=$A" \
-+ -r "alt refs/for/master/topic old-oid=$A new-oid=$B" \
-+ -r "alt refs/for/master/topic refs/changes/25/125/1 old-oid=$B new-oid=$A forced-update"
++ -r "ok refs/for/master/topic" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/24/124/1" \
++ -r "option old-oid $ZERO_OID" \
++ -r "option new-oid $A" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/25/125/1" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report multiple alt, no alt-ref for the 2nd resp (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: multiple rewrite for one ref, no refname for the 1st rewrite ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 old-oid=<ZERO-OID> new-oid=<COMMIT-A>
-+ remote: proc-receive> alt refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/25/125/1 old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/24/124/1
++ remote: proc-receive> option old-oid <ZERO-OID>
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/25/125/1
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (ok and alt for the same ref, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
+ -r "ok refs/for/master/topic" \
-+ -r "alt refs/for/master/topic refs/changes/24/124/1 new-oid=$B old-oid=$A"
++ -r "option refname refs/changes/24/124/1" \
++ -r "option old-oid $ZERO_OID" \
++ -r "option new-oid $A" \
++ -r "ok refs/for/master/topic" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/25/125/1" \
++ -r "option old-oid $B" \
++ -r "option new-oid $A" \
++ -r "option forced-update"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report ok and alt for the same ref (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: multiple rewrites for one ref, no refname for the 2nd rewrite ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh (new)
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive> ok refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/1 new-oid=<COMMIT-B> old-oid=<COMMIT-A>
++ remote: proc-receive> option refname refs/changes/24/124/1
++ remote: proc-receive> option old-oid <ZERO-OID>
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/25/125/1
++ remote: proc-receive> option old-oid <COMMIT-B>
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: proc-receive> option forced-update
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh (new)
+ test_cmp expect actual
+'
+
-+test_expect_success "setup proc-receive hook (multiple responses, $PROTOCOL)" '
++test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "alt refs/for/master/topic refs/changes/23/123/1" \
-+ -r "alt refs/for/master/topic refs/changes/24/124/2 old-oid=$A new-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/23/123/1" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/changes/24/124/2" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : refs/for/master/topic(A)
-+test_expect_success "proc-receive: report multiple response (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ HEAD:refs/for/master/topic \
+ >out 2>&1 &&
@@ t/t5411/test-0037-report-multi-alt-for-one-ref--porcelain.sh (new)
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: # proc-receive hook
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/23/123/1
-+ remote: proc-receive> alt refs/for/master/topic refs/changes/24/124/2 old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/23/123/1
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/changes/24/124/2
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
@@ t/t5411/test-0038-report-mixed-refs.sh (new)
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
+ -r "ok refs/for/next/topic" \
-+ -r "alt refs/for/master/topic refs/for/master/topic old-oid=$A new-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/for/master/topic" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B"
+ EOF
+'
+
@@ t/t5411/test-0038-report-mixed-refs.sh (new)
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive> ok refs/for/next/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
@@ t/t5411/test-0038-report-mixed-refs.sh (new)
+ git update-ref -d refs/heads/bar &&
+ git update-ref -d refs/heads/baz
+ )
-+
+'
## t/t5411/test-0039-report-mixed-refs--porcelain.sh (new) ##
@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh (new)
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
+ -r "ok refs/for/next/topic" \
-+ -r "alt refs/for/master/topic refs/for/master/topic old-oid=$A new-oid=$B"
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/for/master/topic" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B"
+ EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+# git push : (B) bar(A) baz(A) refs/for/next/topic(A) foo(A) refs/for/master/topic(A)
-+test_expect_success "proc-receive: report update of mixed refs (--porcelain, $PROTOCOL)" '
++test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain origin \
+ $B:refs/heads/master \
+ HEAD:refs/heads/bar \
@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh (new)
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive> ok refs/for/next/topic
-+ remote: proc-receive> alt refs/for/master/topic refs/for/master/topic old-oid=<COMMIT-A> new-oid=<COMMIT-B>
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/for/master/topic
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
+ remote: # post-receive hook
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
4: d01004ff52 < -: ---------- send-pack: extension for client-side status report
5: 583b5bdfcd < -: ---------- receive-pack: feed extended_status to post-receive
-: ---------- > 3: 267da25afd New capability "report-status-v2" for git-push
-: ---------- > 4: 2cc92d9383 receive-pack: feed report options to post-receive
6: 860be91506 = 5: 47c5e59c9a refs.c: refactor to reuse ref_is_hidden()
7: 9489db75e6 ! 6: 37e041156f receive-pack: new config receive.procReceiveRefs
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
+ if (proc_receive_refs.nr > 0) {
+ struct strbuf refname_full = STRBUF_INIT;
+ size_t prefix_len;
++
++ strbuf_addstr(&refname_full, get_git_namespace());
++ prefix_len = refname_full.len;
- /* TODO: replace the fixed prefix by looking up git config variables. */
- if (!strncmp(cmd->ref_name, "refs/for/", 9)) {
- cmd->run_proc_receive = RUN_PROC_RECEIVE_SCHEDULED;
- run_proc_receive = 1;
-+ strbuf_addstr(&refname_full, get_git_namespace());
-+ prefix_len = refname_full.len;
-+
+ for (cmd = commands; cmd; cmd = cmd->next) {
+ if (!should_process_cmd(cmd))
+ continue;
@@ t/t5411/test-0040-process-all-refs.sh (new)
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ft refs/heads/master" \
-+ -r "ft refs/heads/foo" \
-+ -r "ft refs/heads/bar" \
-+ -r "alt refs/for/master/topic refs/pull/123/head old-oid=$A new-oid=$B " \
-+ -r "alt refs/for/next/topic refs/pull/124/head old-oid=$B new-oid=$A forced-update"
++ -r "ok refs/heads/master" \
++ -r "option fall-through" \
++ -r "ok refs/heads/foo" \
++ -r "option fall-through" \
++ -r "ok refs/heads/bar" \
++ -r "option fall-through" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/123/head" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B" \
++ -r "ok refs/for/next/topic" \
++ -r "option refname refs/pull/124/head" \
++ -r "option old-oid $B" \
++ -r "option new-oid $A" \
++ -r "option forced-update"
+ EOF
+'
+
@@ t/t5411/test-0040-process-all-refs.sh (new)
+ remote: proc-receive< <COMMIT-B> <COMMIT-A> refs/heads/master
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-+ remote: proc-receive> ft refs/heads/master
-+ remote: proc-receive> ft refs/heads/foo
-+ remote: proc-receive> ft refs/heads/bar
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-A> new-oid=<COMMIT-B>
-+ remote: proc-receive> alt refs/for/next/topic refs/pull/124/head old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update
++ remote: proc-receive> ok refs/heads/master
++ remote: proc-receive> option fall-through
++ remote: proc-receive> ok refs/heads/foo
++ remote: proc-receive> option fall-through
++ remote: proc-receive> ok refs/heads/bar
++ remote: proc-receive> option fall-through
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
++ remote: proc-receive> ok refs/for/next/topic
++ remote: proc-receive> option refname refs/pull/124/head
++ remote: proc-receive> option old-oid <COMMIT-B>
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: proc-receive> option forced-update
+ remote: # post-receive hook
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/bar
+ remote: post-receive< <COMMIT-A> <ZERO-OID> refs/heads/foo
@@ t/t5411/test-0041-process-all-refs--porcelain.sh (new)
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ft refs/heads/master" \
-+ -r "ft refs/heads/foo" \
-+ -r "ft refs/heads/bar" \
-+ -r "alt refs/for/master/topic refs/pull/123/head old-oid=$A new-oid=$B " \
-+ -r "alt refs/for/next/topic refs/pull/124/head old-oid=$B new-oid=$A forced-update"
++ -r "ok refs/heads/master" \
++ -r "option fall-through" \
++ -r "ok refs/heads/foo" \
++ -r "option fall-through" \
++ -r "ok refs/heads/bar" \
++ -r "option fall-through" \
++ -r "ok refs/for/master/topic" \
++ -r "option refname refs/pull/123/head" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B" \
++ -r "ok refs/for/next/topic" \
++ -r "option refname refs/pull/124/head" \
++ -r "option old-oid $B" \
++ -r "option new-oid $A" \
++ -r "option forced-update"
+ EOF
+'
+
+# Refs of upstream : master(B) foo(A) bar(A)) baz(A)
+# Refs of workbench: master(A) tags/v123
+# git push -f : master(A) (NULL) (B) refs/for/master/topic(A) refs/for/next/topic(A)
-+test_expect_success "proc-receive: process all refs (--porcelain) ($PROTOCOL)" '
++test_expect_success "proc-receive: process all refs ($PROTOCOL/porcelain)" '
+ git -C workbench push --porcelain -f origin \
+ HEAD:refs/heads/master \
+ :refs/heads/foo \
@@ t/t5411/test-0041-process-all-refs--porcelain.sh (new)
+ remote: proc-receive< <COMMIT-B> <COMMIT-A> refs/heads/master
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
-+ remote: proc-receive> ft refs/heads/master
-+ remote: proc-receive> ft refs/heads/foo
-+ remote: proc-receive> ft refs/heads/bar
-+ remote: proc-receive> alt refs/for/master/topic refs/pull/123/head old-oid=<COMMIT-A> new-oid=<COMMIT-B>
-+ remote: proc-receive> alt refs/for/next/topic refs/pull/124/head old-oid=<COMMIT-B> new-oid=<COMMIT-A> forced-update
++ remote: proc-receive> ok refs/heads/master
++ remote: proc-receive> option fall-through
++ remote: proc-receive> ok refs/heads/foo
++ remote: proc-receive> option fall-through
++ remote: proc-receive> ok refs/heads/bar
++ remote: proc-receive> option fall-through
++ remote: proc-receive> ok refs/for/master/topic
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
++ remote: proc-receive> ok refs/for/next/topic
++ remote: proc-receive> option refname refs/pull/124/head
++ remote: proc-receive> option old-oid <COMMIT-B>
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: proc-receive> option forced-update
+ remote: # post-receive hook
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/bar
+ remote: post-receive< <COMMIT-A> <ZERO-OID> refs/heads/foo8: 187a723d71 ! 7: 5e08df63d2 doc: add documentation for the proc-receive hook
@@ Documentation/githooks.txt: The default 'update' hook, when enabled--and with
hooks.allowunannotated config option unset or set to false--prevents unannotated tags to be pushed.
++[[proc-receive]]
+proc-receive
+~~~~~~~~~~~~
+
@@ Documentation/githooks.txt: The default 'update' hook, when enabled--and with
+ # NO, I reject it.
+ H: PKT-LINE(ng <ref> <reason>)
+ # Fall through, let 'receive-pack' to execute it.
-+ H: PKT-LINE(ft <ref>)
++ H: PKT-LINE(ok <ref>)
++ H: PKT-LINE(option fall-through)
+ # OK, but has an alternate reference. The alternate reference name
-+ # is given in the third parameter, and other status can be given in
-+ # key-value pairs.
-+ H: PKT-LINE(alt <ref> <alt-ref> old-oid=<old-oid> new-oid=<new-oid>
-+ forced-update)
++ # and other status can be given in options
++ H: PKT-LINE(ok <ref>)
++ H: PKT-LINE(option refname <refname>)
++ H: PKT-LINE(option old-oid <old-oid>)
++ H: PKT-LINE(option new-oid <new-oid>)
++ H: PKT-LINE(option forced-update)
+ H: ... ...
+ H: flush-pkt
+
+Each command for the 'proc-receive' hook may point to a pseudo-reference +and always has a zero-old as its old-oid, while the 'proc-receive' hook +may update an alternate reference and the alternate reference may exist
-+already with a non-zero old-oid. For this case, this hook may return -+different OID and different reference name as extended status of the -+report line.
++already with a non-zero old-oid. For this case, this hook will use ++"option" directives to report extended attributes for the reference given ++by the above "ok/ng" directive.
+
+The report of the commands of this hook should have the same order as +the input. The exit status of the 'proc-receive' hook only determines
----
Jiang Xin (7):
transport: not report a non-head push as a branch
receive-pack: add new proc-receive hook New capability "report-status-v2" for git-push
receive-pack: feed report options to post-receive refs.c: refactor to reuse ref_is_hidden()
receive-pack: new config receive.procReceiveRefs
doc: add documentation for the proc-receive hook
Documentation/config/receive.txt | 14 + Documentation/githooks.txt | 62 +++ Makefile | 1 + builtin/receive-pack.c | 459 ++++++++++++++++-- builtin/send-pack.c | 21 +- refs.c | 13 +- refs.h | 1 + remote.c | 7 +- remote.h | 16 +- send-pack.c | 96 +++- t/helper/test-proc-receive.c | 175 +++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411-proc-receive-hook.sh | 106 ++++ t/t5411/common-functions.sh | 56 +++ t/t5411/test-0000-standard-git-push.sh | 84 ++++ .../test-0001-standard-git-push--porcelain.sh | 86 ++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++ t/t5411/test-0010-proc-receive-settings.sh | 7 + t/t5411/test-0011-no-hook-error.sh | 64 +++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 +++ t/t5411/test-0013-bad-protocol.sh | 225 +++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++ t/t5411/test-0020-report-ng.sh | 67 +++ t/t5411/test-0021-report-ng--porcelain.sh | 69 +++ t/t5411/test-0022-report-unexpect-ref.sh | 45 ++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 ++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 +++ t/t5411/test-0027-push-options--porcelain.sh | 82 ++++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-with-options.sh | 256 ++++++++++ ...est-0033-report-with-options--porcelain.sh | 265 ++++++++++ t/t5411/test-0034-report-ft.sh | 44 ++ t/t5411/test-0035-report-ft--porcelain.sh | 45 ++ ...t-0036-report-multi-rewrite-for-one-ref.sh | 169 +++++++ ...rt-multi-rewrite-for-one-ref--porcelain.sh | 172 +++++++ t/t5411/test-0038-report-mixed-refs.sh | 79 +++ .../test-0039-report-mixed-refs--porcelain.sh | 81 ++++ t/t5411/test-0040-process-all-refs.sh | 113 +++++ .../test-0041-process-all-refs--porcelain.sh | 114 +++++ t/t5516-fetch-push.sh | 2 +- transport-helper.c | 53 +- transport.c | 121 +++-- 47 files changed, 3737 insertions(+), 93 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-with-options.sh create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh
Signature · 1 line
2.26.1.120.g98702cf3e9
Re: [PATCH v14 0/7] New proc-receive hook for centralized workflow
Quoted 5 lines · Jiang Xin
From: Jiang Xin <[email protected]>
This topic introduces a new hook named "proc-receive" for "receive-pack". We can use this hook to implement a Gerrit-like centralized workflow.
https://github.com/git/git/runs/651179641 shows us that osx-clang job ends like so:
Thanks.
Test Summary Report
-------------------t5411-proc-receive-hook.sh (Wstat: 256 Tests: 273 Failed: 0)
Non-zero exit status: 1
Parse errors: Tests out of sequence. Found (27) but expected (26)
Tests out of sequence. Found (28) but expected (27)
Tests out of sequence. Found (29) but expected (28)
Tests out of sequence. Found (30) but expected (29)
Tests out of sequence. Found (31) but expected (30)Displayed the first 5 of 249 TAP syntax errors.
Re-run prove with the -p option to see them all.
Files=906, Tests=22778, 1347 wallclock secs ( 8.21 usr 3.04 sys + 1322.42 cusr 2031.60 csys = 3365.27 CPU)
Result: FAIL
make[1]: *** [prove] Error 1
make: *** [test] Error 2
##[error]Process completed with exit code 2.
Re: [PATCH v14 0/7] New proc-receive hook for centralized workflow
Quoted 19 lines · Junio C Hamano <[email protected]> 于2020年5月7日周四 上午7:14写道:
Quoted 5 lines · Jiang Xin
From: Jiang Xin <[email protected]>
This topic introduces a new hook named "proc-receive" for "receive-pack". We can use this hook to implement a Gerrit-like centralized workflow.
https://github.com/git/git/runs/651179641 shows us that osx-clang job ends like so:
Thanks.
Test Summary Report
-------------------t5411-proc-receive-hook.sh(Wstat: 256 Tests: 273 Failed: 0)
Non-zero exit status: 1
Quoted 5 lines
Parse errors: Tests out of sequence. Found (27) but expected (26)
Tests out of sequence. Found (28) but expected (27)
Tests out of sequence. Found (29) but expected (28)
Tests out of sequence. Found (30) but expected (29)
Tests out of sequence. Found (31) but expected (30)It seems that the status report for git-push ("ok <refname>") confuses the test. Will fix it in next reroll.
Re: [PATCH v14 0/7] New proc-receive hook for centralized workflow
Quoted 27 lines · Jiang Xin <[email protected]> 于2020年5月7日周四 上午9:37写道:
Quoted 19 lines · Junio C Hamano <[email protected]> 于2020年5月7日周四 上午7:14写道:
Quoted 5 lines · Jiang Xin
From: Jiang Xin <[email protected]>
This topic introduces a new hook named "proc-receive" for "receive-pack". We can use this hook to implement a Gerrit-like centralized workflow.
https://github.com/git/git/runs/651179641 shows us that osx-clang job ends like so:
Thanks.
Test Summary Report
-------------------t5411-proc-receive-hook.sh(Wstat: 256 Tests: 273 Failed: 0)
Non-zero exit status: 1Quoted 5 lines
Parse errors: Tests out of sequence. Found (27) but expected (26) Tests out of sequence. Found (28) but expected (27) Tests out of sequence. Found (29) but expected (28) Tests out of sequence. Found (30) but expected (29) Tests out of sequence. Found (31) but expected (30)
Quoted 2 lines
It seems that the status report for git-push ("ok <refname>") confuses the test. Will fix it in next reroll.
This morning I cannot find the specific error from the build log, but now I find the error output inside the job tagged as "Run ci/print-test-failures.sh":
++++ diff -u expect actual
--- expect 2020-05-06 22:47:02.000000000 +0000
+++ actual 2020-05-06 22:47:02.000000000 +0000
@@ -2,5 +2,6 @@
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
remote: # proc-receive hook
remote: fatal: protocol error: expected "old new ref", got
"<ZERO-OID> <COMMIT-A> refs/for/master/topic"
-To <URL/of/upstream.git>
- ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive
failed to report status)
+fatal: unable to write flush packet: Broken pipe +fatal: the remote end hung up unexpectedly
+fatal: the remote end hung up unexpectedly
In order to increase the code coverage (thanks Stolee for sending a nice code coverage report), I add an option "--die-readline" for test-helper (t/helper/test-proc-receive):
if (parse_oid_hex(reader->line, &old_oid, &p) ||
*p++ != ' ' ||
parse_oid_hex(p, &new_oid, &p) ||
*p++ != ' ' ||
die_readline)
die("protocol error: expected 'old new ref', got '%s'",
reader->line);Hook "proc-receive" hook will die early with the "--die_readline" option, and "receive-pack" should continue running because "receive-pack" ignores the SIG_PIPE signal, but I don't know why the behaviors of "receive-pack" are quite different on different platforms.
I will rewrite the test case using "grep" instead of "test_cmp", and may send another reroll tonight.
--
Jiang Xin
PATCH v15 1/7 transport: not report a non-head push as a branch
In reply to Junio C HamanoFrom: Jiang Xin <[email protected]>
When pushing a new reference (not a head or tag), report it as a new reference instead of a new branch.
--- t/t5411-proc-receive-hook.sh | 108 ++++++++++++++++++ t/t5411/common-functions.sh | 56 +++++++++ t/t5411/test-0000-standard-git-push.sh | 84 ++++++++++++++ .../test-0001-standard-git-push--porcelain.sh | 86 ++++++++++++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++++++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++++++ t/t5516-fetch-push.sh | 2 +- transport.c | 9 +- 8 files changed, 408 insertions(+), 4 deletions(-) create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh
t/t5411-proc-receive-hook.sh new file +108 -0
@@ -0,0 +1,108 @@ +#!/bin/sh +# +# Copyright (c) 2020 Jiang Xin +# + +test_description='Test proc-receive hook' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/t5411/common-functions.sh + +setup_upstream_and_workbench () { + # Refs of upstream : master(A) + # Refs of workbench: master(A) tags/v123 + test_expect_success "setup upstream and workbench" ' + rm -rf upstream.git && + rm -rf workbench && + git init --bare upstream.git && + git init workbench && + create_commits_in workbench A B && + ( + cd workbench && + # Try to make a stable fixed width for abbreviated commit ID, + # this fixed-width oid will be replaced with "<OID>". + git config core.abbrev 7 && + git remote add origin ../upstream.git && + git update-ref refs/heads/master $A && + git tag -m "v123" v123 $A && + git push origin $B:refs/heads/master && + git -C ../upstream.git update-ref \ + refs/heads/master $A + ) && + TAG=$(git -C workbench rev-parse v123) && + + # setup pre-receive hook + write_script upstream.git/hooks/pre-receive <<-\EOF && + exec >&2 + echo "# pre-receive hook" + while read old new ref + do + echo "pre-receive< $old $new $ref" + done + EOF + + # setup post-receive hook + write_script upstream.git/hooks/post-receive <<-\EOF && + exec >&2 + echo "# post-receive hook" + while read old new ref + do + echo "post-receive< $old $new $ref" + done + EOF + + upstream=upstream.git + ' +} + +run_proc_receive_hook_test() { + case $1 in + http) + PROTOCOL="HTTP protocol" + URL_PREFIX="http://.*" + ;; + local) + PROTOCOL="builtin protocol" + URL_PREFIX="\.\." + ;; + esac + + # Include test cases for both file and HTTP protocol + for t in "$TEST_DIRECTORY"/t5411/test-*.sh + do + . "$t" + done +} + +# Initialize the upstream repository and local workbench. +setup_upstream_and_workbench + +# Run test cases for 'proc-receive' hook on local file protocol. +run_proc_receive_hook_test local + +ROOT_PATH="$PWD" +. "$TEST_DIRECTORY"/lib-gpg.sh +. "$TEST_DIRECTORY"/lib-httpd.sh +. "$TEST_DIRECTORY"/lib-terminal.sh +start_httpd + +# Re-initialize the upstream repository and local workbench. +setup_upstream_and_workbench + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +test_expect_success "setup for HTTP protocol" ' + git -C upstream.git config http.receivepack true && + upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" && + mv upstream.git "$upstream" && + set_askpass user@host pass@host && + git -C workbench remote set-url origin $HTTPD_URL/smart/upstream.git +' + +setup_askpass_helper + +# Run test cases for 'proc-receive' hook on HTTP protocol. +run_proc_receive_hook_test http + +test_done
t/t5411/common-functions.sh new file +56 -0
56 lines not on this page · raw message
t/t5411/test-0000-standard-git-push.sh new file +84 -0
84 lines not on this page · raw message
t/t5411/test-0001-standard-git-push--porcelain.sh new file +86 -0
86 lines not on this page · raw message
t/t5411/test-0002-pre-receive-declined.sh new file +33 -0
@@ -0,0 +1,33 @@ +test_expect_success "setup pre-receive hook ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && + write_script "$upstream/hooks/pre-receive" <<-EOF + exit 1 + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git-push : master(B) next(A) +test_expect_success "git-push is declined ($PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + $B:refs/heads/master \ + HEAD:refs/heads/next \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] <COMMIT-B> -> master (pre-receive hook declined) + ! [remote rejected] HEAD -> next (pre-receive hook declined) + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +' + +test_expect_success "cleanup ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive" +'
t/t5411/test-0003-pre-receive-declined--porcelain.sh new file +34 -0
@@ -0,0 +1,34 @@ +test_expect_success "setup pre-receive hook ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && + write_script "$upstream/hooks/pre-receive" <<-EOF + exit 1 + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git-push : master(B) next(A) +test_expect_success "git-push is declined ($PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + $B:refs/heads/master \ + HEAD:refs/heads/next \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! <COMMIT-B>:refs/heads/master [remote rejected] (pre-receive hook declined) + ! HEAD:refs/heads/next [remote rejected] (pre-receive hook declined) + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +' + +test_expect_success "cleanup ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive" +'
t/t5516-fetch-push.sh +1 -1
@@ -1039,7 +1039,7 @@ test_force_fetch_tag "annotated tag" "-f -a -m'tag message'" test_expect_success 'push --porcelain' ' mk_empty testrepo && echo >.git/foo "To testrepo" && - echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" && + echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new reference]" && echo >>.git/foo "Done" && git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && (
transport.c +6 -3
@@ -500,9 +500,12 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt porcelain, summary_width); else if (is_null_oid(&ref->old_oid))print_ref_status ('*' , - (starts_with (ref->name,"refs/tags/" ) ?"[new tag]" : -"[new branch]" ), - ref, ref->peer_ref,NULL , porcelain, summary_width); + (starts_with (ref->name,"refs/tags/" ) + ?"[new tag]" + : (starts_with (ref->name,"refs/heads/" ) + ?"[new branch]" + :"[new reference]" )), + ref, ref->peer_ref,NULL , porcelain, summary_width); else {struct strbuf quickref =STRBUF_INIT ;char type;
Signature · 1 line
2.26.1.120.g98702cf3e9
v15 cover New proc-receive hook for centralized workflow
In reply to Junio C HamanoFrom: Jiang Xin <[email protected]>
This topic introduces a new hook named "proc-receive" for "receive-pack". We can use this hook to implement a Gerrit-like centralized workflow.
## Changes since v14
1. Fixed broken test case in patch 2/7, and all test cases passed.
See: https://github.com/jiangxin/git/runs/653492851
2. Bugfix: if "proc-receive" report a "ng" status, other successfully updated references will be reported as failure. Fixed in patch 2/7.
3. Add test case for report status v1 in "t5411/once-0010" in patch 3/7.
## Range-diff v14...v15
1: 805db643dd ! 1: 06dd984d35 transport: not report a non-head push as a branch
@@ t/t5411-proc-receive-hook.sh (new)
+ git remote add origin ../upstream.git &&
+ git update-ref refs/heads/master $A &&
+ git tag -m "v123" v123 $A &&
-+ git push origin $A:refs/heads/master
++ git push origin $B:refs/heads/master &&
++ git -C ../upstream.git update-ref \
++ refs/heads/master $A
+ ) &&
+ TAG=$(git -C workbench rev-parse v123) &&
+
@@ t/t5411-proc-receive-hook.sh (new)
+ PROTOCOL="HTTP protocol" + URL_PREFIX="http://.*"
+ ;;
-+ file | local)
++ local)
+ PROTOCOL="builtin protocol"
+ URL_PREFIX="\.\."
+ ;;
2: d6db85a4e5 ! 2: 1c11a5dcc6 receive-pack: add new proc-receive hook
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
+ if (run_proc_receive &&
+ run_proc_receive_hook(commands, push_options))
+ for (cmd = commands; cmd; cmd = cmd->next)
-+ if (!cmd->report.error_message && (cmd->run_proc_receive || use_atomic))
++ if (!cmd->report.error_message &&
++ !(cmd->run_proc_receive & RUN_PROC_RECEIVE_RETURNED) &&
++ (cmd->run_proc_receive || use_atomic))
+ cmd->report.error_message = "fail to run proc-receive hook";
+
if (use_atomic)
@@ t/t5411/test-0013-bad-protocol.sh (new)
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+
-+ cat >expect <<-EOF &&
-+ remote: # pre-receive hook
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: # proc-receive hook
-+ remote: fatal: protocol error: expected "old new ref", got "<ZERO-OID> <COMMIT-A> refs/for/master/topic"
-+ To <URL/of/upstream.git>
-+ ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
-+ EOF
-+ test_cmp expect actual &&
++ grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/master/topic\"" actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
@@ t/t5411/test-0038-report-mixed-refs.sh (new)
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ok refs/for/next/topic" \
++ -r "ok refs/for/next/topic2" \
++ -r "ng refs/for/next/topic1 fail to call Web API" \
+ -r "ok refs/for/master/topic" \
+ -r "option refname refs/for/master/topic" \
+ -r "option old-oid $A" \
@@ t/t5411/test-0038-report-mixed-refs.sh (new)
+# Refs of workbench: master(A) tags/v123
+# git push : (B) bar(A) baz(A) refs/for/next/topic(A) foo(A) refs/for/master/topic(A)
+test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
-+ git -C workbench push origin \
++ test_must_fail git -C workbench push origin \
+ $B:refs/heads/master \
+ HEAD:refs/heads/bar \
+ HEAD:refs/heads/baz \
-+ HEAD:refs/for/next/topic \
++ HEAD:refs/for/next/topic2 \
++ HEAD:refs/for/next/topic1 \
+ HEAD:refs/heads/foo \
+ HEAD:refs/for/master/topic \
++ HEAD:refs/for/next/topic3 \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
@@ t/t5411/test-0038-report-mixed-refs.sh (new)
+ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic1
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic3
+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic1
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> ok refs/for/next/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic3
++ remote: proc-receive> ok refs/for/next/topic2
++ remote: proc-receive> ng refs/for/next/topic1 fail to call Web API
+ remote: proc-receive> ok refs/for/master/topic
+ remote: proc-receive> option refname refs/for/master/topic
+ remote: proc-receive> option old-oid <COMMIT-A>
@@ t/t5411/test-0038-report-mixed-refs.sh (new)
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+ <OID-A>..<OID-B> <COMMIT-B> -> master
+ * [new branch] HEAD -> bar
+ * [new branch] HEAD -> baz
-+ * [new reference] HEAD -> refs/for/next/topic
++ * [new reference] HEAD -> refs/for/next/topic2
+ * [new branch] HEAD -> foo
+ * [new reference] HEAD -> refs/for/master/topic
++ ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API)
++ ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
+ EOF
+ test_cmp expect actual &&
+ git -C "$upstream" show-ref >out &&
@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh (new)
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+ test-tool proc-receive -v \
-+ -r "ok refs/for/next/topic" \
++ -r "ok refs/for/next/topic2" \
++ -r "ng refs/for/next/topic1 fail to call Web API" \
+ -r "ok refs/for/master/topic" \
+ -r "option refname refs/for/master/topic" \
+ -r "option old-oid $A" \
@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh (new)
+# Refs of workbench: master(A) tags/v123
+# git push : (B) bar(A) baz(A) refs/for/next/topic(A) foo(A) refs/for/master/topic(A)
+test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcelain)" '
-+ git -C workbench push --porcelain origin \
++ test_must_fail git -C workbench push --porcelain origin \
+ $B:refs/heads/master \
+ HEAD:refs/heads/bar \
+ HEAD:refs/heads/baz \
-+ HEAD:refs/for/next/topic \
++ HEAD:refs/for/next/topic2 \
++ HEAD:refs/for/next/topic1 \
+ HEAD:refs/heads/foo \
+ HEAD:refs/for/master/topic \
++ HEAD:refs/for/next/topic3 \
+ >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh (new)
+ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
-+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic1
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic3
+ remote: # proc-receive hook
-+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic1
+ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
-+ remote: proc-receive> ok refs/for/next/topic
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic3
++ remote: proc-receive> ok refs/for/next/topic2
++ remote: proc-receive> ng refs/for/next/topic1 fail to call Web API
+ remote: proc-receive> ok refs/for/master/topic
+ remote: proc-receive> option refname refs/for/master/topic
+ remote: proc-receive> option old-oid <COMMIT-A>
@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh (new)
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
-+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ To <URL/of/upstream.git>
+ <COMMIT-B>:refs/heads/master <OID-A>..<OID-B>
+ * HEAD:refs/heads/bar [new branch]
+ * HEAD:refs/heads/baz [new branch]
-+ * HEAD:refs/for/next/topic [new reference]
++ * HEAD:refs/for/next/topic2 [new reference]
+ * HEAD:refs/heads/foo [new branch]
+ * HEAD:refs/for/master/topic [new reference]
++ ! HEAD:refs/for/next/topic1 [remote rejected] (fail to call Web API)
++ ! HEAD:refs/for/next/topic3 [remote rejected] (proc-receive failed to report status)
+ Done
+ EOF
+ test_cmp expect actual &&
3: 342254d81d ! 3: c7f731b9f6 New capability "report-status-v2" for git-push
@@ remote.c: void free_one_ref(struct ref *ref)
free(ref->symref);
free(ref);
}
-@@ remote.c: void apply_push_cas(struct push_cas_option *cas,
- struct ref *ref;
- for (ref = remote_refs; ref; ref = ref->next)
- apply_cas(cas, remote, ref);
--}
-+}
- \ No newline at end of file
## remote.h ##
@@ remote.h: struct ref {
@@ send-pack.c: static int receive_status(struct packet_reader *reader, struct ref
if (packet_reader_read(reader) != PACKET_READ_NORMAL)
break;
- if (!starts_with(reader->line, "ok ") && !starts_with(reader->line, "ng ")) {
+- error("invalid ref status from remote: %s", reader->line);
+ head = reader->line;
+ p = strchr(head, ' ');
+ if (!p) {
- error("invalid ref status from remote: %s", reader->line);
++ error("invalid status line from remote: %s", reader->line);
ret = -1;
break;
}
@@ send-pack.c: static int receive_status(struct packet_reader *reader, struct ref
- msg = strchr(refname, ' ');
- if (msg)
- *msg++ = '\0';
-+ refname = p;
-+ p = strchr(refname, ' ');
-+ if (p)
-+ *p++ = '\0';
+-
+ if (strcmp(head, "ok") && strcmp(head, "ng")) {
-+ error("invalid ref status from remote: %s", reader->line);
++ error("invalid ref status from remote: %s", head);
+ ret = -1;
+ break;
+ }
-
++ refname = p;
++ p = strchr(refname, ' ');
++ if (p)
++ *p++ = '\0';
/* first try searching at our hint, falling back to all refs */
if (hint)
+ hint = find_ref_by_name(hint, refname);
@@ send-pack.c: static int receive_status(struct packet_reader *reader, struct ref *refs)
refname);
continue;
@@ send-pack.c: int send_pack(struct send_pack_args *args,
strbuf_addstr(&cap_buf, " side-band-64k");
if (quiet_supported && (args->quiet || !args->progress))
+ ## t/t5411-proc-receive-hook.sh ##
+@@ t/t5411-proc-receive-hook.sh: run_proc_receive_hook_test() {
+ # Initialize the upstream repository and local workbench.
+ setup_upstream_and_workbench
+
++# Load test cases that only need to be executed once.
++for t in "$TEST_DIRECTORY"/t5411/once-*.sh
++do
++ . "$t"
++done
++
+ # Run test cases for 'proc-receive' hook on local file protocol.
+ run_proc_receive_hook_test local
+
+
+ ## t/t5411/once-0010-report-status-v1.sh (new) ##
+@@
++test_expect_success "setup proc-receive hook" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/for/master/topic1" \
++ -r "option fall-through" \
++ -r "ok refs/for/master/topic2" \
++ -r "option refname refs/for/changes/23/123/1" \
++ -r "option new-oid $A" \
++ -r "ok refs/for/master/topic2" \
++ -r "option refname refs/for/changes/24/124/2" \
++ -r "option old-oid $B" \
++ -r "option new-oid $A" \
++ -r "option forced-update" \
++ -r "ng refs/for/next/topic target branch not exist"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : (B) refs/for/master/topic1(A) foo(A) refs/for/next/topic(A) refs/for/master/topic2(A)
++test_expect_success "proc-receive: report status v1" '
++ {
++ printf "%s %s refs/heads/master\0report-status\n" \
++ $A $B | packetize &&
++ printf "%s %s refs/for/master/topic1\n" \
++ $ZERO_OID $A | packetize &&
++ printf "%s %s refs/heads/foo\n" \
++ $ZERO_OID $A | packetize &&
++ printf "%s %s refs/for/next/topic\n" \
++ $ZERO_OID $A | packetize &&
++ printf "%s %s refs/for/master/topic2\n" \
++ $ZERO_OID $A | packetize &&
++ printf 0000 &&
++ printf "" | git -C "$upstream" pack-objects --stdout
++ } | git receive-pack "$upstream" --stateless-rpc \
++ >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ # pre-receive hook
++ pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic1
++ pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
++ pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic2
++ # proc-receive hook
++ proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic1
++ proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
++ proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic2
++ proc-receive> ok refs/for/master/topic1
++ proc-receive> option fall-through
++ proc-receive> ok refs/for/master/topic2
++ proc-receive> option refname refs/for/changes/23/123/1
++ proc-receive> option new-oid <COMMIT-A>
++ proc-receive> ok refs/for/master/topic2
++ proc-receive> option refname refs/for/changes/24/124/2
++ proc-receive> option old-oid <COMMIT-B>
++ proc-receive> option new-oid <COMMIT-A>
++ proc-receive> option forced-update
++ proc-receive> ng refs/for/next/topic target branch not exist
++ 000eunpack ok
++ 0019ok refs/heads/master
++ 001eok refs/for/master/topic1
++ 0016ok refs/heads/foo
++ 0033ng refs/for/next/topic target branch not exist
++ 001eok refs/for/master/topic2
++ 0000# post-receive hook
++ post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic1
++ post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
++ post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic2
++ EOF
++ test_cmp expect actual &&
++
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/for/master/topic1
++ <COMMIT-A> refs/heads/foo
++ <COMMIT-B> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(B) foo(A) refs/for/master/topic1(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "cleanup" '
++ (
++ cd "$upstream" &&
++ rm -f "hooks/proc-receive" &&
++ git update-ref refs/heads/master $A &&
++ git update-ref -d refs/for/master/topic1 &&
++ git update-ref -d refs/heads/foo
++ )
++'
+
## t/t5411/test-0032-report-with-options.sh ##
@@ t/t5411/test-0032-report-with-options.sh: test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
remote: # post-receive hook
@@ t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh: test_expect_su
## t/t5411/test-0038-report-mixed-refs.sh ##
@@ t/t5411/test-0038-report-mixed-refs.sh: test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
* [new branch] HEAD -> baz
- * [new reference] HEAD -> refs/for/next/topic
+ * [new reference] HEAD -> refs/for/next/topic2
* [new branch] HEAD -> foo
- * [new reference] HEAD -> refs/for/master/topic
+ <OID-A>..<OID-B> HEAD -> refs/for/master/topic
+ ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API)
+ ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
EOF
- test_cmp expect actual &&
- git -C "$upstream" show-ref >out &&
## t/t5411/test-0039-report-mixed-refs--porcelain.sh ##
@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh: test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
* HEAD:refs/heads/baz [new branch]
- * HEAD:refs/for/next/topic [new reference]
+ * HEAD:refs/for/next/topic2 [new reference]
* HEAD:refs/heads/foo [new branch]
- * HEAD:refs/for/master/topic [new reference]
+ HEAD:refs/for/master/topic <OID-A>..<OID-B>
+ ! HEAD:refs/for/next/topic1 [remote rejected] (fail to call Web API)
+ ! HEAD:refs/for/next/topic3 [remote rejected] (proc-receive failed to report status)
Done
- EOF
- test_cmp expect actual &&
## transport-helper.c ##
@@ transport-helper.c: static int push_update_ref_status(struct strbuf *buf,4: 5c9b732a38 ! 4: 11b917121f receive-pack: feed report options to post-receive
@@ builtin/receive-pack.c: static int feed_receive_hook(void *state_, const char **
*bufp = state->buf.buf;
*sizep = state->buf.len;
+ ## t/t5411/once-0010-report-status-v1.sh ##
+@@ t/t5411/once-0010-report-status-v1.sh: test_expect_success "proc-receive: report status v1" '
+ post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
+ post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic1
+ post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
+- post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic2
++ post-receive< <ZERO-OID> <COMMIT-A> refs/for/changes/23/123/1
++ post-receive< <COMMIT-B> <COMMIT-A> refs/for/changes/24/124/2
+ EOF
+ test_cmp expect actual &&
+
+
## t/t5411/test-0032-report-with-options.sh ##
@@ t/t5411/test-0032-report-with-options.sh: test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
remote: proc-receive> ok refs/for/master/topic
@@ t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh: test_expect_su
## t/t5411/test-0038-report-mixed-refs.sh ##
@@ t/t5411/test-0038-report-mixed-refs.sh: test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
- remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
- remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
@@ t/t5411/test-0038-report-mixed-refs.sh: test_expect_success "proc-receive: repor
## t/t5411/test-0039-report-mixed-refs--porcelain.sh ##
@@ t/t5411/test-0039-report-mixed-refs--porcelain.sh: test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
- remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
- remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
5: cf0774127f = 5: 7b84236103 refs.c: refactor to reuse ref_is_hidden() 6: 8053b06b09 ! 6: 9d9032285b receive-pack: new config receive.procReceiveRefs
@@ builtin/receive-pack.c: int cmd_receive_pack(int argc, const char **argv, const
return 0;
}
+ ## t/t5411/once-0010-report-status-v1.sh ##
+@@
++test_expect_success "setup receive.procReceiveRefs" '
++ git -C "$upstream" config --add receive.procReceiveRefs refs/for
++'
++
+ test_expect_success "setup proc-receive hook" '
+ write_script "$upstream/hooks/proc-receive" <<-EOF
+ printf >&2 "# proc-receive hook\n"
+@@ t/t5411/once-0010-report-status-v1.sh: test_expect_success "proc-receive: report status v1" '
+ test_expect_success "cleanup" '
+ (
+ cd "$upstream" &&
++ git config --unset receive.procReceiveRefs &&
+ rm -f "hooks/proc-receive" &&
+ git update-ref refs/heads/master $A &&
+ git update-ref -d refs/for/master/topic1 &&
+
## t/t5411/test-0010-proc-receive-settings.sh (new) ##
@@
+test_expect_success "add two receive.procReceiveRefs settings" '
7: 861b21d471 = 7: 1a3f58652d doc: add documentation for the proc-receive hook
----
Jiang Xin (7):
transport: not report a non-head push as a branch
receive-pack: add new proc-receive hook New capability "report-status-v2" for git-push
receive-pack: feed report options to post-receive refs.c: refactor to reuse ref_is_hidden()
receive-pack: new config receive.procReceiveRefs
doc: add documentation for the proc-receive hook
Documentation/config/receive.txt | 14 + Documentation/githooks.txt | 62 +++ Makefile | 1 + builtin/receive-pack.c | 461 ++++++++++++++++-- builtin/send-pack.c | 21 +- refs.c | 13 +- refs.h | 1 + remote.c | 5 +- remote.h | 16 +- send-pack.c | 98 +++- t/helper/test-proc-receive.c | 175 +++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411-proc-receive-hook.sh | 114 +++++ t/t5411/common-functions.sh | 56 +++ t/t5411/once-0010-report-status-v1.sh | 101 ++++ t/t5411/test-0000-standard-git-push.sh | 84 ++++ .../test-0001-standard-git-push--porcelain.sh | 86 ++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++ t/t5411/test-0010-proc-receive-settings.sh | 7 + t/t5411/test-0011-no-hook-error.sh | 64 +++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 +++ t/t5411/test-0013-bad-protocol.sh | 217 +++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++ t/t5411/test-0020-report-ng.sh | 67 +++ t/t5411/test-0021-report-ng--porcelain.sh | 69 +++ t/t5411/test-0022-report-unexpect-ref.sh | 45 ++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 ++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 +++ t/t5411/test-0027-push-options--porcelain.sh | 82 ++++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-with-options.sh | 256 ++++++++++ ...est-0033-report-with-options--porcelain.sh | 265 ++++++++++ t/t5411/test-0034-report-ft.sh | 44 ++ t/t5411/test-0035-report-ft--porcelain.sh | 45 ++ ...t-0036-report-multi-rewrite-for-one-ref.sh | 169 +++++++ ...rt-multi-rewrite-for-one-ref--porcelain.sh | 172 +++++++ t/t5411/test-0038-report-mixed-refs.sh | 89 ++++ .../test-0039-report-mixed-refs--porcelain.sh | 91 ++++ t/t5411/test-0040-process-all-refs.sh | 113 +++++ .../test-0041-process-all-refs--porcelain.sh | 114 +++++ t/t5516-fetch-push.sh | 2 +- transport-helper.c | 53 +- transport.c | 121 +++-- 48 files changed, 3859 insertions(+), 94 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/once-0010-report-status-v1.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-with-options.sh create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh
Signature · 1 line
2.26.1.120.g98702cf3e9
v16 cover New proc-receive hook for centralized workflow
From: Jiang Xin <[email protected]>
This topic introduces a new hook named "proc-receive" for "receive-pack". We can use this hook to implement a Gerrit-like centralized workflow.
## Changes since v15
1. Parse report options in function transport_update_tracking_ref() in order to update remote-tracking branches properly.
See patch 9/11 and 10/11.
2. Add docs for 'report-status-v2' in 'Documentation/technical/ pack-protocol.txt', and other files.
See patch 5/11.
3. Remove unnecessary headers:
--- a/remote.c
+++ b/remote.c
@@ -1,6 +1,5 @@
#include "cache.h"
#include "config.h"
-#include "connect.h"
#include "remote.h"
#include "refs.h"
#include "refspec.h"
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -3,7 +3,6 @@
#include "parse-options.h"
#include "pkt-line.h"
#include "sigchain.h"
-#include "string-list.h"
#include "test-tool.h"
static const char *proc_receive_usage[] = {4. Fix format issues:
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -2262,7 +2262,7 @@ static void report(struct command *commands, const char *unpack_status)
for (cmd = commands; cmd; cmd = cmd->next) {
if (!cmd->report.error_message)
packet_buf_write(&buf, "ok %s\n",
- cmd->ref_name);
+ cmd->ref_name);
else
packet_buf_write(&buf, "ng %s %s\n",
cmd->ref_name, cmd->report.error_message);
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -101,13 +101,13 @@ static void print_helper_status(struct ref *ref)
strbuf_addf(&buf, "ok %s\n", ref->name);
if (options->ref_name)
strbuf_addf(&buf, "option refname %s\n",
- options->ref_name);
+ options->ref_name);
if (options->old_oid)
strbuf_addf(&buf, "option old-oid %s\n",
- oid_to_hex(options->old_oid));
+ oid_to_hex(options->old_oid));
if (options->new_oid)
strbuf_addf(&buf, "option new-oid %s\n",
- oid_to_hex(options->new_oid));
+ oid_to_hex(options->new_oid));
if (options->forced_update)
strbuf_addstr(&buf, "option forced-update\n");
}5. Other minor changes:
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -806,7 +806,7 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
if (options) {
struct object_id *old_oid;
struct object_id *new_oid;
- char *ref_name;
+ const char *ref_name;
old_oid = options->old_oid ? options->old_oid : &cmd->old_oid;
new_oid = options->new_oid ? options->new_oid : &cmd->new_oid;
--- a/remote.h
+++ b/remote.h
@@ -94,7 +94,7 @@ int for_each_remote(each_remote_fn fn, void *priv);
int remote_has_url(struct remote *remote, const char *url);
struct ref_push_report_options {
- char *ref_name;
+ const char *ref_name;
struct object_id *old_oid;
struct object_id *new_oid;
unsigned int forced_update:1;----
Jiang Xin (11):
transport: not report a non-head push as a branch
t5411: add basic test cases for proc-receive hook
receive-pack: add new proc-receive hook New capability "report-status-v2" for git-push
doc: add document for capability report-status-v2
receive-pack: feed report options to post-receive refs.c: refactor to reuse ref_is_hidden()
receive-pack: new config receive.procReceiveRefs
t5411: test updates of remote-tracking branches
transport: parse report options for tracking refs
doc: add documentation for the proc-receive hook
Documentation/config/receive.txt | 14 + Documentation/githooks.txt | 62 +++ Documentation/technical/pack-protocol.txt | 43 +- .../technical/protocol-capabilities.txt | 17 +- Makefile | 1 + builtin/receive-pack.c | 461 ++++++++++++++++-- builtin/send-pack.c | 21 +- refs.c | 13 +- refs.h | 1 + remote.c | 4 +- remote.h | 16 +- send-pack.c | 99 +++- t/helper/test-proc-receive.c | 174 +++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411-proc-receive-hook.sh | 117 +++++ t/t5411/common-functions.sh | 56 +++ t/t5411/once-0010-report-status-v1.sh | 88 ++++ t/t5411/test-0000-standard-git-push.sh | 143 ++++++ .../test-0001-standard-git-push--porcelain.sh | 147 ++++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++ t/t5411/test-0010-proc-receive-settings.sh | 7 + t/t5411/test-0011-no-hook-error.sh | 64 +++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 +++ t/t5411/test-0013-bad-protocol.sh | 217 +++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++ t/t5411/test-0020-report-ng.sh | 67 +++ t/t5411/test-0021-report-ng--porcelain.sh | 69 +++ t/t5411/test-0022-report-unexpect-ref.sh | 45 ++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 ++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 +++ t/t5411/test-0027-push-options--porcelain.sh | 82 ++++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-with-options.sh | 256 ++++++++++ ...est-0033-report-with-options--porcelain.sh | 265 ++++++++++ t/t5411/test-0034-report-ft.sh | 44 ++ t/t5411/test-0035-report-ft--porcelain.sh | 45 ++ ...t-0036-report-multi-rewrite-for-one-ref.sh | 227 +++++++++ ...rt-multi-rewrite-for-one-ref--porcelain.sh | 172 +++++++ t/t5411/test-0038-report-mixed-refs.sh | 89 ++++ .../test-0039-report-mixed-refs--porcelain.sh | 91 ++++ t/t5411/test-0040-process-all-refs.sh | 113 +++++ .../test-0041-process-all-refs--porcelain.sh | 114 +++++ t/t5516-fetch-push.sh | 2 +- transport-helper.c | 53 +- transport.c | 161 ++++-- 50 files changed, 4109 insertions(+), 111 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/once-0010-report-status-v1.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-with-options.sh create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh
Signature · 1 line
2.26.1.120.g98702cf3e9
PATCH v17 1/10 transport: not report a non-head push as a branch
From: Jiang Xin <[email protected]>
When pushing a new reference (not a head or tag), report it as a new reference instead of a new branch.
--- t/t5516-fetch-push.sh | 2 +- transport.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
t/t5516-fetch-push.sh +1 -1
@@ -1039,7 +1039,7 @@ test_force_fetch_tag "annotated tag" "-f -a -m'tag message'" test_expect_success 'push --porcelain' ' mk_empty testrepo && echo >.git/foo "To testrepo" && - echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" && + echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new reference]" && echo >>.git/foo "Done" && git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && (
transport.c +6 -3
@@ -499,9 +499,12 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt porcelain, summary_width); else if (is_null_oid(&ref->old_oid))print_ref_status ('*' , - (starts_with (ref->name,"refs/tags/" ) ?"[new tag]" : -"[new branch]" ), - ref, ref->peer_ref,NULL , porcelain, summary_width); + (starts_with (ref->name,"refs/tags/" ) + ?"[new tag]" + : (starts_with (ref->name,"refs/heads/" ) + ?"[new branch]" + :"[new reference]" )), + ref, ref->peer_ref,NULL , porcelain, summary_width); else {struct strbuf quickref =STRBUF_INIT ;char type;
Signature · 1 line
2.28.0
PATCH v17 2/10 t5411: add basic test cases for proc-receive hook
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Topic "proc-receive-hook" will change the workflow and output of git-push. Add some basic test cases in t5411 before introducing the new topic.
--- t/t5411-proc-receive-hook.sh | 108 +++++++++++++ t/t5411/common-functions.sh | 56 +++++++ t/t5411/test-0000-standard-git-push.sh | 143 +++++++++++++++++ .../test-0001-standard-git-push--porcelain.sh | 147 ++++++++++++++++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++++ 6 files changed, 521 insertions(+) create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh
t/t5411-proc-receive-hook.sh new file +108 -0
@@ -0,0 +1,108 @@ +#!/bin/sh +# +# Copyright (c) 2020 Jiang Xin +# + +test_description='Test proc-receive hook' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/t5411/common-functions.sh + +setup_upstream_and_workbench () { + # Refs of upstream : master(A) + # Refs of workbench: master(A) tags/v123 + test_expect_success "setup upstream and workbench" ' + rm -rf upstream.git && + rm -rf workbench && + git init --bare upstream.git && + git init workbench && + create_commits_in workbench A B && + ( + cd workbench && + # Try to make a stable fixed width for abbreviated commit ID, + # this fixed-width oid will be replaced with "<OID>". + git config core.abbrev 7 && + git tag -m "v123" v123 $A && + git remote add origin ../upstream.git && + git push origin master && + git update-ref refs/heads/master $A $B && + git -C ../upstream.git update-ref \ + refs/heads/master $A $B + ) && + TAG=$(git -C workbench rev-parse v123) && + + # setup pre-receive hook + write_script upstream.git/hooks/pre-receive <<-\EOF && + exec >&2 + echo "# pre-receive hook" + while read old new ref + do + echo "pre-receive< $old $new $ref" + done + EOF + + # setup post-receive hook + write_script upstream.git/hooks/post-receive <<-\EOF && + exec >&2 + echo "# post-receive hook" + while read old new ref + do + echo "post-receive< $old $new $ref" + done + EOF + + upstream=upstream.git + ' +} + +run_proc_receive_hook_test() { + case $1 in + http) + PROTOCOL="HTTP protocol" + URL_PREFIX="http://.*" + ;; + local) + PROTOCOL="builtin protocol" + URL_PREFIX="\.\." + ;; + esac + + # Include test cases for both file and HTTP protocol + for t in "$TEST_DIRECTORY"/t5411/test-*.sh + do + . "$t" + done +} + +# Initialize the upstream repository and local workbench. +setup_upstream_and_workbench + +# Run test cases for 'proc-receive' hook on local file protocol. +run_proc_receive_hook_test local + +ROOT_PATH="$PWD" +. "$TEST_DIRECTORY"/lib-gpg.sh +. "$TEST_DIRECTORY"/lib-httpd.sh +. "$TEST_DIRECTORY"/lib-terminal.sh +start_httpd + +# Re-initialize the upstream repository and local workbench. +setup_upstream_and_workbench + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +test_expect_success "setup for HTTP protocol" ' + git -C upstream.git config http.receivepack true && + upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" && + mv upstream.git "$upstream" && + git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" && + set_askpass user@host pass@host +' + +setup_askpass_helper + +# Run test cases for 'proc-receive' hook on HTTP protocol. +run_proc_receive_hook_test http + +test_done
t/t5411/common-functions.sh new file +56 -0
56 lines not on this page · raw message
t/t5411/test-0000-standard-git-push.sh new file +143 -0
143 lines not on this page · raw message
t/t5411/test-0001-standard-git-push--porcelain.sh new file +147 -0
147 lines not on this page · raw message
t/t5411/test-0002-pre-receive-declined.sh new file +33 -0
@@ -0,0 +1,33 @@ +test_expect_success "setup pre-receive hook ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && + write_script "$upstream/hooks/pre-receive" <<-EOF + exit 1 + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git-push : master(B) next(A) +test_expect_success "git-push is declined ($PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + $B:refs/heads/master \ + HEAD:refs/heads/next \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] <COMMIT-B> -> master (pre-receive hook declined) + ! [remote rejected] HEAD -> next (pre-receive hook declined) + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +' + +test_expect_success "cleanup ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive" +'
t/t5411/test-0003-pre-receive-declined--porcelain.sh new file +34 -0
@@ -0,0 +1,34 @@ +test_expect_success "setup pre-receive hook ($PROTOCOL/porcelain)" ' + mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && + write_script "$upstream/hooks/pre-receive" <<-EOF + exit 1 + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git-push : master(B) next(A) +test_expect_success "git-push is declined ($PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + $B:refs/heads/master \ + HEAD:refs/heads/next \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! <COMMIT-B>:refs/heads/master [remote rejected] (pre-receive hook declined) + ! HEAD:refs/heads/next [remote rejected] (pre-receive hook declined) + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +' + +test_expect_success "cleanup ($PROTOCOL/porcelain)" ' + mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive" +'
Signature · 1 line
2.28.0
PATCH v17 3/10 receive-pack: add new proc-receive hook
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Git calls an internal execute_commands function to handle commands sent from client to git-receive-pack. Regardless of what references the user pushes, git creates or updates the corresponding references if the user has write-permission. A contributor who has no write-permission, cannot push to the repository directly. So, the contributor has to write commits to an alternate location, and sends pull request by emails or by other ways. We call this workflow as a distributed workflow.
It would be more convenient to work in a centralized workflow like what Gerrit provided for some cases. For example, a read-only user who cannot push to a branch directly can run the following git push command to push commits to a pseudo reference (has a prefix "refs/for/", not "refs/heads/") to create a code review.
git push origin \
HEAD:refs/for/<branch-name>/<session>The <branch-name> in the above example can be as simple as "master", or a more complicated branch name like "foo/bar". The <session> in the above example command can be the local branch name of the client side, such as "my/topic".
We cannot implement a centralized workflow elegantly by using "pre-receive" + "post-receive", because Git will call the internal function "execute_commands" to create references (even the special pseudo reference) between these two hooks. Even though we can delete the temporarily created pseudo reference via the "post-receive" hook, having a temporary reference is not safe for concurrent pushes.
So, add a filter and a new handler to support this kind of workflow. The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (run_proc_receive) on for the command. Commands with this filed turned on will be executed by a new handler (an hook named "proc-receive") instead of the internal execute_commands function. We can use this "proc-receive" command to create pull requests or send emails for code review.
Suggested by Junio, this "proc-receive" hook reads the commands, push-options (optional), and send result using a protocol in pkt-line format. In the following example, The letter "S" stands for "receive-pack" and letter "H" stands for the hook.
# Version and features negotiation.
S: PKT-LINE(version=1\0push-options atomic...)
S: flush-pkt
H: PKT-LINE(version=1\0push-options...)
H: flush-pkt
# Send commands from server to the hook.
S: PKT-LINE(<old-oid> <new-oid> <ref>)
S: ... ...
S: flush-pkt
# Send push-options only if the 'push-options' feature is enabled.
S: PKT-LINE(push-option)
S: ... ...
S: flush-pkt
# Receive result from the hook.
# OK, run this command successfully.
H: PKT-LINE(ok <ref>)
# NO, I reject it.
H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
H: PKT-LINE(ok <ref>)
H: PKT-LINE(option fall-through)
# OK, but has an alternate reference. The alternate reference name # and other status can be given in options
H: PKT-LINE(ok <ref>)
H: PKT-LINE(option refname <refname>)
H: PKT-LINE(option old-oid <old-oid>)
H: PKT-LINE(option new-oid <new-oid>)
H: PKT-LINE(option forced-update)
H: ... ...
H: flush-pkt
After receiving a command, the hook will execute the command, and may create/update different reference. For example, a command for a pseudo reference "refs/for/master/topic" may create/update different reference such as "refs/pull/123/head". The alternate reference name and other status are given in option lines.
The list of commands returned from "proc-receive" will replace the relevant commands that are sent from user to "receive-pack", and "receive-pack" will continue to run the "execute_commands" function and other routines. Finally, the result of the execution of these commands will be reported to end user.
The reporting function from "receive-pack" to "send-pack" will be extended in latter commit just like what the "proc-receive" hook reports to "receive-pack".
--- Makefile | 1 + builtin/receive-pack.c | 351 ++++++++++++++++-- remote.h | 14 + t/helper/test-proc-receive.c | 176 +++++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411/test-0011-no-hook-error.sh | 64 ++++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 ++++ t/t5411/test-0013-bad-protocol.sh | 217 +++++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++++ t/t5411/test-0020-report-ng.sh | 67 ++++ t/t5411/test-0021-report-ng--porcelain.sh | 69 ++++ t/t5411/test-0022-report-unexpect-ref.sh | 45 +++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 +++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 ++++ t/t5411/test-0027-push-options--porcelain.sh | 82 ++++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-with-options.sh | 256 +++++++++++++ ...est-0033-report-with-options--porcelain.sh | 265 +++++++++++++ t/t5411/test-0034-report-ft.sh | 44 +++ t/t5411/test-0035-report-ft--porcelain.sh | 45 +++ ...t-0036-report-multi-rewrite-for-one-ref.sh | 159 ++++++++ ...rt-multi-rewrite-for-one-ref--porcelain.sh | 162 ++++++++ t/t5411/test-0038-report-mixed-refs.sh | 89 +++++ .../test-0039-report-mixed-refs--porcelain.sh | 91 +++++ 28 files changed, 2659 insertions(+), 31 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-with-options.sh create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh
Makefile +1 -0
@@ -719,6 +719,7 @@ TEST_BUILTINS_OBJS += test-parse-pathspec-file.o TEST_BUILTINS_OBJS += test-path-utils.o TEST_BUILTINS_OBJS += test-pkt-line.o TEST_BUILTINS_OBJS += test-prio-queue.o +TEST_BUILTINS_OBJS += test-proc-receive.o TEST_BUILTINS_OBJS += test-progress.o TEST_BUILTINS_OBJS += test-reach.o TEST_BUILTINS_OBJS += test-read-cache.o
builtin/receive-pack.c +320 -31
506 lines not on this page · raw message
remote.h +14 -0
@@ -93,6 +93,20 @@ int for_each_remote(each_remote_fn fn, void *priv);int remote_has_url (struct remote *remote,const char *url); +struct ref_push_report_options { +const char *ref_name; +struct object_id *old_oid; +struct object_id *new_oid; +unsigned int forced_update:1 ; +struct ref_push_report_options *next; +}; + +struct ref_push_report { +const char *message; +const char *error_message; +struct ref_push_report_options *options; +}; +struct ref {struct ref *next;struct object_id old_oid;
t/helper/test-proc-receive.c new file +176 -0
176 lines not on this page · raw message
t/helper/test-tool.c +1 -0
@@ -46,6 +46,7 @@ static struct test_cmd cmds[] = { { "path-utils", cmd__path_utils }, { "pkt-line", cmd__pkt_line }, { "prio-queue", cmd__prio_queue }, + { "proc-receive", cmd__proc_receive}, { "progress", cmd__progress }, { "reach", cmd__reach }, { "read-cache", cmd__read_cache },
t/helper/test-tool.h +1 -0
@@ -35,6 +35,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);int cmd__path_utils (int argc,const char **argv);int cmd__pkt_line (int argc,const char **argv);int cmd__prio_queue (int argc,const char **argv); +int cmd__proc_receive (int argc,const char **argv);int cmd__progress (int argc,const char **argv);int cmd__reach (int argc,const char **argv);int cmd__read_cache (int argc,const char **argv);
t/t5411/test-0011-no-hook-error.sh new file +64 -0
64 lines not on this page · raw message
t/t5411/test-0012-no-hook-error--porcelain.sh new file +66 -0
66 lines not on this page · raw message
t/t5411/test-0013-bad-protocol.sh new file +217 -0
217 lines not on this page · raw message
t/t5411/test-0014-bad-protocol--porcelain.sh new file +160 -0
160 lines not on this page · raw message
t/t5411/test-0020-report-ng.sh new file +67 -0
67 lines not on this page · raw message
t/t5411/test-0021-report-ng--porcelain.sh new file +69 -0
69 lines not on this page · raw message
t/t5411/test-0022-report-unexpect-ref.sh new file +45 -0
45 lines not on this page · raw message
t/t5411/test-0023-report-unexpect-ref--porcelain.sh new file +46 -0
46 lines not on this page · raw message
t/t5411/test-0024-report-unknown-ref.sh new file +34 -0
@@ -0,0 +1,34 @@ +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/a/b/c/my/topic +test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/a/b/c/my/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: proc-receive> ok refs/for/master/topic + remote: error: proc-receive reported status on unknown ref: refs/for/master/topic + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status) + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0025-report-unknown-ref--porcelain.sh new file +35 -0
@@ -0,0 +1,35 @@ +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/a/b/c/my/topic +test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/a/b/c/my/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: proc-receive> ok refs/for/master/topic + remote: error: proc-receive reported status on unknown ref: refs/for/master/topic + To <URL/of/upstream.git> + ! HEAD:refs/for/a/b/c/my/topic [remote rejected] (proc-receive failed to report status) + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0026-push-options.sh new file +79 -0
79 lines not on this page · raw message
t/t5411/test-0027-push-options--porcelain.sh new file +82 -0
82 lines not on this page · raw message
t/t5411/test-0030-report-ok.sh new file +35 -0
@@ -0,0 +1,35 @@ +test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/master/topic +test_expect_success "proc-receive: ok ($PROTOCOL)" ' + git -C workbench push origin \ + HEAD:refs/for/master/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: proc-receive> ok refs/for/master/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + To <URL/of/upstream.git> + * [new reference] HEAD -> refs/for/master/topic + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0031-report-ok--porcelain.sh new file +36 -0
@@ -0,0 +1,36 @@ +test_expect_success "setup proc-receive hook (ok, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/master/topic +test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" ' + git -C workbench push --porcelain origin \ + HEAD:refs/for/master/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: proc-receive> ok refs/for/master/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + To <URL/of/upstream.git> + * HEAD:refs/for/master/topic [new reference] + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0032-report-with-options.sh new file +256 -0
256 lines not on this page · raw message
t/t5411/test-0033-report-with-options--porcelain.sh new file +265 -0
265 lines not on this page · raw message
t/t5411/test-0034-report-ft.sh new file +44 -0
44 lines not on this page · raw message
t/t5411/test-0035-report-ft--porcelain.sh new file +45 -0
45 lines not on this page · raw message
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh new file +159 -0
159 lines not on this page · raw message
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh new file +162 -0
162 lines not on this page · raw message
t/t5411/test-0038-report-mixed-refs.sh new file +89 -0
89 lines not on this page · raw message
t/t5411/test-0039-report-mixed-refs--porcelain.sh new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH v17 03/10] receive-pack: add new proc-receive hook
Quoted 2 lines · Jiang Xin
Suggested-by Junio C Hamano <[email protected]>
Did I???? I do not think I deserve any credit here.
builtin/receive-pack.c static int run_update_hook(struct command *cmd) · line 853
Quoted 11 lines
Signed-off-by Jiang Xin <[email protected]>builtin/receive-pack.c +8
-0+static struct command *find_command_by_refname (const struct command *list, +const char *refname) +{ +for (; list; list = list->next) +if (!strcmp (list->ref_name, refname)) +return (struct command *)list; +return NULL ; +}
Does the last cast really needed, perhaps the caller is adding "const" to its objects where it is not needed, or the variable caller uses to receive the returned value of too loose a type?
Quoted 14 lines
t/helper/test-proc-receive.c new file +8
-0@@ -0,0 +1,176 @@ +#include "cache.h" +#include "connect.h" +#include "parse-options.h" +#include "pkt-line.h" +#include "sigchain.h" +#include "test-tool.h" + +static const char *proc_receive_usage[] = {
t/helper/test-proc-receive.c line 18
Quoted 10 lines
t/helper/test-proc-receive.c new file +10
-0+"test-tool proc-receive [<options>...]" , + NULL +}; + +static int die_version =0 ; +static int die_readline =0 ; +static int no_push_options =0 ; +static int use_atomic =0 ; +static int use_push_options =0 ; +static int verbose =0 ;
Let BSS do its job by omitting " = 0;" and " = NULL;" at the end.
PATCH v17 4/10 New capability "report-status-v2" for git-push
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
The new introduced "proc-receive" hook may handle a command for a pseudo-reference with a zero-old as its old-oid, while the hook may create or update a reference with different name, different new-oid, and different old-oid (the reference may exist already with a non-zero old-oid). Current "report-status" protocol cannot report the status for such reference rewrite.
Add new capability "report-status-v2" and new report protocol which is not backward compatible for report of git-push.
If a user pushes to a pseudo-reference "refs/for/master/topic", and "receive-pack" creates two new references "refs/changes/23/123/1" and "refs/changes/24/124/1", for client without the knowledge of "report-status-v2", "receive-pack" will only send "ok/ng" directives in the report, such as:
ok ref/for/master/topic
But for client which has the knowledge of "report-status-v2", "receive-pack" will use "option" directives to report more attributes for the reference given by the above "ok/ng" directive.
ok refs/for/master/topic
option refname refs/changes/23/123/1
option new-oid <new-oid>
ok refs/for/master/topic
option refname refs/changes/24/124/1
option new-oid <new-oid>
The client will report two new created references to the end user.
--- builtin/receive-pack.c | 52 +++++++- builtin/send-pack.c | 21 +++- remote.c | 4 +- remote.h | 2 +- send-pack.c | 99 ++++++++++++--- t/t5411-proc-receive-hook.sh | 9 ++ t/t5411/once-0010-report-status-v1.sh | 89 +++++++++++++ t/t5411/test-0032-report-with-options.sh | 14 +-- ...est-0033-report-with-options--porcelain.sh | 14 +-- ...t-0036-report-multi-rewrite-for-one-ref.sh | 11 +- ...rt-multi-rewrite-for-one-ref--porcelain.sh | 11 +- t/t5411/test-0038-report-mixed-refs.sh | 2 +- .../test-0039-report-mixed-refs--porcelain.sh | 2 +- transport-helper.c | 53 +++++++- transport.c | 118 +++++++++++++----- 15 files changed, 424 insertions(+), 77 deletions(-) create mode 100644 t/t5411/once-0010-report-status-v1.sh
builtin/receive-pack.c +50 -2
@@ -57,6 +57,7 @@ static int advertise_push_options;static int unpack_limit =100 ;static off_t max_input_size;static int report_status; +static int report_status_v2;static int use_sideband;static int use_atomic;static int use_push_options;
@@ -240,7 +241,7 @@ static void show_ref(const char *path, const struct object_id *oid)struct strbuf cap =STRBUF_INIT ;strbuf_addstr (&cap, -"report-status delete-refs side-band-64k quiet" ); +"report-status report-status-v2 delete-refs side-band-64k quiet" );if (advertise_atomic_push)strbuf_addstr (&cap," atomic" );if (prefer_ofs_delta)
@@ -1918,6 +1919,8 @@ static struct command *read_head_info(struct packet_reader *reader,int len =0 ;if (parse_feature_request (feature_list,"report-status" )) report_status =1 ; +if (parse_feature_request (feature_list,"report-status-v2" )) + report_status_v2 =1 ;if (parse_feature_request (feature_list,"side-band-64k" )) use_sideband =LARGE_PACKET_MAX ;if (parse_feature_request (feature_list,"quiet" ))
@@ -2236,6 +2239,49 @@ static void report(struct command *commands, const char *unpack_status)strbuf_release (&buf); } +static void report_v2 (struct command *commands,const char *unpack_status) +{ +struct command *cmd; +struct strbuf buf =STRBUF_INIT ; +struct ref_push_report_options *options; + +packet_buf_write (&buf,"unpack %s\n" , + unpack_status ? unpack_status :"ok" ); +for (cmd = commands; cmd; cmd = cmd->next) { +int count =0 ; + +if (!cmd->report.error_message) +packet_buf_write (&buf,"ok %s\n" , + cmd->ref_name); +else +packet_buf_write (&buf,"ng %s %s\n" , + cmd->ref_name, + cmd->report.error_message); +for (options = cmd->report.options; options; options = options->next) { +if (count++ >0 ) +packet_buf_write (&buf,"ok %s\n" , cmd->ref_name); +if (options->ref_name) +packet_buf_write (&buf,"option refname %s\n" , + options->ref_name); +if (options->old_oid) +packet_buf_write (&buf,"option old-oid %s\n" , +oid_to_hex (options->old_oid)); +if (options->new_oid) +packet_buf_write (&buf,"option new-oid %s\n" , +oid_to_hex (options->new_oid)); +if (options->forced_update) +packet_buf_write (&buf,"option forced-update\n" ); + } + } +packet_buf_flush (&buf); + +if (use_sideband) +send_sideband (1 ,1 , buf.buf, buf.len, use_sideband); +else +write_or_die (1 , buf.buf, buf.len); +strbuf_release (&buf); +} +static int delete_only (struct command *commands) {struct command *cmd;
@@ -2344,7 +2390,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix) &push_options);if (pack_lockfile)unlink_or_warn (pack_lockfile); -if (report_status) +if (report_status_v2) +report_v2 (commands, unpack_status); +else if (report_status)report (commands, unpack_status);run_receive_hook (commands,"post-receive" ,1 , &push_options);
builtin/send-pack.c +19 -2
@@ -29,10 +29,12 @@ static struct send_pack_args args;static void print_helper_status (struct ref *ref) {struct strbuf buf =STRBUF_INIT ; +struct ref_push_report_options *options;for (; ref; ref = ref->next) {const char *msg =NULL ;const char *res; +int count =0 ;switch (ref->status) {case REF_STATUS_NONE :
@@ -86,14 +88,29 @@ static void print_helper_status(struct ref *ref)strbuf_reset (&buf);strbuf_addf (&buf,"%s %s" , res, ref->name); -if (ref->remote_status) - msg = ref->remote_status; +if (ref->report.error_message) + msg = ref->report.error_message;if (msg) {strbuf_addch (&buf,' ' );quote_two_c_style (&buf,"" , msg,0 ); }strbuf_addch (&buf,'\n' ); +for (options = ref->report.options; options; options = options->next) { +if (count++ >0 ) +strbuf_addf (&buf,"ok %s\n" , ref->name); +if (options->ref_name) +strbuf_addf (&buf,"option refname %s\n" , + options->ref_name); +if (options->old_oid) +strbuf_addf (&buf,"option old-oid %s\n" , +oid_to_hex (options->old_oid)); +if (options->new_oid) +strbuf_addf (&buf,"option new-oid %s\n" , +oid_to_hex (options->new_oid)); +if (options->forced_update) +strbuf_addstr (&buf,"option forced-update\n" ); + }write_or_die (1 , buf.buf, buf.len); }strbuf_release (&buf);
remote.c +2 -2
@@ -789,7 +789,7 @@ struct ref *copy_ref(const struct ref *ref)memcpy (cpy, ref, len); cpy->next =NULL ; cpy->symref =xstrdup_or_null (ref->symref); - cpy->remote_status =xstrdup_or_null (ref->remote_status); + cpy->report.error_message =xstrdup_or_null (ref->report.error_message); cpy->peer_ref =copy_ref (ref->peer_ref);return cpy; }
@@ -811,7 +811,7 @@ void free_one_ref(struct ref *ref)if (!ref)return ;free_one_ref (ref->peer_ref); -free (ref->remote_status); +free ((void *)ref->report.error_message);free (ref->symref);free (ref); }
remote.h +1 -1
@@ -153,7 +153,7 @@ struct ref {REF_STATUS_EXPECTING_REPORT , REF_STATUS_ATOMIC_PUSH_FAILED } status; -char *remote_status; +struct ref_push_report report;struct ref *peer_ref;/* when renaming */ char name[FLEX_ARRAY ];/* more */ };
send-pack.c +81 -18
140 lines not on this page · raw message
t/t5411-proc-receive-hook.sh +9 -0
@@ -78,6 +78,15 @@ run_proc_receive_hook_test() { # Initialize the upstream repository and local workbench. setup_upstream_and_workbench +# Load test cases that only need to be executed once. +for t in "$TEST_DIRECTORY"/t5411/once-*.sh +do + . "$t" +done + +# Initialize the upstream repository and local workbench. +setup_upstream_and_workbench + # Run test cases for 'proc-receive' hook on local file protocol. run_proc_receive_hook_test local
t/t5411/once-0010-report-status-v1.sh new file +89 -0
89 lines not on this page · raw message
t/t5411/test-0032-report-with-options.sh +7 -7
@@ -56,7 +56,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" ' remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/pull/123/head EOF test_cmp expect actual '
@@ -89,7 +89,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/pull/123/head EOF test_cmp expect actual '
@@ -123,7 +123,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL) remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + <OID-B>..<OID-A> HEAD -> refs/pull/123/head EOF test_cmp expect actual '
@@ -155,7 +155,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" ' remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + <OID-B>..<OID-A> HEAD -> refs/for/master/topic EOF test_cmp expect actual '
@@ -189,7 +189,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL) remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + <OID-A>..<OID-B> HEAD -> refs/for/master/topic EOF test_cmp expect actual '
@@ -241,9 +241,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" ' remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/next/topic + * [new reference] HEAD -> refs/pull/123/head * [new reference] HEAD -> refs/for/a/b/c/topic - * [new reference] HEAD -> refs/for/master/topic + + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update) EOF test_cmp expect actual &&
t/t5411/test-0033-report-with-options--porcelain.sh +7 -7
@@ -57,7 +57,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)" remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + * HEAD:refs/pull/123/head [new reference] Done EOF test_cmp expect actual
@@ -92,7 +92,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + * HEAD:refs/pull/123/head [new reference] Done EOF test_cmp expect actual
@@ -127,7 +127,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/ remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/pull/123/head <OID-B>..<OID-A> Done EOF test_cmp expect actual
@@ -160,7 +160,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)" remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/for/master/topic <OID-B>..<OID-A> Done EOF test_cmp expect actual
@@ -195,7 +195,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/ remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/for/master/topic <OID-A>..<OID-B> Done EOF test_cmp expect actual
@@ -249,9 +249,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/next/topic [new reference] + * HEAD:refs/pull/123/head [new reference] * HEAD:refs/for/a/b/c/topic [new reference] - * HEAD:refs/for/master/topic [new reference] + + HEAD:refs/pull/124/head <OID-B>...<OID-A> (forced update) Done EOF test_cmp expect actual &&
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +8 -3
@@ -43,7 +43,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + <OID-A>..<OID-B> HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/changes/24/124/1 + <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1 EOF test_cmp expect actual && git -C "$upstream" show-ref >out &&
@@ -101,7 +103,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/changes/24/124/1 + <OID-A>..<OID-B> HEAD -> refs/for/master/topic + + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update) EOF test_cmp expect actual && git -C "$upstream" show-ref >out &&
@@ -147,7 +151,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" ' remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * [new reference] HEAD -> refs/for/master/topic + * [new reference] HEAD -> refs/changes/23/123/1 + <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2 EOF test_cmp expect actual && git -C "$upstream" show-ref >out &&
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +8 -3
@@ -43,7 +43,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/for/master/topic <OID-A>..<OID-B> + * HEAD:refs/changes/24/124/1 [new reference] + HEAD:refs/changes/25/125/1 <OID-A>..<OID-B> Done EOF test_cmp expect actual &&
@@ -102,7 +104,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + * HEAD:refs/changes/24/124/1 [new reference] + HEAD:refs/for/master/topic <OID-A>..<OID-B> + + HEAD:refs/changes/25/125/1 <OID-B>...<OID-A> (forced update) Done EOF test_cmp expect actual &&
@@ -149,7 +153,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc remote: # post-receive hook remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> - * HEAD:refs/for/master/topic [new reference] + * HEAD:refs/changes/23/123/1 [new reference] + HEAD:refs/changes/24/124/2 <OID-A>..<OID-B> Done EOF test_cmp expect actual &&
t/t5411/test-0038-report-mixed-refs.sh +1 -1
@@ -60,7 +60,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" ' * [new branch] HEAD -> baz * [new reference] HEAD -> refs/for/next/topic2 * [new branch] HEAD -> foo - * [new reference] HEAD -> refs/for/master/topic + <OID-A>..<OID-B> HEAD -> refs/for/master/topic ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API) ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status) EOF
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
@@ -60,7 +60,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel * HEAD:refs/heads/baz [new branch] * HEAD:refs/for/next/topic2 [new reference] * HEAD:refs/heads/foo [new branch] - * HEAD:refs/for/master/topic [new reference] + HEAD:refs/for/master/topic <OID-A>..<OID-B> ! HEAD:refs/for/next/topic1 [remote rejected] (fail to call Web API) ! HEAD:refs/for/next/topic3 [remote rejected] (proc-receive failed to report status) Done
transport-helper.c +52 -1
73 lines not on this page · raw message
transport.c +89 -29
220 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH v17 04/10] New capability "report-status-v2" for git-push
Quoted 11 lines · Jiang Xin
builtin/receive-pack.c +11
-0+static void report_v2 (struct command *commands,const char *unpack_status) +{ +struct command *cmd; +struct strbuf buf =STRBUF_INIT ; +struct ref_push_report_options *options; + +packet_buf_write (&buf,"unpack %s\n" , + unpack_status ? unpack_status :"ok" ); +for (cmd = commands; cmd; cmd = cmd->next) { +int count =0 ; +
builtin/receive-pack.c static void report(struct command *commands, const char *unpack_status) · line 2262
Quoted 10 lines
builtin/receive-pack.c +10
-0+if (!cmd->report.error_message) +packet_buf_write (&buf,"ok %s\n" , + cmd->ref_name); +else +packet_buf_write (&buf,"ng %s %s\n" , + cmd->ref_name, + cmd->report.error_message); +for (options = cmd->report.options; options; options = options->next) { +if (count++ >0 ) +packet_buf_write (&buf,"ok %s\n" , cmd->ref_name);
If there was an error, the first one gets "ng" but all others say it was "ok"? That smells somewhat strange.
Quoted 14 lines
builtin/receive-pack.c +13
-0+if (options->ref_name) +packet_buf_write (&buf,"option refname %s\n" , + options->ref_name); +if (options->old_oid) +packet_buf_write (&buf,"option old-oid %s\n" , +oid_to_hex (options->old_oid)); +if (options->new_oid) +packet_buf_write (&buf,"option new-oid %s\n" , +oid_to_hex (options->new_oid)); +if (options->forced_update) +packet_buf_write (&buf,"option forced-update\n" ); + } +if (ref->report.error_message)
builtin/receive-pack.c static void report(struct command *commands, const char *unpack_status)
Quoted 10 lines
builtin/receive-pack.c +4
-0+ msg = ref->report.error_message;if (msg) {strbuf_addch (&buf,' ' );quote_two_c_style (&buf,"" , msg,0 ); }strbuf_addch (&buf,'\n' ); +for (options = ref->report.options; options; options = options->next) { +if (count++ >0 ) +strbuf_addf (&buf,"ok %s\n" , ref->name);
Would this one ever report a "ng" for an error?
Quoted 21 lines
builtin/send-pack.c +12
-0+if (options->ref_name) +strbuf_addf (&buf,"option refname %s\n" , + options->ref_name); +if (options->old_oid) +strbuf_addf (&buf,"option old-oid %s\n" , +oid_to_hex (options->old_oid)); +if (options->new_oid) +strbuf_addf (&buf,"option new-oid %s\n" , +oid_to_hex (options->new_oid)); +if (options->forced_update) +strbuf_addstr (&buf,"option forced-update\n" ); + }write_or_die (1 , buf.buf, buf.len); }strbuf_release (&buf);transport-helper.c +0
-0
transport-helper.c static int push_update_ref_status(struct strbuf *buf, · line 733
Quoted 5 lines
transport-helper.c +2
-0@@ -729,6 +729,49 @@ static int push_update_ref_status(struct strbuf *buf, {char *refname, *msg;int status, forced =0 ; +static struct ref *hint =NULL ; +static int new_options =1 ;
I hate to see more helper functions turned into pieces that are impossible to reuse by gaining internal state like this. Does this function have so many callers that makes it impractical to update its signature to have the pointer to a "state" structure passed by the caller? This is called only from push_update_refs_status(), so you should be able to define a new structure that has the two fields
struct {
struct ref *hint;
int new_option;
};initialize an instance of it before push_update_refs_status() enters its endless loop, and pass a pointer to it to this helper function.
Quoted 18 lines
transport-helper.c +18
-0+if (starts_with (buf->buf,"option " )) { +struct ref_push_report_options *options; +struct object_id old_oid, new_oid; +const char *key, *val; +char *p; + +if (!hint) +die (_ ("'option' without a matching 'ok/error' directive" )); + options = hint->report.options; +while (options && options->next) + options = options->next; +if (new_options) { +if (!options) { + hint->report.options =xcalloc (1 ,sizeof (struct ref_push_report_options )); + options = hint->report.options; + }else { + options->next =xcalloc (1 ,sizeof (struct ref_push_report_options )); + options = options->next;
transport-helper.c static int push_update_ref_status(struct strbuf *buf,
Quoted 10 lines
transport-helper.c +6
-2+ } + new_options =0 ; + } -static int print_one_push_status (struct ref *ref,const char *dest,int count, -int porcelain,int summary_width) +static int _print_one_push_status (struct ref *ref,const char *dest,int count, +struct ref_push_report_options *options, +int porcelain,int summary_width)
Our naming convention avoids leading underscore (instead we use _1 suffix, when we cannot come up with a better name).
transport-helper.c
Quoted 11 lines
transport-helper.c +11
-0+static int print_one_push_status (struct ref *ref,const char *dest,int count, +int porcelain,int summary_width) +{ +struct ref_push_report_options *options; +int n =0 ; + +if (!ref->report.options) +return _print_one_push_status (ref, dest, count, +NULL , porcelain, summary_width); + +for (options = ref->report.options; options; options = options->next)
This comment applies to all the patches in this series that adds the same pattern, but
* "ref->report.options" may be a good name in that it is a (linked) list of options;
* The variable that is used to iterate over the list points at one of the elements on the list at any time, and is better called 'option' without 's' at the end.
Quoted 8 lines
transport-helper.c +5
-0+_print_one_push_status (ref, dest, count + n++, + options, porcelain, summary_width); +return n; +} +static int measure_abbrev (const struct object_id *oid,int sofar) {char hex[GIT_MAX_HEXSZ +1 ];
PATCH v17 5/10 doc: add document for capability report-status-v2
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Add ABNF notation for capability 'report-status-v2' which extends capability 'report-status' by adding additional option lines.
--- Documentation/technical/pack-protocol.txt | 43 +++++++++++++++++-- .../technical/protocol-capabilities.txt | 17 ++++++-- 2 files changed, 54 insertions(+), 6 deletions(-)
Documentation/technical/pack-protocol.txt +40 -3
@@ -503,8 +503,8 @@ The reference discovery phase is done nearly the same way as it is in the fetching protocol. Each reference obj-id and name on the server is sent in packet-line format to the client, followed by a flush-pkt. The only real difference is that the capability listing is different - the only -possible values are 'report-status', 'delete-refs', 'ofs-delta' and -'push-options'. +possible values are 'report-status', 'report-status-v2', 'delete-refs', +'ofs-delta', 'atomic' and 'push-options'. Reference Update Request and Packfile Transfer ----------------------------------------------
@@ -625,7 +625,7 @@ Report Status ------------- After receiving the pack data from the sender, the receiver sends a -report if 'report-status' capability is in effect. +report if 'report-status' or 'report-status-v2' capability is in effect. It is a short listing of what happened in that update. It will first list the status of the packfile unpacking as either 'unpack ok' or 'unpack [error]'. Then it will list the status for each of the references
@@ -647,6 +647,43 @@ update was successful, or 'ng [refname] [error]' if the update was not. error-msg = 1*(OCTET) ; where not "ok" ---- +New capability "report-status-v2" extends the protocol by adding new option +lines in order to support reporting of reference rewritten by the +"proc-receive" hook. The "proc-receive" hook may handle a command for a +pseudo-reference which may create or update one or more references, and each +reference may have different name, different new-oid, and different old-oid. + +---- + report-status-v2 = unpack-status + 1*(command-status-v2) + flush-pkt + + unpack-status = PKT-LINE("unpack" SP unpack-result) + unpack-result = "ok" / error-msg + + command-status-v2 = command-ok-v2 / command-fail-v2 + command-ok-v2 = command-ok + *option-line + command-fail-v2 = command-fail + *option-line + + command-ok = PKT-LINE("ok" SP refname) + command-fail = PKT-LINE("ng" SP refname SP error-msg) + + error-msg = 1*(OCTET) ; where not "ok" + + option-line = *1(option-refname) + *1(option-old-oid) + *1(option-new-oid) + *1(option-forced-update) + + option-refname = PKT-LINE("option" SP "refname" SP refname) + option-old-oid = PKT-LINE("option" SP "old-oid" SP obj-id) + option-new-oid = PKT-LINE("option" SP "new-oid" SP obj-id) + option-force = PKT-LINE("option" SP "forced-update") + +---- + Updates can be unsuccessful for a number of reasons. The reference can have changed since the reference discovery phase was originally sent, meaning someone pushed in the meantime. The reference being pushed could be a
Documentation/technical/protocol-capabilities.txt +14 -3
@@ -22,9 +22,9 @@ was sent. Server MUST NOT ignore capabilities that client requested and server advertised. As a consequence of these rules, server MUST NOT advertise capabilities it does not understand. -The 'atomic', 'report-status', 'delete-refs', 'quiet', and 'push-cert' -capabilities are sent and recognized by the receive-pack (push to server) -process. +The 'atomic', 'report-status', 'report-status-v2', 'delete-refs', 'quiet', +and 'push-cert' capabilities are sent and recognized by the receive-pack +(push to server) process. The 'ofs-delta' and 'side-band-64k' capabilities are sent and recognized by both upload-pack and receive-pack protocols. The 'agent' capability
@@ -284,6 +284,17 @@ each reference was updated successfully. If any of those were not successful, it will send back an error message. See pack-protocol.txt for example messages. +report-status-v2 +---------------- + +Capability 'report-status-v2' extends capability 'report-status' by +adding new option lines in order to support reference rewritten by +the"proc-receive" hook. The "proc-receive" hook may handle a command +for a pseudo-reference which may create or update a reference with +different name, new-oid, and old-oid. While the capability +"report-status" cannot report for such case. See pack-protocol.txt +for details. + delete-refs -----------
Signature · 1 line
2.28.0
PATCH v17 6/10 receive-pack: feed report options to post-receive
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
When commands are fed to the "post-receive" hook, report options will be parsed and the real old-oid, new-oid, reference name will feed to the "post-receive" hook.
--- builtin/receive-pack.c | 29 ++++++++++++++++--- t/t5411/once-0010-report-status-v1.sh | 3 +- t/t5411/test-0032-report-with-options.sh | 14 ++++----- ...est-0033-report-with-options--porcelain.sh | 14 ++++----- ...t-0036-report-multi-rewrite-for-one-ref.sh | 11 +++++-- ...rt-multi-rewrite-for-one-ref--porcelain.sh | 11 +++++-- t/t5411/test-0038-report-mixed-refs.sh | 2 +- .../test-0039-report-mixed-refs--porcelain.sh | 2 +- 8 files changed, 59 insertions(+), 27 deletions(-)
builtin/receive-pack.c +25 -4
@@ -777,17 +777,38 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) {struct receive_hook_feed_state *state = state_;struct command *cmd = state->cmd; +static struct ref_push_report_options *options =NULL ;while (cmd && state->skip_broken && (cmd->report.error_message || cmd->did_not_exist)) cmd = cmd->next;if (!cmd)return -1 ;/* EOF */ +if (!bufp) +return 0 ;/* OK, can feed something. */ strbuf_reset (&state->buf); -strbuf_addf (&state->buf,"%s %s %s\n" , -oid_to_hex (&cmd->old_oid),oid_to_hex (&cmd->new_oid), - cmd->ref_name); - state->cmd = cmd->next; +if (!options) + options = cmd->report.options; +if (options) { +struct object_id *old_oid; +struct object_id *new_oid; +const char *ref_name; + + old_oid = options->old_oid ? options->old_oid : &cmd->old_oid; + new_oid = options->new_oid ? options->new_oid : &cmd->new_oid; + ref_name = options->ref_name ? options->ref_name : cmd->ref_name; +strbuf_addf (&state->buf,"%s %s %s\n" , +oid_to_hex (old_oid),oid_to_hex (new_oid), + ref_name); + options = options->next; +if (!options) + state->cmd = cmd->next; + }else { +strbuf_addf (&state->buf,"%s %s %s\n" , +oid_to_hex (&cmd->old_oid),oid_to_hex (&cmd->new_oid), + cmd->ref_name); + state->cmd = cmd->next; + }if (bufp) { *bufp = state->buf.buf; *sizep = state->buf.len;
t/t5411/once-0010-report-status-v1.sh +2 -1
@@ -74,7 +74,8 @@ test_expect_success "proc-receive: report status v1" ' post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic1 post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo - post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic2 + post-receive< <ZERO-OID> <COMMIT-A> refs/for/changes/23/123/1 + post-receive< <COMMIT-B> <COMMIT-A> refs/for/changes/24/124/2 EOF test_cmp expect actual &&
t/t5411/test-0032-report-with-options.sh +7 -7
@@ -54,7 +54,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" ' remote: proc-receive> ok refs/for/master/topic remote: proc-receive> option refname refs/pull/123/head remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> * [new reference] HEAD -> refs/pull/123/head EOF
@@ -87,7 +87,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option forced-update remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> * [new reference] HEAD -> refs/pull/123/head EOF
@@ -121,7 +121,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL) remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option old-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> <OID-B>..<OID-A> HEAD -> refs/pull/123/head EOF
@@ -153,7 +153,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" ' remote: proc-receive> ok refs/for/master/topic remote: proc-receive> option old-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> <OID-B>..<OID-A> HEAD -> refs/for/master/topic EOF
@@ -187,7 +187,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL) remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic To <URL/of/upstream.git> <OID-A>..<OID-B> HEAD -> refs/for/master/topic EOF
@@ -237,9 +237,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" ' remote: proc-receive> option forced-update remote: proc-receive> option new-oid <COMMIT-A> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head To <URL/of/upstream.git> * [new reference] HEAD -> refs/pull/123/head * [new reference] HEAD -> refs/for/a/b/c/topic
t/t5411/test-0033-report-with-options--porcelain.sh +7 -7
@@ -55,7 +55,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)" remote: proc-receive> ok refs/for/master/topic remote: proc-receive> option refname refs/pull/123/head remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> * HEAD:refs/pull/123/head [new reference] Done
@@ -90,7 +90,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option forced-update remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> * HEAD:refs/pull/123/head [new reference] Done
@@ -125,7 +125,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/ remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option old-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head To <URL/of/upstream.git> HEAD:refs/pull/123/head <OID-B>..<OID-A> Done
@@ -158,7 +158,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)" remote: proc-receive> ok refs/for/master/topic remote: proc-receive> option old-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic To <URL/of/upstream.git> HEAD:refs/for/master/topic <OID-B>..<OID-A> Done
@@ -193,7 +193,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/ remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic To <URL/of/upstream.git> HEAD:refs/for/master/topic <OID-A>..<OID-B> Done
@@ -245,9 +245,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc remote: proc-receive> option forced-update remote: proc-receive> option new-oid <COMMIT-A> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head To <URL/of/upstream.git> * HEAD:refs/pull/123/head [new reference] * HEAD:refs/for/a/b/c/topic [new reference]
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +8 -3
@@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1 To <URL/of/upstream.git> <OID-A>..<OID-B> HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/changes/24/124/1
@@ -101,7 +103,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for remote: proc-receive> option new-oid <COMMIT-A> remote: proc-receive> option forced-update remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1 To <URL/of/upstream.git> * [new reference] HEAD -> refs/changes/24/124/1 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
@@ -149,7 +153,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" ' remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2 To <URL/of/upstream.git> * [new reference] HEAD -> refs/changes/23/123/1 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +8 -3
@@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1 To <URL/of/upstream.git> HEAD:refs/for/master/topic <OID-A>..<OID-B> * HEAD:refs/changes/24/124/1 [new reference]
@@ -102,7 +104,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for remote: proc-receive> option new-oid <COMMIT-A> remote: proc-receive> option forced-update remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic + remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1 To <URL/of/upstream.git> * HEAD:refs/changes/24/124/1 [new reference] HEAD:refs/for/master/topic <OID-A>..<OID-B>
@@ -151,7 +155,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-B> remote: # post-receive hook - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2 To <URL/of/upstream.git> * HEAD:refs/changes/23/123/1 [new reference] HEAD:refs/changes/24/124/2 <OID-A>..<OID-B>
t/t5411/test-0038-report-mixed-refs.sh +1 -1
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" ' remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic To <URL/of/upstream.git> <OID-A>..<OID-B> <COMMIT-B> -> master * [new branch] HEAD -> bar
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo - remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic To <URL/of/upstream.git> <COMMIT-B>:refs/heads/master <OID-A>..<OID-B> * HEAD:refs/heads/bar [new branch]
Signature · 1 line
2.28.0
Re: [PATCH v17 06/10] receive-pack: feed report options to post-receive
builtin/receive-pack.c static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) · line 780
Quoted 9 lines · Jiang Xin
builtin/receive-pack.c +1
-0@@ -777,17 +777,38 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) {struct receive_hook_feed_state *state = state_;struct command *cmd = state->cmd; +static struct ref_push_report_options *options =NULL ;
Exactly the same comment as "don't turn helper functions that can be reused into unreusable ones by adding internal states" as one of the previous patches applies here.
PATCH v17 7/10 receive-pack: new config receive.procReceiveRefs
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Add a new multi-valued config variable "receive.procReceiveRefs" for receive-pack command, like the follows:
git config --system --add receive.procReceiveRefs refs/for
git config --system --add receive.procReceiveRefs refs/draftsIf the specific prefix strings given by the config variables match the reference names of the commands which are sent from git client to receive-pack, these commands will be executed by an external hook (named "proc-receive"), instead of the internal execute_commands function.
For example, if it is set to "refs/for", pushing to a reference such as "refs/for/master" will not create or update reference "refs/for/master", but may create or update a pull request directly by running the hook "proc-receive".
Optional modifiers can be provided in the beginning of value of the config variable to filter commands for specific actions: create (a), mofify (m), delete (d). E.g.:
git config --system --add receive.procReceiveRefs ad:refs/heads
--- Documentation/config/receive.txt | 19 +++ builtin/receive-pack.c | 110 ++++++++++++++- t/t5411/once-0010-report-status-v1.sh | 4 + t/t5411/test-0010-proc-receive-settings.sh | 7 + t/t5411/test-0040-process-all-refs.sh | 113 ++++++++++++++++ .../test-0041-process-all-refs--porcelain.sh | 114 ++++++++++++++++ t/t5411/test-0050-proc-receive-refs.sh | 128 ++++++++++++++++++ 7 files changed, 488 insertions(+), 7 deletions(-) create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh create mode 100644 t/t5411/test-0050-proc-receive-refs.sh
Documentation/config/receive.txt +19 -0
@@ -114,6 +114,25 @@ receive.hideRefs:: An attempt to update or delete a hidden ref by `git push` is rejected. +receive.procReceiveRefs:: + This is a multi-valued variable that defines reference prefixes + to match the commands in `receive-pack`. Commands matching the + prefixes will be executed by an external hook "proc-receive", + instead of the internal `execute_commands` function. If this + variable is not defined, the "proc-receive" hook will never be + used, and all commands will be executed by the internal + `execute_commands` function. ++ +For example, if this variable is set to "refs/for", pushing to reference +such as "refs/for/master" will not create or update a reference named +"refs/for/master", but may create or update a pull request directly by +running the hook "proc-receive". ++ +Optional modifiers can be provided in the beginning of the value to filter +commands for specific actions: create (a), mofify (m), delete (d). E.g.: ++ + git config --system --add receive.procReceiveRefs ad:refs/heads + receive.updateServerInfo:: If set to true, git-receive-pack will run git-update-server-info after receiving data from git-push and updating refs.
builtin/receive-pack.c +103 -7
135 lines not on this page · raw message
t/t5411/once-0010-report-status-v1.sh +4 -0
@@ -1,3 +1,7 @@ +test_expect_success "setup receive.procReceiveRefs" ' + git -C "$upstream" config --add receive.procReceiveRefs refs/for +' + test_expect_success "setup proc-receive hook" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n"
t/t5411/test-0010-proc-receive-settings.sh new file +7 -0
@@ -0,0 +1,7 @@ +test_expect_success "add two receive.procReceiveRefs settings" ' + ( + cd "$upstream" && + git config --add receive.procReceiveRefs refs/for && + git config --add receive.procReceiveRefs refs/review/ + ) +'
t/t5411/test-0040-process-all-refs.sh new file +113 -0
113 lines not on this page · raw message
t/t5411/test-0041-process-all-refs--porcelain.sh new file +114 -0
114 lines not on this page · raw message
t/t5411/test-0050-proc-receive-refs.sh new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH v17 07/10] receive-pack: new config receive.procReceiveRefs
Quoted 5 lines · Jiang Xin
builtin/receive-pack.c +0
-0
builtin/receive-pack.c static int keepalive_in_sec = 5; · line 107
Quoted 10 lines
builtin/receive-pack.c +7
-0@@ -98,6 +98,16 @@ static int keepalive_in_sec = 5;static struct tmp_objdir *tmp_objdir; +static struct proc_receive_ref { +unsigned int want_add:1 , + want_delete:1 , + want_modify:1 ; +char *ref_prefix; +struct proc_receive_ref *next; +} *proc_receive_ref =NULL ;
Let BSS do its job here.
builtin/receive-pack.c static int receive_pack_config(const char *var, const char *value, void *cb) · line 243
Quoted 10 lines
builtin/receive-pack.c +3
-0+static void proc_receive_ref_append (const char *prefix); +static enum deny_action parse_deny_action (const char *var,const char *value) {if (value) {@@ -230,6 +240,13 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (strcmp (var,"receive.procreceiverefs" ) ==0 ) {
We may want to fix the style of this function in a preliminary clean-up, but not in the middle of the series, so let's agree to let this pass.
builtin/receive-pack.c struct command { · line 352
Quoted 12 lines
builtin/receive-pack.c +8
-0@@ -325,6 +342,84 @@ struct command {char ref_name[FLEX_ARRAY ];/* more */ }; +static void proc_receive_ref_append (const char *prefix) +{ +struct proc_receive_ref *ref_pattern; +char *p; +int len; + + ref_pattern =xcalloc (1 ,sizeof (struct proc_receive_ref )); + p =strchr (prefix,':' );
A colon ':' is not a valid character in a refname, so the use of it as a separator for the prefix would be reasonable.
Quoted 13 lines
builtin/receive-pack.c +13
-0+if (p) { +while (prefix < p) { +if (*prefix =='a' ) + ref_pattern->want_add =1 ; +else if (*prefix =='d' ) + ref_pattern->want_delete =1 ; +else if (*prefix =='m' ) + ref_pattern->want_modify =1 ; + prefix++; + } + prefix++; + }else { + ref_pattern->want_add =1 ;
builtin/receive-pack.c struct command {
Quoted 10 lines
builtin/receive-pack.c +8
-0+ ref_pattern->want_delete =1 ; + ref_pattern->want_modify =1 ; + } + ref_pattern->next =NULL ; + ref_pattern->ref_prefix =xstrdup (prefix); + len =strlen (ref_pattern->ref_prefix); +while (len && ref_pattern->ref_prefix[len -1 ] =='/' ) + ref_pattern->ref_prefix[--len] ='\0' ;
Why not count "size_t len" before you make a copy of prefix with tail adjustment, so that you can do xmemdupz() at the end without need for potential overallocation?
builtin/receive-pack.c struct command { · line 374
Quoted 1 line
builtin/receive-pack.c +1
-0+if (proc_receive_ref ==NULL ) {
Style:
if (!proc_receive_ref) {like you did below.
Quoted 15 lines
builtin/receive-pack.c +15
-0+static int proc_receive_ref_matches (struct command *cmd) +{ +struct proc_receive_ref *p; + +if (!proc_receive_ref) +return 0 ; + +for (p = proc_receive_ref; p; p = p->next) { +const char *match = p->ref_prefix; +int neg =0 ; +const char *remains; + +if (!p->want_add &&is_null_oid (&cmd->old_oid)) +continue ; +else if (!p->want_delete &&is_null_oid (&cmd->new_oid))
builtin/receive-pack.c struct command { · line 410
Quoted 10 lines
builtin/receive-pack.c +10
-0+continue ; + else if (!p->want_modify && + !is_null_oid(&cmd->old_oid) && + !is_null_oid(&cmd->new_oid)) +continue ; + +if (*match =='!' ) { + neg =1 ; + match++; + }
Shouldn't the "negate" bit be jsut another field that has want_{add,delete,modify}, so that proc_receive_ref_append() can parse it only once without these four lines?
PATCH v17 8/10 t5411: test updates of remote-tracking branches
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
In order to test update of remote-tracking branches for special refs, add new "remote.origin.fetch" settings and test cases.
--- ...t-0036-report-multi-rewrite-for-one-ref.sh | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +48 -0
@@ -1,3 +1,18 @@ +test_expect_success "setup git config for remote-tracking of special refs" ' + ( + cd workbench && + if ! git config --get-all remote.origin.fetch | grep refs/for/ + then + git config --add remote.origin.fetch \ + "+refs/for/*:refs/t/for/*" && + git config --add remote.origin.fetch \ + "+refs/pull/*:refs/t/pull/*" && + git config --add remote.origin.fetch \ + "+refs/changes/*:refs/t/changes/*" + fi + ) +' + test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n"
@@ -58,6 +73,17 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for test_cmp expect actual ' +test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" ' + git -C workbench show-ref | + grep -v -e refs/remotes -e refs/heads -e refs/tags >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/t/for/master/topic + EOF + test_cmp expect actual && + git -C workbench update-ref -d refs/t/for/master/topic +' + test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n"
@@ -120,6 +146,17 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for test_cmp expect actual ' +test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" ' + git -C workbench show-ref | + grep -v -e refs/remotes -e refs/heads -e refs/tags >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/t/for/master/topic + EOF + test_cmp expect actual && + git -C workbench update-ref -d refs/t/for/master/topic +' + test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n"
@@ -167,3 +204,14 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" ' EOF test_cmp expect actual ' + +test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" ' + git -C workbench show-ref | + grep -v -e refs/remotes -e refs/heads -e refs/tags >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/t/for/master/topic + EOF + test_cmp expect actual && + git -C workbench update-ref -d refs/t/for/master/topic +'
Signature · 1 line
2.28.0
PATCH v17 9/10 transport: parse report options for tracking refs
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
When pushing a pseudo reference (such as "refs/for/master/topic"), may create or update one or more references. The real names of the references will be stored in the report options. Parse report options to create or update remote-tracking branches properly.
--- ...t-0036-report-multi-rewrite-for-one-ref.sh | 22 +++++++--- transport.c | 40 ++++++++++++++----- 2 files changed, 46 insertions(+), 16 deletions(-)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +16 -6
@@ -78,10 +78,14 @@ test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" ' grep -v -e refs/remotes -e refs/heads -e refs/tags >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && - <COMMIT-A> refs/t/for/master/topic + <COMMIT-A> refs/t/changes/24/124/1 + <COMMIT-B> refs/t/changes/25/125/1 + <COMMIT-B> refs/t/for/master/topic EOF test_cmp expect actual && - git -C workbench update-ref -d refs/t/for/master/topic + git -C workbench update-ref -d refs/t/for/master/topic && + git -C workbench update-ref -d refs/t/changes/24/124/1 && + git -C workbench update-ref -d refs/t/changes/25/125/1 ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
@@ -151,10 +155,14 @@ test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" ' grep -v -e refs/remotes -e refs/heads -e refs/tags >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && - <COMMIT-A> refs/t/for/master/topic + <COMMIT-A> refs/t/changes/24/124/1 + <COMMIT-A> refs/t/changes/25/125/1 + <COMMIT-B> refs/t/for/master/topic EOF test_cmp expect actual && - git -C workbench update-ref -d refs/t/for/master/topic + git -C workbench update-ref -d refs/t/for/master/topic && + git -C workbench update-ref -d refs/t/changes/24/124/1 && + git -C workbench update-ref -d refs/t/changes/25/125/1 ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
@@ -210,8 +218,10 @@ test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" ' grep -v -e refs/remotes -e refs/heads -e refs/tags >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && - <COMMIT-A> refs/t/for/master/topic + <COMMIT-A> refs/t/changes/23/123/1 + <COMMIT-B> refs/t/changes/24/124/2 EOF test_cmp expect actual && - git -C workbench update-ref -d refs/t/for/master/topic + git -C workbench update-ref -d refs/t/changes/24/124/1 && + git -C workbench update-ref -d refs/t/changes/25/125/2 '
transport.c +30 -10
@@ -436,28 +436,48 @@ int transport_refs_pushed(struct ref *ref)return 0 ; } -void transport_update_tracking_ref (struct remote *remote,struct ref *ref,int verbose) +static void update_tracking_ref (struct remote *remote,char *refname, +struct object_id *new_oid,int deletion, +int verbose) {struct refspec_item rs; -if (ref->status !=REF_STATUS_OK && ref->status !=REF_STATUS_UPTODATE ) -return ; - - rs.src = ref->name; + rs.src = refname; rs.dst =NULL ; -if (!remote_find_tracking (remote, &rs)) {if (verbose)fprintf (stderr,"updating local tracking ref '%s'\n" , rs.dst); -if (ref->deletion) { +if (deletion)delete_ref (NULL , rs.dst,NULL ,0 ); - }else -update_ref ("update by push" , rs.dst, &ref->new_oid, -NULL ,0 ,0 ); +else +update_ref ("update by push" , rs.dst, new_oid, +NULL ,0 ,0 );free (rs.dst); } } +void transport_update_tracking_ref (struct remote *remote,struct ref *ref,int verbose) +{ +char *refname; +struct object_id *new_oid; +struct ref_push_report_options *options; + +if (ref->status !=REF_STATUS_OK && ref->status !=REF_STATUS_UPTODATE ) +return ; + + options = ref->report.options; +if (!options) +update_tracking_ref (remote, ref->name, &ref->new_oid, + ref->deletion, verbose); +else +for (; options; options = options->next) { + refname = options->ref_name ? (char *)options->ref_name : ref->name; + new_oid = options->new_oid ? options->new_oid : &ref->new_oid; +update_tracking_ref (remote, refname, new_oid, +is_null_oid (new_oid), verbose); + } +} + static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg, struct ref_push_report_options *options,
Signature · 1 line
2.28.0
PATCH v17 10/10 doc: add documentation for the proc-receive hook
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
"git receive-pack" that accepts requests by "git push" learned to outsource some of the ref updates to the new "proc-receive" hook.
--- Documentation/githooks.txt | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
Documentation/githooks.txt +62 -0
@@ -333,6 +333,68 @@ The default 'update' hook, when enabled--and with `hooks.allowunannotated` config option unset or set to false--prevents unannotated tags to be pushed. +[[proc-receive]] +proc-receive +~~~~~~~~~~~~ + +This hook is invoked by linkgit:git-receive-pack[1]. If the server has +set the multi-valued config variable `receive.procReceiveRefs`, and the +commands sent to 'receive-pack' have matching reference names, these +commands will be executed by this hook, instead of by the internal +`execute_commands()` function. This hook is responsible for updating +the relevant references and reporting the results back to 'receive-pack'. + +This hook executes once for the receive operation. It takes no +arguments, but uses a pkt-line format protocol to communicate with +'receive-pack' to read commands, push-options and send results. In the +following example for the protocol, the letter 'S' stands for +'receive-pack' and the letter 'H' stands for this hook. + + # Version and features negotiation. + S: PKT-LINE(version=1\0push-options atomic...) + S: flush-pkt + H: PKT-LINE(version=1\0push-options...) + H: flush-pkt + + # Send commands from server to the hook. + S: PKT-LINE(<old-oid> <new-oid> <ref>) + S: ... ... + S: flush-pkt + # Send push-options only if the 'push-options' feature is enabled. + S: PKT-LINE(push-option) + S: ... ... + S: flush-pkt + + # Receive result from the hook. + # OK, run this command successfully. + H: PKT-LINE(ok <ref>) + # NO, I reject it. + H: PKT-LINE(ng <ref> <reason>) + # Fall through, let 'receive-pack' to execute it. + H: PKT-LINE(ok <ref>) + H: PKT-LINE(option fall-through) + # OK, but has an alternate reference. The alternate reference name + # and other status can be given in options + H: PKT-LINE(ok <ref>) + H: PKT-LINE(option refname <refname>) + H: PKT-LINE(option old-oid <old-oid>) + H: PKT-LINE(option new-oid <new-oid>) + H: PKT-LINE(option forced-update) + H: ... ... + H: flush-pkt + +Each command for the 'proc-receive' hook may point to a pseudo-reference +and always has a zero-old as its old-oid, while the 'proc-receive' hook +may update an alternate reference and the alternate reference may exist +already with a non-zero old-oid. For this case, this hook will use +"option" directives to report extended attributes for the reference given +by the above "ok/ng" directive. + +The report of the commands of this hook should have the same order as +the input. The exit status of the 'proc-receive' hook only determines +the success or failure of the group of commands sent to it, unless +atomic push is in use. + [[post-receive]] post-receive ~~~~~~~~~~~~
Signature · 1 line
2.28.0
v17 cover New proc-receive hook for centralized workflow
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
This topic introduces a new hook named "proc-receive" for "receive-pack". We can use this hook to implement a Gerrit-like centralized workflow.
## Changes since v16
1. Fixes test helper for proc-receive which is not compatible with sha256.
Run setup_git_directory_gently() in t/helper/test-proc-receive.c, so that the_repository variable is initialized with proper hash_algo.
See range-diff:
3: 6ac2e0f88c ! 3: 94d3053662 receive-pack: add new proc-receive hook
@@ builtin/receive-pack.c: static void run_update_post_hook(struct command *command
- if (cmd->error_string || cmd->did_not_exist)
+ if (cmd->report.error_message || cmd->did_not_exist)
continue;
- if (!proc.args.argc)
- argv_array_push(&proc.args, hook);
+ if (!proc.args.nr)
+ strvec_push(&proc.args, hook);
@@ builtin/receive-pack.c: static void check_aliased_update_internal(struct command *cmd,
if (!dst_name) {
rp_error("refusing update to broken symref '%s'", cmd->ref_name);
@@ t/helper/test-proc-receive.c (new)
+
+int cmd__proc_receive(int argc, const char **argv)
+{
++ int nongit_ok = 0;
+ struct packet_reader reader;
+ struct command *commands = NULL;
+ struct string_list push_options = STRING_LIST_INIT_DUP;
@@ t/helper/test-proc-receive.c (new)
+ OPT_END()
+ };
+
++ setup_git_directory_gently(&nongit_ok);
++
+ argc = parse_options(argc, argv, "test-tools", options, proc_receive_usage, 0);
+ if (argc > 0)
+ usage_msg_opt("Too many arguments.", proc_receive_usage, options);
-+
+ packet_reader_init(&reader, 0, NULL, 0,
+ PACKET_READ_CHOMP_NEWLINE |
+ PACKET_READ_DIE_ON_ERR_PACKET);2. Fixed broken test cases which is not compatible with sha256.
Add capability "object-format=$GIT_DEFAULT_HASH" in "t/t5411/once-0010-report-status-v1.sh". See range-diff:
4: 00c9eee210 ! 4: 215d786adc New capability "report-status-v2" for git-push
@@ builtin/receive-pack.c: static void show_ref(const char *path, const struct obje
strbuf_addstr(&cap, " atomic");
if (prefer_ofs_delta)
@@ builtin/receive-pack.c: static struct command *read_head_info(struct packet_reader *reader,
- const char *feature_list = reader->line + linelen + 1;
+ int len = 0;
if (parse_feature_request(feature_list, "report-status"))
report_status = 1;
+ if (parse_feature_request(feature_list, "report-status-v2"))
@@ t/t5411/once-0010-report-status-v1.sh (new)
+# git push : (B) refs/for/master/topic1(A) foo(A) refs/for/next/topic(A) refs/for/master/topic2(A)
+test_expect_success "proc-receive: report status v1" '
+ {
-+ printf "%s %s refs/heads/master\0report-status\n" \
-+ $A $B | packetize &&
++ if test -z "$GIT_DEFAULT_HASH" || test "$GIT_DEFAULT_HASH" = "sha1"
++ then
++ printf "%s %s refs/heads/master\0report-status\n" \
++ $A $B | packetize
++ else
++ printf "%s %s refs/heads/master\0report-status object-format=$GIT_DEFAULT_HASH\n" \
++ $A $B | packetize
++ fi &&
+ printf "%s %s refs/for/master/topic1\n" \
+ $ZERO_OID $A | packetize &&
+ printf "%s %s refs/heads/foo\n" \3. Add optional modifiers for config variable "receive.procReceiveRefs". See range-diff:
7: 97704cbcc6 < -: ---------- refs.c: refactor to reuse ref_is_hidden()
8: 415677f838 ! 7: 08b176a61a receive-pack: new config receive.procReceiveRefs
@@ Commit message
git config --system --add receive.procReceiveRefs refs/for
git config --system --add receive.procReceiveRefs refs/drafts
- If the specific prefix strings match the reference names of the commands
- which are sent from git client to `receive-pack`, these commands will be
- executed by an external hook (named "proc-receive"), instead of the
- internal `execute_commands` function.
+ If the specific prefix strings given by the config variables match the
+ reference names of the commands which are sent from git client to
+ `receive-pack`, these commands will be executed by an external hook
+ (named "proc-receive"), instead of the internal `execute_commands`
+ function.
For example, if it is set to "refs/for", pushing to a reference such as
"refs/for/master" will not create or update reference "refs/for/master",
but may create or update a pull request directly by running the hook
"proc-receive".
+ Optional modifiers can be provided in the beginning of value of the
+ config variable to filter commands for specific actions: create (a),
+ mofify (m), delete (d). E.g.:
+
+ git config --system --add receive.procReceiveRefs ad:refs/heads
+
Signed-off-by: Jiang Xin <[email protected]>
## Documentation/config/receive.txt ##
@@ Documentation/config/receive.txt: receive.hideRefs::
+ variable is not defined, the "proc-receive" hook will never be
+ used, and all commands will be executed by the internal
+ `execute_commands` function.
-+
-+ For example, if this variable is set to "refs/for", pushing to
-+ reference such as "refs/for/master" will not create or update a
-+ reference named "refs/for/master", but may create or update a
-+ pull request directly by running the hook "proc-receive".
-+
+++
++For example, if this variable is set to "refs/for", pushing to reference
++such as "refs/for/master" will not create or update a reference named
++"refs/for/master", but may create or update a pull request directly by
++running the hook "proc-receive".
+++
++Optional modifiers can be provided in the beginning of the value to filter
++commands for specific actions: create (a), mofify (m), delete (d). E.g.:
+++
++ git config --system --add receive.procReceiveRefs ad:refs/heads
++
receive.updateServerInfo::
If set to true, git-receive-pack will run git-update-server-info
after receiving data from git-push and updating refs.
## builtin/receive-pack.c ##
-@@ builtin/receive-pack.c: static struct object_id push_cert_oid;
- static struct signature_check sigcheck;
- static const char *push_cert_nonce;
- static const char *cert_nonce_seed;
-+static struct string_list proc_receive_refs;
+@@ builtin/receive-pack.c: static int keepalive_in_sec = 5;
- static const char *NONCE_UNSOLICITED = "UNSOLICITED";
- static const char *NONCE_BAD = "BAD";
+ static struct tmp_objdir *tmp_objdir;
+
++static struct proc_receive_ref {
++ unsigned int want_add:1,
++ want_delete:1,
++ want_modify:1;
++ char *ref_prefix;
++ struct proc_receive_ref *next;
++} *proc_receive_ref = NULL;
++
++static void proc_receive_ref_append(const char *prefix);
++
+ static enum deny_action parse_deny_action(const char *var, const char *value)
+ {
+ if (value) {
@@ builtin/receive-pack.c: static int receive_pack_config(const char *var, const char *value, void *cb)
return 0;
}
+ if (strcmp(var, "receive.procreceiverefs") == 0) {
-+ char *prefix;
-+ int len;
-+
+ if (!value)
+ return config_error_nonbool(var);
-+ prefix = xstrdup(value);
-+ len = strlen(prefix);
-+ while (len && prefix[len - 1] == '/')
-+ prefix[--len] = '\0';
-+ string_list_append(&proc_receive_refs, prefix);
++ proc_receive_ref_append(value);
+ return 0;
+ }
+
return git_default_config(var, value, cb);
}
+@@ builtin/receive-pack.c: struct command {
+ char ref_name[FLEX_ARRAY]; /* more */
+ };
+
++static void proc_receive_ref_append(const char *prefix)
++{
++ struct proc_receive_ref *ref_pattern;
++ char *p;
++ int len;
++
++ ref_pattern = xcalloc(1, sizeof(struct proc_receive_ref));
++ p = strchr(prefix, ':');
++ if (p) {
++ while (prefix < p) {
++ if (*prefix == 'a')
++ ref_pattern->want_add = 1;
++ else if (*prefix == 'd')
++ ref_pattern->want_delete = 1;
++ else if (*prefix == 'm')
++ ref_pattern->want_modify = 1;
++ prefix++;
++ }
++ prefix++;
++ } else {
++ ref_pattern->want_add = 1;
++ ref_pattern->want_delete = 1;
++ ref_pattern->want_modify = 1;
++ }
++ ref_pattern->next = NULL;
++ ref_pattern->ref_prefix = xstrdup(prefix);
++ len = strlen(ref_pattern->ref_prefix);
++ while (len && ref_pattern->ref_prefix[len - 1] == '/')
++ ref_pattern->ref_prefix[--len] = '\0';
++ if (proc_receive_ref == NULL) {
++ proc_receive_ref = ref_pattern;
++ } else {
++ struct proc_receive_ref *end;
++
++ end = proc_receive_ref;
++ while (end->next)
++ end = end->next;
++ end->next = ref_pattern;
++ }
++}
++
++static int proc_receive_ref_matches(struct command *cmd)
++{
++ struct proc_receive_ref *p;
++
++ if (!proc_receive_ref)
++ return 0;
++
++ for (p = proc_receive_ref; p; p = p->next) {
++ const char *match = p->ref_prefix;
++ int neg = 0;
++ const char *remains;
++
++ if (!p->want_add && is_null_oid(&cmd->old_oid))
++ continue;
++ else if (!p->want_delete && is_null_oid(&cmd->new_oid))
++ continue;
++ else if (!p->want_modify &&
++ !is_null_oid(&cmd->old_oid) &&
++ !is_null_oid(&cmd->new_oid))
++ continue;
++
++ if (*match == '!') {
++ neg = 1;
++ match++;
++ }
++
++ if (skip_prefix(cmd->ref_name, match, &remains) &&
++ (!*remains || *remains == '/')) {
++ if (!neg)
++ return 1;
++ } else if (neg) {
++ return 1;
++ }
++ }
++ return 0;
++}
++
+ static void rp_error(const char *err, ...) __attribute__((format (printf, 1, 2)));
+ static void rp_warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
+
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
* Try to find commands that have special prefix in their reference names,
* and mark them to run an external "proc-receive" hook later.
@@ builtin/receive-pack.c: static void execute_commands(struct command *commands,
- for (cmd = commands; cmd; cmd = cmd->next) {
- if (!should_process_cmd(cmd))
- continue;
-+ if (proc_receive_refs.nr > 0) {
-+ struct strbuf refname_full = STRBUF_INIT;
-+ size_t prefix_len;
-+
-+ strbuf_addstr(&refname_full, get_git_namespace());
-+ prefix_len = refname_full.len;
++ if (proc_receive_ref) {
++ for (cmd = commands; cmd; cmd = cmd->next) {
++ if (!should_process_cmd(cmd))
++ continue;
- /* TODO: replace the fixed prefix by looking up git config variables. */
- if (!strncmp(cmd->ref_name, "refs/for/", 9)) {
- cmd->run_proc_receive = RUN_PROC_RECEIVE_SCHEDULED;
- run_proc_receive = 1;
-+ for (cmd = commands; cmd; cmd = cmd->next) {
-+ if (!should_process_cmd(cmd))
-+ continue;
-+
-+ strbuf_setlen(&refname_full, prefix_len);
-+ strbuf_addstr(&refname_full, cmd->ref_name);
-+ if (ref_matches(&proc_receive_refs, cmd->ref_name, refname_full.buf)) {
++ if (proc_receive_ref_matches(cmd)) {
+ cmd->run_proc_receive = RUN_PROC_RECEIVE_SCHEDULED;
+ run_proc_receive = 1;
+ }
}
-+
-+ strbuf_release(&refname_full);
}
- if (run_receive_hook(commands, "pre-receive", 0, push_options)) {
-@@ builtin/receive-pack.c: int cmd_receive_pack(int argc, const char **argv, const char *prefix)
- OPT_END()
- };
-
-+ string_list_init(&proc_receive_refs, 0);
-+
- packet_trace_identity("receive-pack");
-
- argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0);
-@@ builtin/receive-pack.c: int cmd_receive_pack(int argc, const char **argv, const char *prefix)
- oid_array_clear(&shallow);
- oid_array_clear(&ref);
- free((void *)push_cert_nonce);
-+ string_list_clear(&proc_receive_refs, 0);
- return 0;
- }
## t/t5411/once-0010-report-status-v1.sh ##
@@
@@ t/t5411/test-0041-process-all-refs--porcelain.sh (new)
+ git update-ref -d refs/heads/baz
+ )
+'
+
+ ## t/t5411/test-0050-proc-receive-refs.sh (new) ##
+@@
++test_expect_success "config receive.procReceiveRefs with modifiers ($PROTOCOL)" '
++ (
++ cd "$upstream" &&
++ git config --unset-all receive.procReceiveRefs &&
++ git config --add receive.procReceiveRefs m:refs/heads/master &&
++ git config --add receive.procReceiveRefs ad:refs/heads &&
++ git config --add receive.procReceiveRefs "a:!refs/heads"
++ )
++'
++
++test_expect_success "setup proc-receive hook ($PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/heads/master" \
++ -r "option refname refs/pull/123/head" \
++ -r "option old-oid $A" \
++ -r "option new-oid $B" \
++ -r "ok refs/tags/v123 " \
++ -r "option refname refs/pull/124/head"
++ EOF
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++# git push : master(B) tags/v123
++test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" '
++ git -C workbench push origin \
++ $B:refs/heads/master \
++ v123 >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ remote: pre-receive< <ZERO-OID> <TAG-v123> refs/tags/v123
++ remote: # proc-receive hook
++ remote: proc-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
++ remote: proc-receive< <ZERO-OID> <TAG-v123> refs/tags/v123
++ remote: proc-receive> ok refs/heads/master
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <COMMIT-B>
++ remote: proc-receive> ok refs/tags/v123
++ remote: proc-receive> option refname refs/pull/124/head
++ remote: # post-receive hook
++ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head
++ remote: post-receive< <ZERO-OID> <TAG-v123> refs/pull/124/head
++ To <URL/of/upstream.git>
++ <OID-A>..<OID-B> <COMMIT-B> -> refs/pull/123/head
++ * [new reference] v123 -> refs/pull/124/head
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'
++
++# Refs of upstream : master(A)
++# Refs of workbench: master(A) tags/v123
++test_expect_success "setup upstream: create tags/v123 ($PROTOCOL)" '
++ git -C "$upstream" update-ref refs/tags/v123 $TAG &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ <TAG-v123> refs/tags/v123
++ EOF
++ test_cmp expect actual
++'
++
++test_expect_success "setup proc-receive hook ($PROTOCOL)" '
++ write_script "$upstream/hooks/proc-receive" <<-EOF
++ printf >&2 "# proc-receive hook\n"
++ test-tool proc-receive -v \
++ -r "ok refs/heads/master" \
++ -r "option refname refs/pull/123/head" \
++ -r "option old-oid $A" \
++ -r "option new-oid $ZERO_OID" \
++ -r "ok refs/heads/next" \
++ -r "option refname refs/pull/124/head" \
++ -r "option new-oid $A"
++ EOF
++'
++
++# Refs of upstream : master(A) tags/v123
++# Refs of workbench: master(A) tags/v123
++# git push : NULL NULL next(A)
++test_expect_success "proc-receive: create/delete branch, and delete tag ($PROTOCOL)" '
++ git -C workbench push origin \
++ :refs/heads/master \
++ $A:refs/heads/next \
++ :refs/tags/v123 >out 2>&1 &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ remote: # pre-receive hook
++ remote: pre-receive< <COMMIT-A> <ZERO-OID> refs/heads/master
++ remote: pre-receive< <TAG-v123> <ZERO-OID> refs/tags/v123
++ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ remote: # proc-receive hook
++ remote: proc-receive< <COMMIT-A> <ZERO-OID> refs/heads/master
++ remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
++ remote: proc-receive> ok refs/heads/master
++ remote: proc-receive> option refname refs/pull/123/head
++ remote: proc-receive> option old-oid <COMMIT-A>
++ remote: proc-receive> option new-oid <ZERO-OID>
++ remote: proc-receive> ok refs/heads/next
++ remote: proc-receive> option refname refs/pull/124/head
++ remote: proc-receive> option new-oid <COMMIT-A>
++ remote: # post-receive hook
++ remote: post-receive< <COMMIT-A> <ZERO-OID> refs/pull/123/head
++ remote: post-receive< <TAG-v123> <ZERO-OID> refs/tags/v123
++ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/124/head
++ To <URL/of/upstream.git>
++ - [deleted] refs/pull/123/head
++ - [deleted] v123
++ * [new reference] <COMMIT-A> -> refs/pull/124/head
++ EOF
++ test_cmp expect actual &&
++ git -C "$upstream" show-ref >out &&
++ make_user_friendly_and_stable_output <out >actual &&
++ cat >expect <<-EOF &&
++ <COMMIT-A> refs/heads/master
++ EOF
++ test_cmp expect actual
++'---
Jiang Xin (10):
transport: not report a non-head push as a branch
t5411: add basic test cases for proc-receive hook
receive-pack: add new proc-receive hook New capability "report-status-v2" for git-push
doc: add document for capability report-status-v2
receive-pack: feed report options to post-receive
receive-pack: new config receive.procReceiveRefs
t5411: test updates of remote-tracking branches
transport: parse report options for tracking refs
doc: add documentation for the proc-receive hook
Documentation/config/receive.txt | 19 + Documentation/githooks.txt | 62 ++ Documentation/technical/pack-protocol.txt | 43 +- .../technical/protocol-capabilities.txt | 17 +- Makefile | 1 + builtin/receive-pack.c | 528 ++++++++++++++++-- builtin/send-pack.c | 21 +- remote.c | 4 +- remote.h | 16 +- send-pack.c | 99 +++- t/helper/test-proc-receive.c | 176 ++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411-proc-receive-hook.sh | 117 ++++ t/t5411/common-functions.sh | 56 ++ t/t5411/once-0010-report-status-v1.sh | 94 ++++ t/t5411/test-0000-standard-git-push.sh | 143 +++++ .../test-0001-standard-git-push--porcelain.sh | 147 +++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++ t/t5411/test-0010-proc-receive-settings.sh | 7 + t/t5411/test-0011-no-hook-error.sh | 64 +++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 +++ t/t5411/test-0013-bad-protocol.sh | 217 +++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++ t/t5411/test-0020-report-ng.sh | 67 +++ t/t5411/test-0021-report-ng--porcelain.sh | 69 +++ t/t5411/test-0022-report-unexpect-ref.sh | 45 ++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 ++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 +++ t/t5411/test-0027-push-options--porcelain.sh | 82 +++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-with-options.sh | 256 +++++++++ ...est-0033-report-with-options--porcelain.sh | 265 +++++++++ t/t5411/test-0034-report-ft.sh | 44 ++ t/t5411/test-0035-report-ft--porcelain.sh | 45 ++ ...t-0036-report-multi-rewrite-for-one-ref.sh | 227 ++++++++ ...rt-multi-rewrite-for-one-ref--porcelain.sh | 172 ++++++ t/t5411/test-0038-report-mixed-refs.sh | 89 +++ .../test-0039-report-mixed-refs--porcelain.sh | 91 +++ t/t5411/test-0040-process-all-refs.sh | 113 ++++ .../test-0041-process-all-refs--porcelain.sh | 114 ++++ t/t5411/test-0050-proc-receive-refs.sh | 128 +++++ t/t5516-fetch-push.sh | 2 +- transport-helper.c | 53 +- transport.c | 161 ++++-- 49 files changed, 4307 insertions(+), 107 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/once-0010-report-status-v1.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-with-options.sh create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh create mode 100644 t/t5411/test-0050-proc-receive-refs.sh
Signature · 1 line
2.28.0
v18 cover New proc-receive hook for centralized workflow
From: Jiang Xin <[email protected]>
## Changes since v17
Fixed all issues found in review on v17.
Quoted 1 line
Did I???? I do not think I deserve any credit here.
@@ Commit message
extended in latter commit just like what the "proc-receive" hook reports to "receive-pack".
- Suggested-by: Junio C Hamano <[email protected]>
Quoted 3 lines
Does the last cast really needed, perhaps the caller is adding "const" to its objects where it is not needed, or the variable caller uses to receive the returned value of too loose a type?
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
return finish_command(&proc);
}
-+static struct command *find_command_by_refname(const struct command *list,
++static struct command *find_command_by_refname(struct command *list,
+ const char *refname)
+{
+ for (; list; list = list->next)
+ if (!strcmp(list->ref_name, refname))
-+ return (struct command *)list;
++ return list;
+ return NULL;
+}
+Quoted 1 line
Let BSS do its job by omitting " = 0;" and " = NULL;" at the end.
@@ t/helper/test-proc-receive.c (new)
+ NULL
+};
+
-+static int die_version = 0;
-+static int die_readline = 0;
-+static int no_push_options = 0;
-+static int use_atomic = 0;
-+static int use_push_options = 0;
-+static int verbose = 0;
++static int die_version;
++static int die_readline;
++static int no_push_options;
++static int use_atomic;
++static int use_push_options;
++static int verbose;
+static int version = 1;
+static struct string_list returns = STRING_LIST_INIT_NODUP;
+Quoted 9 lines
This comment applies to all the patches in this series that adds the same pattern, but
* "
ref->report.options" may be a good name in that it is a (linked) list of options;* The variable that is used to iterate over the list points at one of the elements on the list at any time, and is better called 'option' without 's' at the end.
Merge "struct ref_push_report_options" into "struct ref_push_report".
@@ remote.h: int for_each_remote(each_remote_fn fn, void *priv);
int remote_has_url(struct remote *remote, const char *url);
-+struct ref_push_report_options {
++struct ref_push_report {
+ const char *ref_name;
+ struct object_id *old_oid;
+ struct object_id *new_oid;
+ unsigned int forced_update:1;
-+ struct ref_push_report_options *next;
-+};
-+
-+struct ref_push_report {
-+ const char *message;
-+ const char *error_message;
-+ struct ref_push_report_options *options;
++ struct ref_push_report *next;
+};
+
struct ref {Quoted 4 lines
If there was an error, the first one gets "ng" but all others say it was "ok"? That smells somewhat strange.
Would this one ever report a "ng" for an error?
Preserve "error_string" in command, and no "options" for an "ng" error.
@@ builtin/receive-pack.c: static void write_head_info(void)
+#define RUN_PROC_RECEIVE_RETURNED 2
struct command {
struct command *next;
-- const char *error_string;
-+ struct ref_push_report report;
+ const char *error_string;
++ struct ref_push_report *report;
unsigned int skip_update:1,
- did_not_exist:1;
+ did_not_exist:1,
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+{
+ struct command *cmd;
+ struct command *hint = NULL;
++ struct ref_push_report *report = NULL;
++ int new_report = 0;
+ int code = 0;
-+ int new_options = 1;
++ int once = 0;
+
+ for (;;) {
+ struct object_id old_oid, new_oid;
@@ builtin/receive-pack.c: static int run_update_hook(struct command *cmd)
+ }
+ *p++ = '\0';
+ if (!strcmp(head, "option")) {
-+ struct ref_push_report_options *options;
+ const char *key, *val;
+
-+ if (!hint) {
-+ if (new_options) {
++ if (!hint || !(report || new_report)) {
++ if (!once++)
+ strbuf_addstr(errmsg, "proc-receive reported 'option' without a matching 'ok/ng' directive\n");
-+ new_options = 0;
-+ }
+ code = -1;
+ continue;
+ }
-+ options = hint->report.options;
-+ while (options && options->next)
-+ options = options->next;
-+ if (new_options) {
-+ if (!options) {
-+ hint->report.options = xcalloc(1, sizeof(struct ref_push_report_options));
-+ options = hint->report.options;
++ if (new_report) {
++ if (!hint->report) {
++ hint->report = xcalloc(1, sizeof(struct ref_push_report));
++ report = hint->report;
+ } else {
-+ options->next = xcalloc(1, sizeof(struct ref_push_report_options));
-+ options = options->next;
++ report = hint->report;
++ while (report->next)
++ report = report->next;
++ report->next = xcalloc(1, sizeof(struct ref_push_report));
++ report = report->next;
+ }
-+ new_options = 0;
++ new_report = 0;
+ }
-+ assert(options);
+ key = p;
+ p = strchr(key, ' ');
+ if (p)
+ *p++ = '\0';
+ val = p;
+ if (!strcmp(key, "refname"))
-+ options->ref_name = xstrdup_or_null(val);
++ report->ref_name = xstrdup_or_null(val);
+ else if (!strcmp(key, "old-oid") && val &&
+ !parse_oid_hex(val, &old_oid, &val))
-+ options->old_oid = oiddup(&old_oid);
++ report->old_oid = oiddup(&old_oid);
+ else if (!strcmp(key, "new-oid") && val &&
+ !parse_oid_hex(val, &new_oid, &val))
-+ options->new_oid = oiddup(&new_oid);
++ report->new_oid = oiddup(&new_oid);
+ else if (!strcmp(key, "forced-update"))
-+ options->forced_update = 1;
++ report->forced_update = 1;
+ else if (!strcmp(key, "fall-through"))
+ /* Fall through, let 'receive-pack' to execute it. */
+ hint->run_proc_receive = 0;
+ continue;
+ }
+
++ report = NULL;
++ new_report = 0;
+ refname = p;
+ p = strchr(refname, ' ');
+ if (p)Quoted 2 lines
Our naming convention avoids leading underscore (instead we use _1 suffix, when we cannot come up with a better name).
Rename "_print_one_push_status" to "print_one_push_report".
@@ transport.c: static void print_ok_ref_status(struct ref *ref, int porcelain, int
print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg,
- porcelain, summary_width);
-+ options, porcelain, summary_width);
++ report, porcelain, summary_width);
strbuf_release(&quickref);
}
}
-static int print_one_push_status(struct ref *ref, const char *dest, int count,
-- int porcelain, int summary_width)
-+static int _print_one_push_status(struct ref *ref, const char *dest, int count,
-+ struct ref_push_report_options *options,
-+ int porcelain, int summary_width)
++static int print_one_push_report(struct ref *ref, const char *dest, int count,
++ struct ref_push_report *report,
+ int porcelain, int summary_width)
{
if (!count) {
- char *url = transport_anonymize_url(dest);Quoted 7 lines
I hate to see more helper functions turned into pieces that are impossible to reuse by gaining internal state like this. Does this function have so many callers that makes it impractical to update its signature to have the pointer to a "state" structure passed by the caller? This is called only from
push_update_refs_status(), so you should be able to define a new structure that has the two fields
Quoted 7 lines
struct { struct ref *hint; int new_option; };initialize an instance of it before
push_update_refs_status()enters its endless loop, and pass a pointer to it to this helper function.
## transport-helper.c ##
-@@ transport-helper.c: static int push_update_ref_status(struct strbuf *buf,
+@@ transport-helper.c: static int fetch(struct transport *transport,
+ return -1;
+ }
+
++struct push_update_ref_state {
++ struct ref *hint;
++ struct ref_push_report *report;
++ int new_report;
++};
++
+ static int push_update_ref_status(struct strbuf *buf,
+- struct ref **ref,
++ struct push_update_ref_state *state,
+ struct ref *remote_refs)
{
char *refname, *msg;
int status, forced = 0;
-+ static struct ref *hint = NULL;
-+ static int new_options = 1;
-+
+
+ if (starts_with(buf->buf, "option ")) {
-+ struct ref_push_report_options *options;
+ struct object_id old_oid, new_oid;
+ const char *key, *val;
+ char *p;
+
-+ if (!hint)
++ if (!state->hint || !(state->report || state->new_report))
+ die(_("'option' without a matching 'ok/error' directive"));
-+ options = hint->report.options;
-+ while (options && options->next)
-+ options = options->next;
-+ if (new_options) {
-+ if (!options) {
-+ hint->report.options = xcalloc(1, sizeof(struct ref_push_report_options));
-+ options = hint->report.options;
++ if (state->new_report) {
++ if (!state->hint->report) {
++ state->hint->report = xcalloc(1, sizeof(struct ref_push_report));
++ state->report = state->hint->report;
+ } else {
-+ options->next = xcalloc(1, sizeof(struct ref_push_report_options));
-+ options = options->next;
++ state->report = state->hint->report;
++ while (state->report->next)
++ state->report = state->report->next;
++ state->report->next = xcalloc(1, sizeof(struct ref_push_report));
++ state->report = state->report->next;
+ }
-+ new_options = 0;
++ state->new_report = 0;
+ }
-+ assert(options);
+ key = buf->buf + 7;
+ p = strchr(key, ' ');
+ if (p)
+ *p++ = '\0';
+ val = p;
+ if (!strcmp(key, "refname"))
-+ options->ref_name = xstrdup_or_null(val);
++ state->report->ref_name = xstrdup_or_null(val);
+ else if (!strcmp(key, "old-oid") && val &&
+ !parse_oid_hex(val, &old_oid, &val))
-+ options->old_oid = oiddup(&old_oid);
++ state->report->old_oid = oiddup(&old_oid);
+ else if (!strcmp(key, "new-oid") && val &&
+ !parse_oid_hex(val, &new_oid, &val))
-+ options->new_oid = oiddup(&new_oid);
++ state->report->new_oid = oiddup(&new_oid);
+ else if (!strcmp(key, "forced-update"))
-+ options->forced_update = 1;
++ state->report->forced_update = 1;
+ /* Not update remote namespace again. */
+ return 1;
+ }
-
++
++ state->report = NULL;
++ state->new_report = 0;
++
if (starts_with(buf->buf, "ok ")) {
status = REF_STATUS_OK;
+ refname = buf->buf + 3;
@@ transport-helper.c: static int push_update_ref_status(struct strbuf *buf,
- *ref = find_ref_by_name(remote_refs, refname);
- if (!*ref) {
+ }
+ }
+
+- if (*ref)
+- *ref = find_ref_by_name(*ref, refname);
+- if (!*ref)
+- *ref = find_ref_by_name(remote_refs, refname);
+- if (!*ref) {
++ if (state->hint)
++ state->hint = find_ref_by_name(state->hint, refname);
++ if (!state->hint)
++ state->hint = find_ref_by_name(remote_refs, refname);
++ if (!state->hint) {
warning(_("helper reported unexpected status of %s"), refname);
-+ hint = NULL;
return 1;
}
-+ hint = *ref;
-+ new_options = 1;
- if ((*ref)->status != REF_STATUS_NONE) {
+- if ((*ref)->status != REF_STATUS_NONE) {
++ if (state->hint->status != REF_STATUS_NONE) {
/*
+ * Earlier, the ref was marked not to be pushed, so ignore the ref
+ * status reported by the remote helper if the latter is 'no match'.
@@ transport-helper.c: static int push_update_ref_status(struct strbuf *buf,
+ return 1;
+ }
- (*ref)->status = status;
- (*ref)->forced_update |= forced;
+- (*ref)->status = status;
+- (*ref)->forced_update |= forced;
- (*ref)->remote_status = msg;
-+ if (msg) {
-+ if (status == REF_STATUS_OK)
-+ (*ref)->report.message = msg;
-+ else
-+ (*ref)->report.error_message = msg;
-+ }
++ if (status == REF_STATUS_OK)
++ state->new_report = 1;
++ state->hint->status = status;
++ state->hint->forced_update |= forced;
++ state->hint->remote_status = msg;
return !(status == REF_STATUS_OK);
}
+@@ transport-helper.c: static int push_update_refs_status(struct helper_data *data,
+ struct ref *remote_refs,
+ int flags)
+ {
++ struct ref *ref;
++ struct ref_push_report *report;
+ struct strbuf buf = STRBUF_INIT;
+- struct ref *ref = remote_refs;
+- int ret = 0;
++ struct push_update_ref_state state = { remote_refs, NULL, 0 };
+
+ for (;;) {
+- char *private;
+-
+ if (recvline(data, &buf)) {
+- ret = 1;
+- break;
++ strbuf_release(&buf);
++ return 1;
+ }
+-
+ if (!buf.len)
+ break;
++ push_update_ref_status(&buf, &state, remote_refs);
++ }
++ strbuf_release(&buf);
+
+- if (push_update_ref_status(&buf, &ref, remote_refs))
+- continue;
++ if (flags & TRANSPORT_PUSH_DRY_RUN || !data->rs.nr || data->no_private_update)
++ return 0;
+
+- if (flags & TRANSPORT_PUSH_DRY_RUN || !data->rs.nr || data->no_private_update)
+- continue;
++ /* propagate back the update to the remote namespace */
++ for (ref = remote_refs; ref; ref = ref->next) {
++ char *private;
+
+- /* propagate back the update to the remote namespace */
+- private = apply_refspecs(&data->rs, ref->name);
+- if (!private)
++ if (ref->status != REF_STATUS_OK)
+ continue;
+- update_ref("update by helper", private, &ref->new_oid, NULL,
+- 0, 0);
+- free(private);
++
++ if (!ref->report) {
++ private = apply_refspecs(&data->rs, ref->name);
++ if (!private)
++ continue;
++ update_ref("update by helper", private, &(ref->new_oid),
++ NULL, 0, 0);
++ free(private);
++ } else {
++ for (report = ref->report; report; report = report->next) {
++ private = apply_refspecs(&data->rs,
++ report->ref_name
++ ? report->ref_name
++ : ref->name);
++ if (!private)
++ continue;
++ update_ref("update by helper", private,
++ report->new_oid
++ ? report->new_oid
++ : &(ref->new_oid),
++ NULL, 0, 0);
++ free(private);
++ }
++ }
+ }
+- strbuf_release(&buf);
+- return ret;
++ return 0;
+ }
+
+ static void set_common_push_options(struct transport *transport,Quoted 3 lines
Exactly the same comment as "don't turn helper functions that can be reused into unreusable ones by adding internal states" as one of the previous patches applies here.
6: ca4fc6d511 ! 4: 60b9157a8e receive-pack: feed report options to post-receive
@@ Commit message
Signed-off-by: Jiang Xin <[email protected]>
## builtin/receive-pack.c ##
-@@ builtin/receive-pack.c: static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
- {
- struct receive_hook_feed_state *state = state_;
- struct command *cmd = state->cmd;
-+ static struct ref_push_report_options *options = NULL;
+@@ builtin/receive-pack.c: static void prepare_push_cert_sha1(struct child_process *proc)
- while (cmd &&
- state->skip_broken && (cmd->report.error_message || cmd->did_not_exist))
+ struct receive_hook_feed_state {
+ struct command *cmd;
++ struct ref_push_report *report;
+ int skip_broken;
+ struct strbuf buf;
+ const struct string_list *push_options;
+@@ builtin/receive-pack.c: static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
cmd = cmd->next;
if (!cmd)
return -1; /* EOF */
@@ builtin/receive-pack.c: static int feed_receive_hook(void *state_, const char **
- oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid),
- cmd->ref_name);
- state->cmd = cmd->next;
-+ if (!options)
-+ options = cmd->report.options;
-+ if (options) {
++ if (!state->report)
++ state->report = cmd->report;
++ if (state->report) {
+ struct object_id *old_oid;
+ struct object_id *new_oid;
+ const char *ref_name;
+
-+ old_oid = options->old_oid ? options->old_oid : &cmd->old_oid;
-+ new_oid = options->new_oid ? options->new_oid : &cmd->new_oid;
-+ ref_name = options->ref_name ? options->ref_name : cmd->ref_name;
++ old_oid = state->report->old_oid ? state->report->old_oid : &cmd->old_oid;
++ new_oid = state->report->new_oid ? state->report->new_oid : &cmd->new_oid;
++ ref_name = state->report->ref_name ? state->report->ref_name : cmd->ref_name;
+ strbuf_addf(&state->buf, "%s %s %s\n",
+ oid_to_hex(old_oid), oid_to_hex(new_oid),
+ ref_name);
-+ options = options->next;
-+ if (!options)
++ state->report = state->report->next;
++ if (!state->report)
+ state->cmd = cmd->next;
+ } else {
+ strbuf_addf(&state->buf, "%s %s %s\n",
+@@ builtin/receive-pack.c: static int run_receive_hook(struct command *commands,
+ strbuf_init(&state.buf, 0);
+ state.cmd = commands;
+ state.skip_broken = skip_broken;
++ state.report = NULL;
+ if (feed_receive_hook(&state, NULL, NULL))
+ return 0;
+ state.cmd = commands;Quoted 8 lines
Why not count "
size_tlen" before you make a copy of prefix with tail adjustment, so that you can doxmemdupz()at the end without need for potential overallocation?Style:
if (!proc_receive_ref) {like you did below.
@@ builtin/receive-pack.c: struct command {
+ ref_pattern->want_delete = 1;
+ ref_pattern->want_modify = 1;
+ }
-+ ref_pattern->next = NULL;
-+ ref_pattern->ref_prefix = xstrdup(prefix);
-+ len = strlen(ref_pattern->ref_prefix);
-+ while (len && ref_pattern->ref_prefix[len - 1] == '/')
-+ ref_pattern->ref_prefix[--len] = '\0';
-+ if (proc_receive_ref == NULL) {
++ len = strlen(prefix);
++ while (len && prefix[len - 1] == '/')
++ len--;
++ ref_pattern->ref_prefix = xmemdupz(prefix, len);
++ if (!proc_receive_ref) {
+ proc_receive_ref = ref_pattern;
+ } else {
+ struct proc_receive_ref *end;Quoted 3 lines
Shouldn't the "negate" bit be jsut another field that has want_{add,delete,modify}, so that
proc_receive_ref_append()can parse it only once without these four lines?
@@ builtin/receive-pack.c: static int keepalive_in_sec = 5;
+static struct proc_receive_ref {
+ unsigned int want_add:1,
+ want_delete:1,
-+ want_modify:1;
++ want_modify:1,
++ negative_ref:1;
+ char *ref_prefix;
+ struct proc_receive_ref *next;
-+} *proc_receive_ref = NULL;
++} *proc_receive_ref;
+
+static void proc_receive_ref_append(const char *prefix);
+
@@ builtin/receive-pack.c: struct command {
+ ref_pattern->want_delete = 1;
+ else if (*prefix == 'm')
+ ref_pattern->want_modify = 1;
++ else if (*prefix == '!')
++ ref_pattern->negative_ref = 1;
+ prefix++;
+ }
+ prefix++;
@@ builtin/receive-pack.c: struct command {
+
+ for (p = proc_receive_ref; p; p = p->next) {
+ const char *match = p->ref_prefix;
-+ int neg = 0;
+ const char *remains;
+
+ if (!p->want_add && is_null_oid(&cmd->old_oid))
@@ builtin/receive-pack.c: struct command {
+ !is_null_oid(&cmd->new_oid))
+ continue;
+
-+ if (*match == '!') {
-+ neg = 1;
-+ match++;
-+ }
-+
+ if (skip_prefix(cmd->ref_name, match, &remains) &&
+ (!*remains || *remains == '/')) {
-+ if (!neg)
++ if (!p->negative_ref)
+ return 1;
-+ } else if (neg) {
++ } else if (p->negative_ref) {
+ return 1;
+ }
+ }
@@ t/t5411/test-0050-proc-receive-refs.sh (new)
+ git config --unset-all receive.procReceiveRefs &&
+ git config --add receive.procReceiveRefs m:refs/heads/master &&
+ git config --add receive.procReceiveRefs ad:refs/heads &&
-+ git config --add receive.procReceiveRefs "a:!refs/heads"
++ git config --add receive.procReceiveRefs "a!:refs/heads"
+ )
+'
+---
Jiang Xin (10):
transport: not report a non-head push as a branch
t5411: add basic test cases for proc-receive hook
receive-pack: add new proc-receive hook
receive-pack: feed report options to post-receive New capability "report-status-v2" for git-push
doc: add document for capability report-status-v2
receive-pack: new config receive.procReceiveRefs
t5411: test updates of remote-tracking branches
transport: parse report options for tracking refs
doc: add documentation for the proc-receive hook
Documentation/config/receive.txt | 21 + Documentation/githooks.txt | 62 +++ Documentation/technical/pack-protocol.txt | 43 +- .../technical/protocol-capabilities.txt | 17 +- Makefile | 1 + builtin/receive-pack.c | 472 +++++++++++++++++- builtin/send-pack.c | 19 + remote.h | 9 + send-pack.c | 101 +++- t/helper/test-proc-receive.c | 176 +++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411-proc-receive-hook.sh | 117 +++++ t/t5411/common-functions.sh | 56 +++ t/t5411/once-0010-report-status-v1.sh | 94 ++++ t/t5411/test-0000-standard-git-push.sh | 143 ++++++ .../test-0001-standard-git-push--porcelain.sh | 147 ++++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++ t/t5411/test-0010-proc-receive-settings.sh | 7 + t/t5411/test-0011-no-hook-error.sh | 64 +++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 +++ t/t5411/test-0013-bad-protocol.sh | 217 ++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++ t/t5411/test-0020-report-ng.sh | 67 +++ t/t5411/test-0021-report-ng--porcelain.sh | 69 +++ t/t5411/test-0022-report-unexpect-ref.sh | 45 ++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 ++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 +++ t/t5411/test-0027-push-options--porcelain.sh | 82 +++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-with-options.sh | 256 ++++++++++ ...est-0033-report-with-options--porcelain.sh | 265 ++++++++++ t/t5411/test-0034-report-ft.sh | 44 ++ t/t5411/test-0035-report-ft--porcelain.sh | 45 ++ ...t-0036-report-multi-rewrite-for-one-ref.sh | 227 +++++++++ ...rt-multi-rewrite-for-one-ref--porcelain.sh | 172 +++++++ t/t5411/test-0038-report-mixed-refs.sh | 89 ++++ .../test-0039-report-mixed-refs--porcelain.sh | 91 ++++ t/t5411/test-0040-process-all-refs.sh | 113 +++++ .../test-0041-process-all-refs--porcelain.sh | 114 +++++ t/t5411/test-0050-proc-receive-refs.sh | 128 +++++ t/t5516-fetch-push.sh | 2 +- transport-helper.c | 128 +++-- transport.c | 159 ++++-- 48 files changed, 4320 insertions(+), 102 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/once-0010-report-status-v1.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-with-options.sh create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh create mode 100644 t/t5411/test-0050-proc-receive-refs.sh
Signature · 1 line
2.26.2.543.ge7de2a6e37
v19 cover New proc-receive hook for centralized workflow
From: Jiang Xin <[email protected]>
## Changes since v18
1. This series is based on "next" branch, in order to resolve a conflict with commit 95e7c38539 (refspec: make sure stack refspec_item variables are zeroed, 2020-08-14). See patch 9/10.
2. Fix typos in patch 3/10, 6/10, 7/10.
3. Fix ABNF syntax for capability "report-status-v2" in patch 6/10.
4. Add more test cases in patch 7/10 to increase code coverage.
## Range diff
1: 22a9252587 = 1: 96c6d41872 transport: not report a non-head push as a branch 2: 5c3fd7eb7a = 2: 861507a38e t5411: add basic test cases for proc-receive hook 3: 003a36b71f ! 3: 4b6d00a671 receive-pack: add new proc-receive hook
@@ Commit message
The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (run_proc_receive) on for the command. Commands with this filed
- turned on will be executed by a new handler (an hook named
+ turned on will be executed by a new handler (a hook named
"proc-receive") instead of the internal execute_commands function. We can use this "proc-receive" command to create pull requests or send emails for code review.
Suggested by Junio, this "proc-receive" hook reads the commands, push-options (optional), and send result using a protocol in pkt-line
- format. In the following example, The letter "S" stands for
+ format. In the following example, the letter "S" stands for
"receive-pack" and letter "H" stands for the hook.
# Version and features negotiation.
4: 60b9157a8e = 4: b3986f98eb receive-pack: feed report options to post-receive 5: 4a9b7187af ! 5: 882f391b4f New capability "report-status-v2" for git-push
@@ builtin/receive-pack.c: static void show_ref(const char *path, const struct obje
strbuf_addstr(&cap, " atomic");
if (prefer_ofs_delta)
@@ builtin/receive-pack.c: static struct command *read_head_info(struct packet_reader *reader,
- const char *feature_list = reader->line + linelen + 1;
+ int len = 0;
if (parse_feature_request(feature_list, "report-status"))
report_status = 1;
+ if (parse_feature_request(feature_list, "report-status-v2"))
6: 940acbc406 ! 6: 331bfd4697 doc: add document for capability report-status-v2
@@ Documentation/technical/pack-protocol.txt: update was successful, or 'ng [refnam
error-msg = 1*(OCTET) ; where not "ok"
----
-+New capability "report-status-v2" extends the protocol by adding new option ++The 'report-status-v2' capability extends the protocol by adding new option
+lines in order to support reporting of reference rewritten by the
-+"proc-receive" hook. The "proc-receive" hook may handle a command for a ++'proc-receive' hook. The 'proc-receive' hook may handle a command for a
+pseudo-reference which may create or update one or more references, and each +reference may have different name, different new-oid, and different old-oid. +
@@ Documentation/technical/pack-protocol.txt: update was successful, or 'ng [refnam
+ unpack-status = PKT-LINE("unpack" SP unpack-result)
+ unpack-result = "ok" / error-msg
+
-+ command-status-v2 = command-ok-v2 / command-fail-v2
++ command-status-v2 = command-ok-v2 / command-fail
+ command-ok-v2 = command-ok
+ *option-line
-+ command-fail-v2 = command-fail
-+ *option-line
+
+ command-ok = PKT-LINE("ok" SP refname)
+ command-fail = PKT-LINE("ng" SP refname SP error-msg)
@@ Documentation/technical/protocol-capabilities.txt: each reference was updated su
+----------------
+
+Capability 'report-status-v2' extends capability 'report-status' by
-+adding new option lines in order to support reference rewritten by -+the"proc-receive" hook. The "proc-receive" hook may handle a command ++adding new "option" directives in order to support reference rewritten by ++the "proc-receive" hook. The "proc-receive" hook may handle a command
+for a pseudo-reference which may create or update a reference with +different name, new-oid, and old-oid. While the capability
-+"report-status" cannot report for such case. See pack-protocol.txt ++'report-status' cannot report for such case. See pack-protocol.txt
+for details.
+
delete-refs
7: 974a06e15e ! 7: d5465fc22b receive-pack: new config receive.procReceiveRefs
@@ Commit message
"proc-receive".
Optional modifiers can be provided in the beginning of the value to
- filter commands for specific actions: create (a), mofify (m),
+ filter commands for specific actions: create (a), modify (m),
delete (d). A `!` can be included in the modifiers to negate the
reference prefix entry. E.g.:
git config --system --add receive.procReceiveRefs ad:refs/heads
+ git config --system --add receive.procReceiveRefs !:refs/heads
Signed-off-by: Jiang Xin <[email protected]>
@@ Documentation/config/receive.txt: receive.hideRefs::
+running the hook "proc-receive".
++
+Optional modifiers can be provided in the beginning of the value to filter
-+commands for specific actions: create (a), mofify (m), delete (d).
++commands for specific actions: create (a), modify (m), delete (d).
+A `!` can be included in the modifiers to negate the reference prefix entry.
+E.g.:
++
+ git config --system --add receive.procReceiveRefs ad:refs/heads
++ git config --system --add receive.procReceiveRefs !:refs/heads
+
receive.updateServerInfo::
If set to true, git-receive-pack will run git-update-server-info
@@ t/t5411/test-0041-process-all-refs--porcelain.sh (new)
+ )
+'
- ## t/t5411/test-0050-proc-receive-refs.sh (new) ##
+ ## t/t5411/test-0050-proc-receive-refs-with-modifiers.sh (new) ##
@@
+test_expect_success "config receive.procReceiveRefs with modifiers ($PROTOCOL)" '
+ (
@@ t/t5411/test-0050-proc-receive-refs.sh (new)
+# Refs of upstream : master(A)
+# Refs of workbench: master(A) tags/v123
+test_expect_success "setup upstream: create tags/v123 ($PROTOCOL)" '
++ git -C "$upstream" update-ref refs/heads/topic $A &&
+ git -C "$upstream" update-ref refs/tags/v123 $TAG &&
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/master
++ <COMMIT-A> refs/heads/topic
+ <TAG-v123> refs/tags/v123
+ EOF
+ test_cmp expect actual
@@ t/t5411/test-0050-proc-receive-refs.sh (new)
+ EOF
+'
+
-+# Refs of upstream : master(A) tags/v123
-+# Refs of workbench: master(A) tags/v123
-+# git push : NULL NULL next(A)
++# Refs of upstream : master(A) topic(A) tags/v123
++# Refs of workbench: master(A) tags/v123
++# git push : NULL topic(B) NULL next(A)
+test_expect_success "proc-receive: create/delete branch, and delete tag ($PROTOCOL)" '
+ git -C workbench push origin \
+ :refs/heads/master \
++ $B:refs/heads/topic \
+ $A:refs/heads/next \
+ :refs/tags/v123 >out 2>&1 &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ remote: # pre-receive hook
+ remote: pre-receive< <COMMIT-A> <ZERO-OID> refs/heads/master
++ remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/topic
+ remote: pre-receive< <TAG-v123> <ZERO-OID> refs/tags/v123
+ remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
+ remote: # proc-receive hook
@@ t/t5411/test-0050-proc-receive-refs.sh (new)
+ remote: proc-receive> option new-oid <COMMIT-A>
+ remote: # post-receive hook
+ remote: post-receive< <COMMIT-A> <ZERO-OID> refs/pull/123/head
++ remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/topic
+ remote: post-receive< <TAG-v123> <ZERO-OID> refs/tags/v123
+ remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/124/head
+ To <URL/of/upstream.git>
+ - [deleted] refs/pull/123/head
++ <OID-A>..<OID-B> <COMMIT-B> -> topic
+ - [deleted] v123
+ * [new reference] <COMMIT-A> -> refs/pull/124/head
+ EOF
@@ t/t5411/test-0050-proc-receive-refs.sh (new)
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/master
++ <COMMIT-B> refs/heads/topic
+ EOF
+ test_cmp expect actual
+'
8: 5b588f7926 = 8: cd38e2ddf5 t5411: test updates of remote-tracking branches
9: 7c707984e3 ! 9: 342784222f transport: parse report options for tracking refs
@@ transport.c: int transport_refs_pushed(struct ref *ref)
}
-void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
-+static void update_tracking_ref(struct remote *remote, char *refname,
-+ struct object_id *new_oid, int deletion,
-+ int verbose)
++static void update_one_tracking_ref(struct remote *remote, char *refname,
++ struct object_id *new_oid, int deletion,
++ int verbose)
{
struct refspec_item rs;
- if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
- return;
-
+ memset(&rs, 0, sizeof(rs));
- rs.src = ref->name;
+ rs.src = refname;
rs.dst = NULL;
--
+
if (!remote_find_tracking(remote, &rs)) {
if (verbose)
fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
@@ transport.c: int transport_refs_pushed(struct ref *ref)
delete_ref(NULL, rs.dst, NULL, 0);
- } else
- update_ref("update by push", rs.dst, &ref->new_oid,
-- NULL, 0, 0);
+ else
+ update_ref("update by push", rs.dst, new_oid,
-+ NULL, 0, 0);
+ NULL, 0, 0);
free(rs.dst);
}
}
@@ transport.c: int transport_refs_pushed(struct ref *ref)
+
+ report = ref->report;
+ if (!report)
-+ update_tracking_ref(remote, ref->name, &ref->new_oid,
-+ ref->deletion, verbose);
++ update_one_tracking_ref(remote, ref->name, &ref->new_oid,
++ ref->deletion, verbose);
+ else
+ for (; report; report = report->next) {
+ refname = report->ref_name ? (char *)report->ref_name : ref->name;
+ new_oid = report->new_oid ? report->new_oid : &ref->new_oid;
-+ update_tracking_ref(remote, refname, new_oid,
-+ is_null_oid(new_oid), verbose);
++ update_one_tracking_ref(remote, refname, new_oid,
++ is_null_oid(new_oid), verbose);
+ }
+}
+10: e66c7c3f51 ! 10: a7268305e3 doc: add documentation for the proc-receive hook
@@ Documentation/githooks.txt: The default 'update' hook, when enabled--and with
+ H: PKT-LINE(ok <ref>)
+ H: PKT-LINE(option fall-through)
+ # OK, but has an alternate reference. The alternate reference name
-+ # and other status can be given in options
++ # and other status can be given in option directives.
+ H: PKT-LINE(ok <ref>)
+ H: PKT-LINE(option refname <refname>)
+ H: PKT-LINE(option old-oid <old-oid>)
@@ Documentation/githooks.txt: The default 'update' hook, when enabled--and with
+may update an alternate reference and the alternate reference may exist +already with a non-zero old-oid. For this case, this hook will use +"option" directives to report extended attributes for the reference given
-+by the above "ok/ng" directive.
++by the leading "ok" directive.
+
+The report of the commands of this hook should have the same order as +the input. The exit status of the 'proc-receive' hook only determines
---
Jiang Xin (10):
transport: not report a non-head push as a branch
t5411: add basic test cases for proc-receive hook
receive-pack: add new proc-receive hook
receive-pack: feed report options to post-receive New capability "report-status-v2" for git-push
doc: add document for capability report-status-v2
receive-pack: new config receive.procReceiveRefs
t5411: test updates of remote-tracking branches
transport: parse report options for tracking refs
doc: add documentation for the proc-receive hook
Documentation/config/receive.txt | 22 + Documentation/githooks.txt | 62 +++ Documentation/technical/pack-protocol.txt | 41 +- .../technical/protocol-capabilities.txt | 17 +- Makefile | 1 + builtin/receive-pack.c | 472 +++++++++++++++++- builtin/send-pack.c | 19 + remote.h | 9 + send-pack.c | 101 +++- t/helper/test-proc-receive.c | 176 +++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411-proc-receive-hook.sh | 117 +++++ t/t5411/common-functions.sh | 56 +++ t/t5411/once-0010-report-status-v1.sh | 94 ++++ t/t5411/test-0000-standard-git-push.sh | 143 ++++++ .../test-0001-standard-git-push--porcelain.sh | 147 ++++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++ t/t5411/test-0010-proc-receive-settings.sh | 7 + t/t5411/test-0011-no-hook-error.sh | 64 +++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 +++ t/t5411/test-0013-bad-protocol.sh | 217 ++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++ t/t5411/test-0020-report-ng.sh | 67 +++ t/t5411/test-0021-report-ng--porcelain.sh | 69 +++ t/t5411/test-0022-report-unexpect-ref.sh | 45 ++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 ++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 ++ t/t5411/test-0026-push-options.sh | 79 +++ t/t5411/test-0027-push-options--porcelain.sh | 82 +++ t/t5411/test-0030-report-ok.sh | 35 ++ t/t5411/test-0031-report-ok--porcelain.sh | 36 ++ t/t5411/test-0032-report-with-options.sh | 256 ++++++++++ ...est-0033-report-with-options--porcelain.sh | 265 ++++++++++ t/t5411/test-0034-report-ft.sh | 44 ++ t/t5411/test-0035-report-ft--porcelain.sh | 45 ++ ...t-0036-report-multi-rewrite-for-one-ref.sh | 227 +++++++++ ...rt-multi-rewrite-for-one-ref--porcelain.sh | 172 +++++++ t/t5411/test-0038-report-mixed-refs.sh | 89 ++++ .../test-0039-report-mixed-refs--porcelain.sh | 91 ++++ t/t5411/test-0040-process-all-refs.sh | 113 +++++ .../test-0041-process-all-refs--porcelain.sh | 114 +++++ ...t-0050-proc-receive-refs-with-modifiers.sh | 135 +++++ t/t5516-fetch-push.sh | 2 +- transport-helper.c | 128 +++-- transport.c | 156 ++++-- 48 files changed, 4325 insertions(+), 100 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/once-0010-report-status-v1.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh create mode 100644 t/t5411/test-0010-proc-receive-settings.sh create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-with-options.sh create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh create mode 100644 t/t5411/test-0040-process-all-refs.sh create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh create mode 100644 t/t5411/test-0050-proc-receive-refs-with-modifiers.sh
Signature · 1 line
2.26.2.543.g44b58e439b
Re: [PATCH v19 00/10] New proc-receive hook for centralized workflow
Quoted 7 lines · Jiang Xin
From: Jiang Xin <[email protected]>
## Changes since v18
1. This series is based on "next" branch, in order to resolve a conflict with commit
95e7c38539(refspec: make sure stackrefspec_itemvariables are zeroed, 2020-08-14). See patch 9/10.
We cannot ever merge such a topic that depends on 'next' down to 'master' without dragging all the other topics that present in 'next', plus the merge commits that bring these topics to 'next'.
In this particular case, I think the conflict resolution is trivial and more importantly, it is not a *new* conflict v19 introduces but did not exist with v18. IOW, what is in 'seen' has already resolved the same conflict between 95e7c38539 and this topic.
I've applied these directly on 'next' (call it c0), rebased the result on the same base as v18 is queued on, and then merged the rebased v19 (call it c1) with 'next' to make sure that the result (call it c2) matches, i.e. tree of c0 and tree of c2 are identical.
I'll use c1 to replace what is queued in 'seen'.
A workable alternative would be to base these on top of the topic that contains 95e7c38539 (i.e. jk/refspecs-cleanup). Then, this topic is still taken hostage by that 'cleanup' topic, but at least as long as that topic graduates, this topic can graduate to 'master' without having to drag any other cruft with it.
Thanks.
PATCH v19 1/10 transport: not report a non-head push as a branch
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
When pushing a new reference (not a head or tag), report it as a new reference instead of a new branch.
--- t/t5516-fetch-push.sh | 2 +- transport.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
t/t5516-fetch-push.sh +1 -1
@@ -1039,7 +1039,7 @@ test_force_fetch_tag "annotated tag" "-f -a -m'tag message'" test_expect_success 'push --porcelain' ' mk_empty testrepo && echo >.git/foo "To testrepo" && - echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" && + echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new reference]" && echo >>.git/foo "Done" && git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && (
transport.c +6 -3
@@ -500,9 +500,12 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt porcelain, summary_width); else if (is_null_oid(&ref->old_oid))print_ref_status ('*' , - (starts_with (ref->name,"refs/tags/" ) ?"[new tag]" : -"[new branch]" ), - ref, ref->peer_ref,NULL , porcelain, summary_width); + (starts_with (ref->name,"refs/tags/" ) + ?"[new tag]" + : (starts_with (ref->name,"refs/heads/" ) + ?"[new branch]" + :"[new reference]" )), + ref, ref->peer_ref,NULL , porcelain, summary_width); else {struct strbuf quickref =STRBUF_INIT ;char type;
Signature · 1 line
2.26.2.543.g44b58e439b
PATCH v19 2/10 t5411: add basic test cases for proc-receive hook
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Topic "proc-receive-hook" will change the workflow and output of git-push. Add some basic test cases in t5411 before introducing the new topic.
--- t/t5411-proc-receive-hook.sh | 108 +++++++++++++ t/t5411/common-functions.sh | 56 +++++++ t/t5411/test-0000-standard-git-push.sh | 143 +++++++++++++++++ .../test-0001-standard-git-push--porcelain.sh | 147 ++++++++++++++++++ t/t5411/test-0002-pre-receive-declined.sh | 33 ++++ ...st-0003-pre-receive-declined--porcelain.sh | 34 ++++ 6 files changed, 521 insertions(+) create mode 100755 t/t5411-proc-receive-hook.sh create mode 100644 t/t5411/common-functions.sh create mode 100644 t/t5411/test-0000-standard-git-push.sh create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh create mode 100644 t/t5411/test-0002-pre-receive-declined.sh create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh
t/t5411-proc-receive-hook.sh new file +108 -0
@@ -0,0 +1,108 @@ +#!/bin/sh +# +# Copyright (c) 2020 Jiang Xin +# + +test_description='Test proc-receive hook' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/t5411/common-functions.sh + +setup_upstream_and_workbench () { + # Refs of upstream : master(A) + # Refs of workbench: master(A) tags/v123 + test_expect_success "setup upstream and workbench" ' + rm -rf upstream.git && + rm -rf workbench && + git init --bare upstream.git && + git init workbench && + create_commits_in workbench A B && + ( + cd workbench && + # Try to make a stable fixed width for abbreviated commit ID, + # this fixed-width oid will be replaced with "<OID>". + git config core.abbrev 7 && + git tag -m "v123" v123 $A && + git remote add origin ../upstream.git && + git push origin master && + git update-ref refs/heads/master $A $B && + git -C ../upstream.git update-ref \ + refs/heads/master $A $B + ) && + TAG=$(git -C workbench rev-parse v123) && + + # setup pre-receive hook + write_script upstream.git/hooks/pre-receive <<-\EOF && + exec >&2 + echo "# pre-receive hook" + while read old new ref + do + echo "pre-receive< $old $new $ref" + done + EOF + + # setup post-receive hook + write_script upstream.git/hooks/post-receive <<-\EOF && + exec >&2 + echo "# post-receive hook" + while read old new ref + do + echo "post-receive< $old $new $ref" + done + EOF + + upstream=upstream.git + ' +} + +run_proc_receive_hook_test() { + case $1 in + http) + PROTOCOL="HTTP protocol" + URL_PREFIX="http://.*" + ;; + local) + PROTOCOL="builtin protocol" + URL_PREFIX="\.\." + ;; + esac + + # Include test cases for both file and HTTP protocol + for t in "$TEST_DIRECTORY"/t5411/test-*.sh + do + . "$t" + done +} + +# Initialize the upstream repository and local workbench. +setup_upstream_and_workbench + +# Run test cases for 'proc-receive' hook on local file protocol. +run_proc_receive_hook_test local + +ROOT_PATH="$PWD" +. "$TEST_DIRECTORY"/lib-gpg.sh +. "$TEST_DIRECTORY"/lib-httpd.sh +. "$TEST_DIRECTORY"/lib-terminal.sh +start_httpd + +# Re-initialize the upstream repository and local workbench. +setup_upstream_and_workbench + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +test_expect_success "setup for HTTP protocol" ' + git -C upstream.git config http.receivepack true && + upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" && + mv upstream.git "$upstream" && + git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" && + set_askpass user@host pass@host +' + +setup_askpass_helper + +# Run test cases for 'proc-receive' hook on HTTP protocol. +run_proc_receive_hook_test http + +test_done
t/t5411/common-functions.sh new file +56 -0
56 lines not on this page · raw message
t/t5411/test-0000-standard-git-push.sh new file +143 -0
143 lines not on this page · raw message
t/t5411/test-0001-standard-git-push--porcelain.sh new file +147 -0
147 lines not on this page · raw message
t/t5411/test-0002-pre-receive-declined.sh new file +33 -0
@@ -0,0 +1,33 @@ +test_expect_success "setup pre-receive hook ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && + write_script "$upstream/hooks/pre-receive" <<-EOF + exit 1 + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git-push : master(B) next(A) +test_expect_success "git-push is declined ($PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + $B:refs/heads/master \ + HEAD:refs/heads/next \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] <COMMIT-B> -> master (pre-receive hook declined) + ! [remote rejected] HEAD -> next (pre-receive hook declined) + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +' + +test_expect_success "cleanup ($PROTOCOL)" ' + mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive" +'
t/t5411/test-0003-pre-receive-declined--porcelain.sh new file +34 -0
@@ -0,0 +1,34 @@ +test_expect_success "setup pre-receive hook ($PROTOCOL/porcelain)" ' + mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && + write_script "$upstream/hooks/pre-receive" <<-EOF + exit 1 + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git-push : master(B) next(A) +test_expect_success "git-push is declined ($PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + $B:refs/heads/master \ + HEAD:refs/heads/next \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! <COMMIT-B>:refs/heads/master [remote rejected] (pre-receive hook declined) + ! HEAD:refs/heads/next [remote rejected] (pre-receive hook declined) + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +' + +test_expect_success "cleanup ($PROTOCOL/porcelain)" ' + mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive" +'
Signature · 1 line
2.26.2.543.g44b58e439b
PATCH v19 3/10 receive-pack: add new proc-receive hook
In reply to Jiang XinFrom: Jiang Xin <[email protected]>
Git calls an internal execute_commands function to handle commands sent from client to git-receive-pack. Regardless of what references the user pushes, git creates or updates the corresponding references if the user has write-permission. A contributor who has no write-permission, cannot push to the repository directly. So, the contributor has to write commits to an alternate location, and sends pull request by emails or by other ways. We call this workflow as a distributed workflow.
It would be more convenient to work in a centralized workflow like what Gerrit provided for some cases. For example, a read-only user who cannot push to a branch directly can run the following git push command to push commits to a pseudo reference (has a prefix "refs/for/", not "refs/heads/") to create a code review.
git push origin \
HEAD:refs/for/<branch-name>/<session>The <branch-name> in the above example can be as simple as "master", or a more complicated branch name like "foo/bar". The <session> in the above example command can be the local branch name of the client side, such as "my/topic".
We cannot implement a centralized workflow elegantly by using "pre-receive" + "post-receive", because Git will call the internal function "execute_commands" to create references (even the special pseudo reference) between these two hooks. Even though we can delete the temporarily created pseudo reference via the "post-receive" hook, having a temporary reference is not safe for concurrent pushes.
So, add a filter and a new handler to support this kind of workflow. The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (run_proc_receive) on for the command. Commands with this filed turned on will be executed by a new handler (a hook named "proc-receive") instead of the internal execute_commands function. We can use this "proc-receive" command to create pull requests or send emails for code review.
Suggested by Junio, this "proc-receive" hook reads the commands, push-options (optional), and send result using a protocol in pkt-line format. In the following example, the letter "S" stands for "receive-pack" and letter "H" stands for the hook.
# Version and features negotiation.
S: PKT-LINE(version=1\0push-options atomic...)
S: flush-pkt
H: PKT-LINE(version=1\0push-options...)
H: flush-pkt
# Send commands from server to the hook.
S: PKT-LINE(<old-oid> <new-oid> <ref>)
S: ... ...
S: flush-pkt
# Send push-options only if the 'push-options' feature is enabled.
S: PKT-LINE(push-option)
S: ... ...
S: flush-pkt
# Receive result from the hook.
# OK, run this command successfully.
H: PKT-LINE(ok <ref>)
# NO, I reject it.
H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
H: PKT-LINE(ok <ref>)
H: PKT-LINE(option fall-through)
# OK, but has an alternate reference. The alternate reference name # and other status can be given in options
H: PKT-LINE(ok <ref>)
H: PKT-LINE(option refname <refname>)
H: PKT-LINE(option old-oid <old-oid>)
H: PKT-LINE(option new-oid <new-oid>)
H: PKT-LINE(option forced-update)
H: ... ...
H: flush-pkt
After receiving a command, the hook will execute the command, and may create/update different reference. For example, a command for a pseudo reference "refs/for/master/topic" may create/update different reference such as "refs/pull/123/head". The alternate reference name and other status are given in option lines.
The list of commands returned from "proc-receive" will replace the relevant commands that are sent from user to "receive-pack", and "receive-pack" will continue to run the "execute_commands" function and other routines. Finally, the result of the execution of these commands will be reported to end user.
The reporting function from "receive-pack" to "send-pack" will be extended in latter commit just like what the "proc-receive" hook reports to "receive-pack".
--- Makefile | 1 + builtin/receive-pack.c | 296 +++++++++++++++++- remote.h | 8 + t/helper/test-proc-receive.c | 176 +++++++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t5411/test-0011-no-hook-error.sh | 64 ++++ t/t5411/test-0012-no-hook-error--porcelain.sh | 66 ++++ t/t5411/test-0013-bad-protocol.sh | 217 +++++++++++++ t/t5411/test-0014-bad-protocol--porcelain.sh | 160 ++++++++++ t/t5411/test-0020-report-ng.sh | 67 ++++ t/t5411/test-0021-report-ng--porcelain.sh | 69 ++++ t/t5411/test-0022-report-unexpect-ref.sh | 45 +++ ...est-0023-report-unexpect-ref--porcelain.sh | 46 +++ t/t5411/test-0024-report-unknown-ref.sh | 34 ++ ...test-0025-report-unknown-ref--porcelain.sh | 35 +++ t/t5411/test-0026-push-options.sh | 79 +++++ t/t5411/test-0027-push-options--porcelain.sh | 82 +++++ t/t5411/test-0030-report-ok.sh | 35 +++ t/t5411/test-0031-report-ok--porcelain.sh | 36 +++ t/t5411/test-0032-report-with-options.sh | 256 +++++++++++++++ ...est-0033-report-with-options--porcelain.sh | 265 ++++++++++++++++ t/t5411/test-0034-report-ft.sh | 44 +++ t/t5411/test-0035-report-ft--porcelain.sh | 45 +++ ...t-0036-report-multi-rewrite-for-one-ref.sh | 159 ++++++++++ ...rt-multi-rewrite-for-one-ref--porcelain.sh | 162 ++++++++++ t/t5411/test-0038-report-mixed-refs.sh | 89 ++++++ .../test-0039-report-mixed-refs--porcelain.sh | 91 ++++++ 28 files changed, 2626 insertions(+), 3 deletions(-) create mode 100644 t/helper/test-proc-receive.c create mode 100644 t/t5411/test-0011-no-hook-error.sh create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh create mode 100644 t/t5411/test-0013-bad-protocol.sh create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh create mode 100644 t/t5411/test-0020-report-ng.sh create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh create mode 100644 t/t5411/test-0024-report-unknown-ref.sh create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh create mode 100644 t/t5411/test-0026-push-options.sh create mode 100644 t/t5411/test-0027-push-options--porcelain.sh create mode 100644 t/t5411/test-0030-report-ok.sh create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh create mode 100644 t/t5411/test-0032-report-with-options.sh create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh create mode 100644 t/t5411/test-0034-report-ft.sh create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh create mode 100644 t/t5411/test-0038-report-mixed-refs.sh create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh
Makefile +1 -0
@@ -719,6 +719,7 @@ TEST_BUILTINS_OBJS += test-parse-pathspec-file.o TEST_BUILTINS_OBJS += test-path-utils.o TEST_BUILTINS_OBJS += test-pkt-line.o TEST_BUILTINS_OBJS += test-prio-queue.o +TEST_BUILTINS_OBJS += test-proc-receive.o TEST_BUILTINS_OBJS += test-progress.o TEST_BUILTINS_OBJS += test-reach.o TEST_BUILTINS_OBJS += test-read-cache.o
builtin/receive-pack.c +293 -3
342 lines not on this page · raw message
remote.h +8 -0
@@ -93,6 +93,14 @@ int for_each_remote(each_remote_fn fn, void *priv);int remote_has_url (struct remote *remote,const char *url); +struct ref_push_report { +const char *ref_name; +struct object_id *old_oid; +struct object_id *new_oid; +unsigned int forced_update:1 ; +struct ref_push_report *next; +}; +struct ref {struct ref *next;struct object_id old_oid;
t/helper/test-proc-receive.c new file +176 -0
176 lines not on this page · raw message
t/helper/test-tool.c +1 -0
@@ -46,6 +46,7 @@ static struct test_cmd cmds[] = { { "path-utils", cmd__path_utils }, { "pkt-line", cmd__pkt_line }, { "prio-queue", cmd__prio_queue }, + { "proc-receive", cmd__proc_receive}, { "progress", cmd__progress }, { "reach", cmd__reach }, { "read-cache", cmd__read_cache },
t/helper/test-tool.h +1 -0
@@ -35,6 +35,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);int cmd__path_utils (int argc,const char **argv);int cmd__pkt_line (int argc,const char **argv);int cmd__prio_queue (int argc,const char **argv); +int cmd__proc_receive (int argc,const char **argv);int cmd__progress (int argc,const char **argv);int cmd__reach (int argc,const char **argv);int cmd__read_cache (int argc,const char **argv);
t/t5411/test-0011-no-hook-error.sh new file +64 -0
64 lines not on this page · raw message
t/t5411/test-0012-no-hook-error--porcelain.sh new file +66 -0
66 lines not on this page · raw message
t/t5411/test-0013-bad-protocol.sh new file +217 -0
217 lines not on this page · raw message
t/t5411/test-0014-bad-protocol--porcelain.sh new file +160 -0
160 lines not on this page · raw message
t/t5411/test-0020-report-ng.sh new file +67 -0
67 lines not on this page · raw message
t/t5411/test-0021-report-ng--porcelain.sh new file +69 -0
69 lines not on this page · raw message
t/t5411/test-0022-report-unexpect-ref.sh new file +45 -0
45 lines not on this page · raw message
t/t5411/test-0023-report-unexpect-ref--porcelain.sh new file +46 -0
46 lines not on this page · raw message
t/t5411/test-0024-report-unknown-ref.sh new file +34 -0
@@ -0,0 +1,34 @@ +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/a/b/c/my/topic +test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/a/b/c/my/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: proc-receive> ok refs/for/master/topic + remote: error: proc-receive reported status on unknown ref: refs/for/master/topic + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status) + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0025-report-unknown-ref--porcelain.sh new file +35 -0
@@ -0,0 +1,35 @@ +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/a/b/c/my/topic +test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/a/b/c/my/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic + remote: proc-receive> ok refs/for/master/topic + remote: error: proc-receive reported status on unknown ref: refs/for/master/topic + To <URL/of/upstream.git> + ! HEAD:refs/for/a/b/c/my/topic [remote rejected] (proc-receive failed to report status) + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0026-push-options.sh new file +79 -0
79 lines not on this page · raw message
t/t5411/test-0027-push-options--porcelain.sh new file +82 -0
82 lines not on this page · raw message
t/t5411/test-0030-report-ok.sh new file +35 -0
@@ -0,0 +1,35 @@ +test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/master/topic +test_expect_success "proc-receive: ok ($PROTOCOL)" ' + git -C workbench push origin \ + HEAD:refs/for/master/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: proc-receive> ok refs/for/master/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + To <URL/of/upstream.git> + * [new reference] HEAD -> refs/for/master/topic + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0031-report-ok--porcelain.sh new file +36 -0
@@ -0,0 +1,36 @@ +test_expect_success "setup proc-receive hook (ok, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/master/topic" + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/master/topic +test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" ' + git -C workbench push --porcelain origin \ + HEAD:refs/for/master/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + remote: proc-receive> ok refs/for/master/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic + To <URL/of/upstream.git> + * HEAD:refs/for/master/topic [new reference] + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
t/t5411/test-0032-report-with-options.sh new file +256 -0
256 lines not on this page · raw message
t/t5411/test-0033-report-with-options--porcelain.sh new file +265 -0
265 lines not on this page · raw message
t/t5411/test-0034-report-ft.sh new file +44 -0
44 lines not on this page · raw message
t/t5411/test-0035-report-ft--porcelain.sh new file +45 -0
45 lines not on this page · raw message
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh new file +159 -0
159 lines not on this page · raw message
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh new file +162 -0
162 lines not on this page · raw message
t/t5411/test-0038-report-mixed-refs.sh new file +89 -0
89 lines not on this page · raw message
t/t5411/test-0039-report-mixed-refs--porcelain.sh new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.26.2.543.g44b58e439b
Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook
Hi,
Quoted 15 lines · Jiang Xin
t/t5411/test-0013-bad-protocol.sh new file +15
-0+test_expect_success "setup proc-receive hook (hook --die-readline, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-readline + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/master/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/master/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual &&
t/t5411/test-0013-bad-protocol.sh line 103
Quoted 10 lines
t/t5411/test-0013-bad-protocol.sh new file +10
-0+ + grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/master/topic\"" actual && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'
While investigating a flaky hang in t5411 in the osx-clang job of our CI/PR builds, I ran into this issue (with --stress):
-- snip --
[...]
+++ test_must_fail git -C workbench push origin HEAD:refs/for/main/topic
+++ case "$1" in
+++ _test_ok=
+++ test_must_fail_acceptable git -C workbench push origin HEAD:refs/for/main/topic
+++ test git = env
+++ case "$1" in
+++ return 0
+++ git -C workbench push origin HEAD:refs/for/main/topic
+++ exit_code=128
+++ test 128 -eq 0
+++ test_match_signal 13 128
+++ test 128 = 141
+++ test 128 = 269
+++ return 1
+++ test 128 -gt 129
+++ test 128 -eq 127
+++ test 128 -eq 126
+++ return 0
+++ make_user_friendly_and_stable_output
++++ echo 4844d8acf2fc62b151a29cfb3b916b6778476b9e
++++ cut -c1-7
++++ echo c208c3bb8a1aeea6d4e40027a17251ccd59a2b1b
++++ cut -c1-7
+++ sed -e 's/ *$//' -e 's/ */ /g' -e 's/'\''/"/g' -e 's/ / /g' -e 's/4844d8acf2fc62b151a29cfb3b916b6778476b9e/<COMMIT-A>/g' -e 's/c208c3bb8a1aeea6d4e40027a17251ccd59a2b1b/<COMMIT-B>/g' -e 's/f7cc02ec1b3393b9a9638a0e02a7039c234cffa4/<TAG-v123>/g' -e 's/0000000000000000000000000000000000000000/<ZERO-OID>/g' -e 's/4844d8a[0-9a-f]*/<OID-A>/g' -e 's/c208c3b[0-9a-f]*/<OID-B>/g' -e 's#To \.\./upstream.git#To <URL/of/upstream.git>#' -e '/^error: / d'
+++ grep 'remote: fatal: protocol error: expected "old new ref", got "<ZERO-OID> <COMMIT-A> refs/for/main/topic"' actual
error: last command exited with $?=1
not ok 34 - proc-receive: bad protocol (hook --die-readline, builtin protocol)
#
# test_must_fail git -C workbench push origin \
# HEAD:refs/for/main/topic \
# >out 2>&1 &&
# make_user_friendly_and_stable_output <out >actual &&
#
# grep "remote: fatal: protocol error: expected \"old new # ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" # actual && # # git -C "$upstream" show-ref >out && # make_user_friendly_and_stable_output <out >actual && # cat >expect <<-EOF && # <COMMIT-A> refs/heads/main # EOF # test_cmp expect actual
#
-- snap --
The output of actual reads like this:
-- snip --
remote: # pre-receive hook
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
remote: # proc-receive hook
fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
-- snap --
Applying Gábor's patch as obtained from
https://lore.kernel.org/git/[email protected]/ seemed to help this issue at first, but then turned out not to prevent the same issue from happening again.
Any ideas?
Ciao,
Johannes
Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook
Me again,
Quoted 90 lines · Johannes Schindelin
Quoted 15 lines · Jiang Xin
t/t5411/test-0013-bad-protocol.sh new file +15
-0+test_expect_success "setup proc-receive hook (hook --die-readline, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-readline + EOF +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : refs/for/master/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/master/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual &&t/t5411/test-0013-bad-protocol.sh line 103
Quoted 10 lines
t/t5411/test-0013-bad-protocol.sh new file +10
-0+ + grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/master/topic\"" actual && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/master + EOF + test_cmp expect actual +'While investigating a flaky hang in t5411 in the osx-clang job of our CI/PR builds, I ran into this issue (with --stress):
-- snip --
[...]
+++test_must_failgit -C workbench push origin HEAD:refs/for/main/topic
+++ case "$1" in
+++ _test_ok=
+++test_must_fail_acceptablegit -C workbench push origin HEAD:refs/for/main/topic
+++ test git = env
+++ case "$1" in
+++ return 0
+++ git -C workbench push origin HEAD:refs/for/main/topic
+++ exit_code=128
+++ test 128 -eq 0
+++test_match_signal13 128
+++ test 128 = 141
+++ test 128 = 269
+++ return 1
+++ test 128 -gt 129
+++ test 128 -eq 127
+++ test 128 -eq 126
+++ return 0
+++make_user_friendly_and_stable_output
++++ echo4844d8acf2fc62b151a29cfb3b916b6778476b9e
++++ cut -c1-7
++++ echoc208c3bb8a1aeea6d4e40027a17251ccd59a2b1b
++++ cut -c1-7
+++ sed -e 's/ *$//' -e 's/ */ /g' -e 's/'\''/"/g' -e 's/ / /g' -e 's/4844d8acf2fc62b151a29cfb3b916b6778476b9e/<COMMIT-A>/g' -e 's/c208c3bb8a1aeea6d4e40027a17251ccd59a2b1b/<COMMIT-B>/g' -e 's/f7cc02ec1b3393b9a9638a0e02a7039c234cffa4/<TAG-v123>/g' -e 's/0000000000000000000000000000000000000000/<ZERO-OID>/g' -e 's/4844d8a[0-9a-f]*/<OID-A>/g' -e 's/c208c3b[0-9a-f]*/<OID-B>/g' -e 's#To \.\./upstream.git#To <URL/of/upstream.git>#' -e '/^error: / d'
+++ grep 'remote: fatal: protocol error: expected "old new ref", got "<ZERO-OID> <COMMIT-A> refs/for/main/topic"' actual
error: last command exited with $?=1
not ok 34 - proc-receive: bad protocol (hook --die-readline, builtin protocol)
#
#test_must_failgit -C workbench push origin \
# HEAD:refs/for/main/topic \
# >out 2>&1 &&
#make_user_friendly_and_stable_output<out >actual &&
## grep "remote: fatal: protocol error: expected \"old new # ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" # actual && # # git -C "$upstream" show-ref >out && # make_user_friendly_and_stable_output <out >actual && # cat >expect <<-EOF && # <COMMIT-A> refs/heads/main # EOF # test_cmp expect actual#
-- snap --The output of
actualreads like this:-- snip --
remote: # pre-receive hook
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
remote: # proc-receive hook
fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
-- snap --
Quoted 6 lines
Applying Gábor's patch as obtained from
https://lore.kernel.org/git/[email protected]/ seemed to help this issue at first, but then turned out not to prevent the same issue from happening again.Any ideas?
More puzzles. I was finally able to reproduce the hang in a --stress run. It basically happens in t5411.186, which is stalled at this:
-- snip --
[...]
expecting success of 5411.186 'proc-receive: bad protocol (hook --die-readline, HTTP protocol)':
test_must_fail git -C workbench push origin \
HEAD:refs/for/main/topic \
>out 2>&1 &&
make_user_friendly_and_stable_output <out >actual &&
grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" actual &&
git -C "$upstream" show-ref >out &&
make_user_friendly_and_stable_output <out >actual &&
cat >expect <<-EOF &&
<COMMIT-A> refs/heads/main
EOF
test_cmp expect actual+++ test_must_fail git -C workbench push origin HEAD:refs/for/main/topic +++ case "$1" in
+++ _test_ok=
+++ test_must_fail_acceptable git -C workbench push origin HEAD:refs/for/main/topic +++ test git = env
+++ case "$1" in
+++ return 0
+++ git -C workbench push origin HEAD:refs/for/main/topic
-- snap --
That push never goes anywhere. And I found something of a clue at trash directory.t5411-proc-receive-hook.stress-*/httpd/error.log:
-- snip --
[...]
[Wed Nov 04 22:28:20.838388 2020] [cgi:error] [pid 60577] [client 127.0.0.1:52794] AH01215: fatal: unable to write flush packet: Broken pipe: /Users/runner/work/git/git/git-http-backend
-- snap --
This is once again running _with_ Gábor's patch mentioned in the quoted part above.
Could you please look into this?
Ciao,
Johannes
Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook
In reply to Johannes SchindelinQuoted 22 lines · Johannes Schindelin <[email protected]> 于2020年11月5日周四 上午6:15写道:
not ok 34 - proc-receive: bad protocol (hook --die-readline, builtin protocol) #
#test_must_failgit -C workbench push origin \
# HEAD:refs/for/main/topic \
# >out 2>&1 &&
#make_user_friendly_and_stable_output<out >actual &&
## grep "remote: fatal: protocol error: expected \"old new # ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" # actual && # # git -C "$upstream" show-ref >out && # make_user_friendly_and_stable_output <out >actual && # cat >expect <<-EOF && # <COMMIT-A> refs/heads/main # EOF # test_cmp expect actual#
-- snap --The output of
actualreads like this:
Quoted 8 lines
-- snip --
remote: # pre-receive hook
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
remote: # proc-receive hook
fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
-- snap --
In this test case, the "proc-receive" hook sends an error message and dies earlier. While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but there is no such error message in output. It seems that the expected error message is overridden by the broken pipe error message. The broken pipe error is because "receive-pack" sends other commands to the "proc-receive" hook, but the hook dies earlier.
Quoted 4 lines
Applying Gábor's patch as obtained from
https://lore.kernel.org/git/[email protected]/ seemed to help this issue at first, but then turned out not to prevent the same issue from happening again.
I think this is the right way to fix this issue, even though I cannot reproduce this issue in my laptop.
1. In the run_proc_receive_hook() function of "receive-pack", should close the input (proc.in) before reading result from "proc-receive":
-- snip --
@@ -1196,11 +1197,12 @@ static int run_proc_receive_hook(struct command *commands,
packet_flush(proc.in);
}+ close(proc.in);
+
/* Read result from proc-receive */
code = read_proc_receive_report(&reader, commands, &errmsg);cleanup:
- close(proc.in);
close(proc.out);
if (use_sideband)
finish_async(&muxer);-- snap --
2. test helper for proc-receive should consume the input stream before die earlier:
-- snip --
@@ -79,9 +79,11 @@ static void proc_receive_read_commands(struct packet_reader *reader,
*p++ != ' ' ||
parse_oid_hex(p, &new_oid, &p) ||
*p++ != ' ' ||- die_readline)
+ die_readline) {
+ while (packet_reader_read(reader) != PACKET_READ_EOF);
die("protocol error: expected 'old new ref', got '%s'",
- reader->line);
+ die_readline? "<call with
--die-readline>": reader->line);
+ }
refname = p;
FLEX_ALLOC_STR(cmd, ref_name, refname);
oidcpy(&cmd->old_oid, &old_oid);
@@ -136,7 +138,7 @@ int cmd__proc_receive(int argc, const char **argv)
usage_msg_opt("Too many arguments.",
proc_receive_usage, options);
packet_reader_init(&reader, 0, NULL, 0,
PACKET_READ_CHOMP_NEWLINE |- PACKET_READ_DIE_ON_ERR_PACKET);
+ PACKET_READ_GENTLE_ON_EOF);
sigchain_push(SIGPIPE, SIG_IGN);
proc_receive_verison(&reader);-- snap --
I will send a standalone patch using git-send-email command line later.
--
Jiang Xin
RFC PATCH 1/1 t5411: fix broken pipe write error on proc-receive
From: Jiang Xin <[email protected]>
Johannes found a flaky hang in t5411 in the osx-clang job of the CI/PR builds, and ran into this issue using --stress option with the following errror messages:
fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
In this test case, the "proc-receive" hook sends an error message and dies earlier. While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but there is no such error message in output. It seems that the expected error message is overridden by the broken pipe error message. The broken pipe error is because "receive-pack" sends other commands to the "proc-receive" hook, but the hook dies earlier.
To fix this issue, these changes are made:
1. In "receive-pack", close the input stream for the "proc-receive" hook before reading result from "proc-receive".
2. The test helper for "proc-receive" consumes the input stream before it die earlier.
--- builtin/receive-pack.c | 4 +++- t/helper/test-proc-receive.c | 8 +++++--- t/t5411/test-0013-bad-protocol.sh | 3 +-- 3 files changed, 9 insertions(+), 6 deletions(-)
builtin/receive-pack.c +3 -1
@@ -1172,6 +1172,7 @@ static int run_proc_receive_hook(struct command *commands,if (version !=1 ) {strbuf_addf (&errmsg,"proc-receive version '%d' is not supported" , version); +close (proc.in); code =-1 ; goto cleanup; }
@@ -1196,11 +1197,12 @@ static int run_proc_receive_hook(struct command *commands,packet_flush (proc.in); } +close (proc.in); +/* Read result from proc-receive */ code =read_proc_receive_report (&reader, commands, &errmsg); cleanup: -close (proc.in);close (proc.out);if (use_sideband)finish_async (&muxer);
t/helper/test-proc-receive.c +5 -3
@@ -79,9 +79,11 @@ static void proc_receive_read_commands(struct packet_reader *reader, *p++ !=' ' ||parse_oid_hex (p, &new_oid, &p) || *p++ !=' ' || - die_readline) + die_readline) { + while (packet_reader_read(reader) != PACKET_READ_EOF);die ("protocol error: expected 'old new ref', got '%s'" , - reader->line); + die_readline?"<call with --die-readline>" : reader->line); + } refname = p;FLEX_ALLOC_STR (cmd, ref_name, refname);oidcpy (&cmd->old_oid, &old_oid);
@@ -136,7 +138,7 @@ int cmd__proc_receive(int argc, const char **argv)usage_msg_opt ("Too many arguments." , proc_receive_usage, options);packet_reader_init (&reader,0 ,NULL ,0 ,PACKET_READ_CHOMP_NEWLINE | -PACKET_READ_DIE_ON_ERR_PACKET ); +PACKET_READ_GENTLE_ON_EOF );sigchain_push (SIGPIPE ,SIG_IGN );proc_receive_verison (&reader);
t/t5411/test-0013-bad-protocol.sh +1 -2
@@ -91,8 +91,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL) HEAD:refs/for/master/topic \ >out 2>&1 && make_user_friendly_and_stable_output <out >actual && - - grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/master/topic\"" actual && + grep "remote: fatal: protocol error: expected \"old new ref\", got \"<call with --die-readline>\"" actual && git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual &&
Signature · 1 line
2.29.0.dirty
Re: [RFC PATCH] t5411: fix broken pipe write error on proc-receive
Quoted 5 lines · Jiang Xin
From: Jiang Xin <[email protected]>
Johannes found a flaky hang in t5411 in the osx-clang job of the CI/PR builds, and ran into this issue using
--stressoption with the following errror messages:
s/errror/error/;
Quoted 6 lines
fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedlyIn this test case, the "proc-receive" hook sends an error message and dies earlier. While "receive-pack" on the other side of the pipe
Micronit. "dies first" may be easier to read.
Quoted 5 lines
should forward the error message of the "proc-receive" hook to the client side, but there is no such error message in output. It seems that the expected error message is overridden by the broken pipe error message. The broken pipe error is because "receive-pack" sends other commands to the "proc-receive" hook, but the hook dies earlier.
The way the exchange designed to happen in a successfull case is that receive-pack process feeds the commands over the pipe, and after feeding all commands start reading response? Even if the hooks were forbidden from (1) disconnect before reading the commands and/or (2) speaking before receive-pack finishes feeding the commands, since they are end-user-supplied random scripts, receive-pack needs to be prepared to deal with misbehaving hooks.
Quoted 4 lines
To fix this issue, these changes are made:
1. In "receive-pack", close the input stream for the "proc-receive" hook before reading result from "proc-receive".
This is necessary because...? Until/unless we close our end, the hook would not know we finished talking to them, so it is a good discipline to close our end of the pipe, but it is unclear to me how this causes the broken pipe failure, i.e. write by receive-pack into a pipe connected to the hook that has already died.
Quoted 2 lines
2. The test helper for "proc-receive" consumes the input stream before it die earlier.
"before it dies."
This is merely a workaround in the hook used for testing. End-user hook that misbehaves can still disconnect without reading anything, and receive-pack needs to be prepared for such a case, no?
Is it irrelevant because this is only about forcing a flakey test that fails in two different ways to fail in a predictable way?
Thanks.
Quoted 39 lines
Reported-by Johannes Schindelin <[email protected]>Signed-off-by Jiang Xin <[email protected]>--- builtin/receive-pack.c | 4 +++- t/helper/test-proc-receive.c | 8 +++++--- t/t5411/test-0013-bad-protocol.sh | 3 +-- 3 files changed, 9 insertions(+), 6 deletions(-)builtin/receive-pack.c +3
-1@@ -1172,6 +1172,7 @@ static int run_proc_receive_hook(struct command *commands,if (version !=1 ) {strbuf_addf (&errmsg,"proc-receive version '%d' is not supported" , version); +close (proc.in); code =-1 ; goto cleanup; }@@ -1196,11 +1197,12 @@ static int run_proc_receive_hook(struct command *commands,packet_flush (proc.in); } +close (proc.in); +/* Read result from proc-receive */ code =read_proc_receive_report (&reader, commands, &errmsg); cleanup: -close (proc.in);close (proc.out);if (use_sideband)finish_async (&muxer);t/helper/test-proc-receive.c +0
-0
t/helper/test-proc-receive.c static void proc_receive_read_commands(struct packet_reader *reader, · line 83
Quoted 6 lines
t/helper/test-proc-receive.c +2
-1@@ -79,9 +79,11 @@ static void proc_receive_read_commands(struct packet_reader *reader, *p++ != ' ' || parse_oid_hex(p, &new_oid, &p) || *p++ != ' ' || - die_readline) + die_readline) { +while (packet_reader_read (reader) !=PACKET_READ_EOF );
Have the empty statement on its own line, i.e.
while (condition) ; /* do nothing */
t/helper/test-proc-receive.c static void proc_receive_read_commands(struct packet_reader *reader, · line 85
Quoted 3 lines
t/helper/test-proc-receive.c +1
-1die ("protocol error: expected 'old new ref', got '%s'" , - reader->line); + die_readline?"<call with --die-readline>" : reader->line);
SP around both sides of "?" and ":", and if that makes the line too long, consider wrapping the line, i.e.
die_readline ? "<call with --die-readline>" : reader->line);
Quoted 27 lines
t/helper/test-proc-receive.c +2
-1+ } refname = p;FLEX_ALLOC_STR (cmd, ref_name, refname);oidcpy (&cmd->old_oid, &old_oid);@@ -136,7 +138,7 @@ int cmd__proc_receive(int argc, const char **argv)usage_msg_opt ("Too many arguments." , proc_receive_usage, options);packet_reader_init (&reader,0 ,NULL ,0 ,PACKET_READ_CHOMP_NEWLINE | -PACKET_READ_DIE_ON_ERR_PACKET ); +PACKET_READ_GENTLE_ON_EOF );sigchain_push (SIGPIPE ,SIG_IGN );proc_receive_verison (&reader);t/t5411/test-0013-bad-protocol.sh +1
-2@@ -91,8 +91,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL) HEAD:refs/for/master/topic \ >out 2>&1 && make_user_friendly_and_stable_output <out >actual && - - grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/master/topic\"" actual && + grep "remote: fatal: protocol error: expected \"old new ref\", got \"<call with --die-readline>\"" actual && git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual &&
PATCH 1/1 t5411: consistent result for proc-receive broken test
From: Jiang Xin <[email protected]>
Johannes found a flaky hang in t5411/test-0013-bad-protocol.sh in the osx-clang job of the CI/PR builds, and ran into an issue when using the --stress option with the following error messages:
fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
In this test case, the "proc-receive" hook sends an error message and dies earlier. While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but it fails to do so. Perhaps it depends on the size of the pipe buffer and timing of the processes getting scheduled.
The way the exchange designed to happen in a successful case is that "receive-pack" process feeds the commands, and optional push options over the pipe, and after feeding all these information, "receive-pack" starts reading the response of "proc-receive". Let "receive-pack" close the input stream to "proc-receive" right before reading the response, so that "proc-receive" may consume all the input from "receive-pack" before sending an error message and closing the pipe.
The "proc-receive" hook may close the pipe at any time. Three options (--die-version, --die-readline, and --die-report) can be used for the test helper to simulate different broken cases. In order to keep the test results consistent under stress test, only status reports are matched.
--- builtin/receive-pack.c | 4 ++- t/helper/test-proc-receive.c | 20 +++++++++--- t/t5411/test-0013-bad-protocol.sh | 53 +++++++++++++++++++++++++------ 3 files changed, 63 insertions(+), 14 deletions(-)
builtin/receive-pack.c +3 -1
@@ -1172,6 +1172,7 @@ static int run_proc_receive_hook(struct command *commands,if (version !=1 ) {strbuf_addf (&errmsg,"proc-receive version '%d' is not supported" , version); +close (proc.in); code =-1 ; goto cleanup; }
@@ -1196,11 +1197,12 @@ static int run_proc_receive_hook(struct command *commands,packet_flush (proc.in); } +close (proc.in); +/* Read result from proc-receive */ code =read_proc_receive_report (&reader, commands, &errmsg); cleanup: -close (proc.in);close (proc.out);if (use_sideband)finish_async (&muxer);
t/helper/test-proc-receive.c +16 -4
@@ -12,6 +12,7 @@ static const char *proc_receive_usage[] = {static int die_version;static int die_readline; +static int die_report;static int no_push_options;static int use_atomic;static int use_push_options;
@@ -52,8 +53,10 @@ static void proc_receive_verison(struct packet_reader *reader) { } } -if (server_version !=1 || die_version) +if (server_version !=1 )die ("bad protocol version: %d" , server_version); +if (die_version) +die ("die with the --die-version option" ); packet_write_fmt(1, "version=%d%c%s\n", version, '\0',
@@ -75,13 +78,18 @@ static void proc_receive_read_commands(struct packet_reader *reader,if (packet_reader_read (reader) !=PACKET_READ_NORMAL )break ; +if (die_readline) +die ("die with the --die-readline option" ); +if (parse_oid_hex (reader->line, &old_oid, &p) || *p++ !=' ' ||parse_oid_hex (p, &new_oid, &p) || - *p++ !=' ' || - die_readline) + *p++ !=' ' ) { +while (packet_reader_read (reader) !=PACKET_READ_EOF ) + ;/* do nothing */ die ("protocol error: expected 'old new ref', got '%s'" , reader->line); + } refname = p;FLEX_ALLOC_STR (cmd, ref_name, refname);oidcpy (&cmd->old_oid, &old_oid);
@@ -121,6 +129,8 @@ int cmd__proc_receive(int argc, const char **argv) "die during version negotiation"),OPT_BOOL (0 ,"die-readline" , &die_readline,"die when readline" ), +OPT_BOOL (0 ,"die-report" , &die_report, +"die when reporting" ),OPT_STRING_LIST ('r' ,"return" , &returns,"old/new/ref/status/msg" ,"return of results" ), OPT__VERBOSE(&verbose, "be verbose"),
@@ -136,7 +146,7 @@ int cmd__proc_receive(int argc, const char **argv)usage_msg_opt ("Too many arguments." , proc_receive_usage, options);packet_reader_init (&reader,0 ,NULL ,0 ,PACKET_READ_CHOMP_NEWLINE | -PACKET_READ_DIE_ON_ERR_PACKET ); +PACKET_READ_GENTLE_ON_EOF );sigchain_push (SIGPIPE ,SIG_IGN );proc_receive_verison (&reader);
@@ -166,6 +176,8 @@ int cmd__proc_receive(int argc, const char **argv)fprintf (stderr,"proc-receive> %s\n" , item->string); } +if (die_report) +die ("die with the --die-report option" );if (returns.nr)for_each_string_list_item (item, &returns)packet_write_fmt (1 ,"%s\n" , item->string);
t/t5411/test-0013-bad-protocol.sh +44 -9
73 lines not on this page · raw message
Signature · 1 line
2.29.0.dirty
Re: [PATCH] t5411: consistent result for proc-receive broken test
Quoted 11 lines · Jiang Xin <[email protected]> 于2020年11月7日周六 上午10:57写道:
(quoted diff) +3
-1@@ -75,13 +78,18 @@ static void proc_receive_read_commands(struct packet_reader *reader, if (packet_reader_read(reader) != PACKET_READ_NORMAL) break; + if (die_readline) + die("die with the --die-readline option"); + if (parse_oid_hex(reader->line, &old_oid, &p) || *p++ != ' ' || parse_oid_hex(p, &new_oid, &p) || - *p++ != ' ' ||
Review static void proc_receive_read_commands(struct packet_reader *reader, · line 95
Quoted 10 lines
(quoted diff) +4
-1- die_readline) + *p++ != ' ') { + while (packet_reader_read(reader) != PACKET_READ_EOF) + ; /* do nothing */ die("protocol error: expected 'old new ref', got '%s'", reader->line); + } refname = p; FLEX_ALLOC_STR(cmd, ref_name, refname); oidcpy(&cmd->old_oid, &old_oid);
Still have problems under the stress test. Today I figured out how to run stress test by setting proper environment variable GIT_TEST_STRESS_LOAD without consuming too many resources and leading to random strange errors. E.g.:
$ GIT_TEST_STRESS_LOAD=11 sh t5411-proc-receive-hook.sh -v --stress
Will send patch v2 later with the following changes:
-- snip --
t/helper/test-proc-receive.c +0 -0
@@ -78,17 +78,18 @@ static void proc_receive_read_commands(struct
packet_reader *reader,
if (packet_reader_read(reader) != PACKET_READ_NORMAL)
break;- if (die_readline)
- die("die with the --die-readline option");
-
if (parse_oid_hex(reader->line, &old_oid, &p) ||
*p++ != ' ' ||
parse_oid_hex(p, &new_oid, &p) ||
- *p++ != ' ') {
+ *p++ != ' ' ||
+ die_readline) {
+ char *bad_line = xstrdup(reader->line);
while (packet_reader_read(reader) != PACKET_READ_EOF)
; /* do nothing */+ if (die_readline)
+ die("die with the --die-readline option");
die("protocol error: expected 'old new ref', got '%s'",
- reader->line);
+ bad_line);
}
refname = p;
FLEX_ALLOC_STR(cmd, ref_name, refname);-- snap --
PATCH v2 1/1 t5411: consistent result for proc-receive broken test
Johannes found a flaky hang in t5411/test-0013-bad-protocol.sh in the osx-clang job of the CI/PR builds, and ran into an issue when using the --stress option with the following error messages:
fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
In this test case, the "proc-receive" hook sends an error message and dies earlier. While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but it fails to do so. Perhaps it depends on the size of the pipe buffer and timing of the processes getting scheduled.
The way the exchange designed to happen in a successful case is that "receive-pack" process feeds the commands, and optional push options over the pipe, and after feeding all these information, "receive-pack" starts reading the response of "proc-receive". Let "receive-pack" close the input stream to "proc-receive" right before reading the response, so that "proc-receive" may consume all the input from "receive-pack" before sending an error message and closing the pipe.
The "proc-receive" hook may close the pipe at any time. Three options (--die-version, --die-readline, and --die-report) can be used for the test helper to simulate different broken cases. In order to keep the test results consistent under stress test, only status reports are matched.
--- builtin/receive-pack.c | 4 +- t/helper/test-proc-receive.c | 21 ++++- t/t5411/test-0013-bad-protocol.sh | 53 +++++++++-- t/t5411/test-0014-bad-protocol--porcelain.sh | 96 ++++++++++++++++++++ 4 files changed, 160 insertions(+), 14 deletions(-)
builtin/receive-pack.c +3 -1
@@ -1172,6 +1172,7 @@ static int run_proc_receive_hook(struct command *commands,if (version !=1 ) {strbuf_addf (&errmsg,"proc-receive version '%d' is not supported" , version); +close (proc.in); code =-1 ; goto cleanup; }
@@ -1196,11 +1197,12 @@ static int run_proc_receive_hook(struct command *commands,packet_flush (proc.in); } +close (proc.in); +/* Read result from proc-receive */ code =read_proc_receive_report (&reader, commands, &errmsg); cleanup: -close (proc.in);close (proc.out);if (use_sideband)finish_async (&muxer);
t/helper/test-proc-receive.c +17 -4
@@ -12,6 +12,7 @@ static const char *proc_receive_usage[] = {static int die_version;static int die_readline; +static int die_report;static int no_push_options;static int use_atomic;static int use_push_options;
@@ -52,8 +53,10 @@ static void proc_receive_verison(struct packet_reader *reader) { } } -if (server_version !=1 || die_version) +if (server_version !=1 )die ("bad protocol version: %d" , server_version); +if (die_version) +die ("die with the --die-version option" ); packet_write_fmt(1, "version=%d%c%s\n", version, '\0',
@@ -79,9 +82,15 @@ static void proc_receive_read_commands(struct packet_reader *reader, *p++ !=' ' ||parse_oid_hex (p, &new_oid, &p) || *p++ !=' ' || - die_readline) + die_readline) { + char *bad_line = xstrdup(reader->line); +while (packet_reader_read (reader) !=PACKET_READ_EOF ) + ;/* do nothing */ +if (die_readline) +die ("die with the --die-readline option" );die ("protocol error: expected 'old new ref', got '%s'" , - reader->line); + bad_line); + } refname = p;FLEX_ALLOC_STR (cmd, ref_name, refname);oidcpy (&cmd->old_oid, &old_oid);
@@ -121,6 +130,8 @@ int cmd__proc_receive(int argc, const char **argv) "die during version negotiation"),OPT_BOOL (0 ,"die-readline" , &die_readline,"die when readline" ), +OPT_BOOL (0 ,"die-report" , &die_report, +"die when reporting" ),OPT_STRING_LIST ('r' ,"return" , &returns,"old/new/ref/status/msg" ,"return of results" ), OPT__VERBOSE(&verbose, "be verbose"),
@@ -136,7 +147,7 @@ int cmd__proc_receive(int argc, const char **argv)usage_msg_opt ("Too many arguments." , proc_receive_usage, options);packet_reader_init (&reader,0 ,NULL ,0 ,PACKET_READ_CHOMP_NEWLINE | -PACKET_READ_DIE_ON_ERR_PACKET ); +PACKET_READ_GENTLE_ON_EOF );sigchain_push (SIGPIPE ,SIG_IGN );proc_receive_verison (&reader);
@@ -166,6 +177,8 @@ int cmd__proc_receive(int argc, const char **argv)fprintf (stderr,"proc-receive> %s\n" , item->string); } +if (die_report) +die ("die with the --die-report option" );if (returns.nr)for_each_string_list_item (item, &returns)packet_write_fmt (1 ,"%s\n" , item->string);
t/t5411/test-0013-bad-protocol.sh +44 -9
73 lines not on this page · raw message
t/t5411/test-0014-bad-protocol--porcelain.sh +96 -0
102 lines not on this page · raw message
Signature · 1 line
2.29.0.dirty
Re: [PATCH v2] t5411: consistent result for proc-receive broken test
Quoted 16 lines · Jiang Xin
builtin/receive-pack.c +1
-0@@ -1172,6 +1172,7 @@ static int run_proc_receive_hook(struct command *commands,if (version !=1 ) {strbuf_addf (&errmsg,"proc-receive version '%d' is not supported" , version); +close (proc.in); code =-1 ; goto cleanup; }@@ -1196,11 +1197,12 @@ static int run_proc_receive_hook(struct command *commands,packet_flush (proc.in); }
builtin/receive-pack.c static int run_proc_receive_hook(struct command *commands, · line 1208
Quoted 10 lines
builtin/receive-pack.c +2
-1+close (proc.in); +/* Read result from proc-receive */ code =read_proc_receive_report (&reader, commands, &errmsg); cleanup: -close (proc.in);close (proc.out);if (use_sideband)finish_async (&muxer);
OK, without us closing our end, the hook cannot even tell that it read to the end of our input.
Quoted 13 lines
t/helper/test-proc-receive.c +1
-0@@ -12,6 +12,7 @@ static const char *proc_receive_usage[] = {static int die_version;static int die_readline; +static int die_report;static int no_push_options;static int use_atomic;static int use_push_options;
t/helper/test-proc-receive.c static void proc_receive_verison(struct packet_reader *reader) { · line 59
Quoted 8 lines
t/helper/test-proc-receive.c +3
-1@@ -52,8 +53,10 @@ static void proc_receive_verison(struct packet_reader *reader) { } } -if (server_version !=1 || die_version) +if (server_version !=1 )die ("bad protocol version: %d" , server_version); +if (die_version) +die ("die with the --die-version option" );
If any of these trigger, wouldn't we end up dying without consuming what receive-pack said?
Quoted 8 lines
t/helper/test-proc-receive.c +0
-1packet_write_fmt(1, "version=%d%c%s\n", version, '\0',@@ -79,9 +82,15 @@ static void proc_receive_read_commands(struct packet_reader *reader, *p++ !=' ' ||parse_oid_hex (p, &new_oid, &p) || *p++ != ' ' || - die_readline)
t/helper/test-proc-receive.c static void proc_receive_read_commands(struct packet_reader *reader, · line 93
Quoted 10 lines
t/helper/test-proc-receive.c +8
-1+ die_readline) { +char *bad_line =xstrdup (reader->line); +while (packet_reader_read (reader) !=PACKET_READ_EOF ) + ;/* do nothing */ +if (die_readline) +die ("die with the --die-readline option" );die ("protocol error: expected 'old new ref', got '%s'" , - reader->line); + bad_line); + }
This part is different from the previous one in that it slurps all the input before dying evein in die_readline case.
t/helper/test-proc-receive.c int cmd__proc_receive(int argc, const char **argv) · line 181
Quoted 6 lines
t/helper/test-proc-receive.c +2
-0@@ -166,6 +177,8 @@ int cmd__proc_receive(int argc, const char **argv)fprintf (stderr,"proc-receive> %s\n" , item->string); } +if (die_report) +die ("die with the --die-report option" );
And at this point we have already read everything the other end said (if so, there is no need for the artificial "read everything before we die")?
t/t5411/test-0013-bad-protocol.sh test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" · line 57
Quoted 8 lines
t/t5411/test-0013-bad-protocol.sh +0
-0@@ -55,19 +55,16 @@ test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" test_must_fail git -C workbench push origin \ HEAD:refs/for/master/topic \ >out 2>&1 &&
Are these expected to conflict with Dscho's changes to move 'master' around?
t/t5411/test-0013-bad-protocol.sh test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" · line 62
Quoted 7 lines
t/t5411/test-0013-bad-protocol.sh +5
-2- make_user_friendly_and_stable_output <out >actual && - + make_user_friendly_and_stable_output <out | + sed -n \ + -e "/^To / { s/ */ /g; p; }" \ + -e "/^ ! / { s/ */ /g; p; }" \ + >actual &&
It's the same thing but I somehow find "s/ */ /g" easier to read. The comparison is between "there may be two things or more---squish them down to one" and "After one thing, there may be any number of things---remove all the extra ones".
Makes me wonder if make_user_friendly should optionally have an option to do something like this for us. I doubt it that it is worth to do something like the attached patch.
t/t5411/common-functions.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
t/t5411/common-functions.sh +5 -2
@@ -40,7 +40,9 @@ create_commits_in () { # `GIT_TEST_GETTEXT_POISON=true` in order to test unintentional translations # on plumbing commands. make_user_friendly_and_stable_output () { - sed \ + local en= + case "$#" in 0) ;; *) en=-n ;; esac + sed $en \ -e "s/ *\$//" \ -e "s/ */ /g" \ -e "s/'/\"/g" \
@@ -52,5 +54,6 @@ make_user_friendly_and_stable_output () { -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \ -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \ -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \ - -e "/^error: / d" + -e "/^error: / d" \ + ${1+"$@"} }