@matheusbsbs / matheus-bagliano / commits / 15d3af5e22
Fork 0

receive-pack: add new proc-receive hook

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". Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jiang Xin committed Aug 27, 2020 at 11:45 UTC 15d3af5e22eceb9cd6cd341703d612a62194451e
28 files changed +2626 -3
Makefile
+1
@@ -722,6 +722,7 @@ TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
722 TEST_BUILTINS_OBJS += test-path-utils.o
723 TEST_BUILTINS_OBJS += test-pkt-line.o
724 TEST_BUILTINS_OBJS += test-prio-queue.o
725 +TEST_BUILTINS_OBJS += test-proc-receive.o
726 TEST_BUILTINS_OBJS += test-progress.o
727 TEST_BUILTINS_OBJS += test-reach.o
728 TEST_BUILTINS_OBJS += test-read-cache.o
builtin/receive-pack.c
+293 -3
@@ -308,11 +308,15 @@ static void write_head_info(void)
308 packet_flush(1);
309 }
310
311 +#define RUN_PROC_RECEIVE_SCHEDULED 1
312 +#define RUN_PROC_RECEIVE_RETURNED 2
313 struct command {
314 struct command *next;
315 const char *error_string;
316 + struct ref_push_report *report;
317 unsigned int skip_update:1,
315 - did_not_exist:1;
318 + did_not_exist:1,
319 + run_proc_receive:2;
320 int index;
321 struct object_id old_oid;
322 struct object_id new_oid;
@@ -838,6 +842,268 @@ static int run_update_hook(struct command *cmd)
842 return finish_command(&proc);
843 }
844
845 +static struct command *find_command_by_refname(struct command *list,
846 + const char *refname)
847 +{
848 + for (; list; list = list->next)
849 + if (!strcmp(list->ref_name, refname))
850 + return list;
851 + return NULL;
852 +}
853 +
854 +static int read_proc_receive_report(struct packet_reader *reader,
855 + struct command *commands,
856 + struct strbuf *errmsg)
857 +{
858 + struct command *cmd;
859 + struct command *hint = NULL;
860 + struct ref_push_report *report = NULL;
861 + int new_report = 0;
862 + int code = 0;
863 + int once = 0;
864 +
865 + for (;;) {
866 + struct object_id old_oid, new_oid;
867 + const char *head;
868 + const char *refname;
869 + char *p;
870 +
871 + if (packet_reader_read(reader) != PACKET_READ_NORMAL)
872 + break;
873 +
874 + head = reader->line;
875 + p = strchr(head, ' ');
876 + if (!p) {
877 + strbuf_addf(errmsg, "proc-receive reported incomplete status line: '%s'\n", head);
878 + code = -1;
879 + continue;
880 + }
881 + *p++ = '\0';
882 + if (!strcmp(head, "option")) {
883 + const char *key, *val;
884 +
885 + if (!hint || !(report || new_report)) {
886 + if (!once++)
887 + strbuf_addstr(errmsg, "proc-receive reported 'option' without a matching 'ok/ng' directive\n");
888 + code = -1;
889 + continue;
890 + }
891 + if (new_report) {
892 + if (!hint->report) {
893 + hint->report = xcalloc(1, sizeof(struct ref_push_report));
894 + report = hint->report;
895 + } else {
896 + report = hint->report;
897 + while (report->next)
898 + report = report->next;
899 + report->next = xcalloc(1, sizeof(struct ref_push_report));
900 + report = report->next;
901 + }
902 + new_report = 0;
903 + }
904 + key = p;
905 + p = strchr(key, ' ');
906 + if (p)
907 + *p++ = '\0';
908 + val = p;
909 + if (!strcmp(key, "refname"))
910 + report->ref_name = xstrdup_or_null(val);
911 + else if (!strcmp(key, "old-oid") && val &&
912 + !parse_oid_hex(val, &old_oid, &val))
913 + report->old_oid = oiddup(&old_oid);
914 + else if (!strcmp(key, "new-oid") && val &&
915 + !parse_oid_hex(val, &new_oid, &val))
916 + report->new_oid = oiddup(&new_oid);
917 + else if (!strcmp(key, "forced-update"))
918 + report->forced_update = 1;
919 + else if (!strcmp(key, "fall-through"))
920 + /* Fall through, let 'receive-pack' to execute it. */
921 + hint->run_proc_receive = 0;
922 + continue;
923 + }
924 +
925 + report = NULL;
926 + new_report = 0;
927 + refname = p;
928 + p = strchr(refname, ' ');
929 + if (p)
930 + *p++ = '\0';
931 + if (strcmp(head, "ok") && strcmp(head, "ng")) {
932 + strbuf_addf(errmsg, "proc-receive reported bad status '%s' on ref '%s'\n",
933 + head, refname);
934 + code = -1;
935 + continue;
936 + }
937 +
938 + /* first try searching at our hint, falling back to all refs */
939 + if (hint)
940 + hint = find_command_by_refname(hint, refname);
941 + if (!hint)
942 + hint = find_command_by_refname(commands, refname);
943 + if (!hint) {
944 + strbuf_addf(errmsg, "proc-receive reported status on unknown ref: %s\n",
945 + refname);
946 + code = -1;
947 + continue;
948 + }
949 + if (!hint->run_proc_receive) {
950 + strbuf_addf(errmsg, "proc-receive reported status on unexpected ref: %s\n",
951 + refname);
952 + code = -1;
953 + continue;
954 + }
955 + hint->run_proc_receive |= RUN_PROC_RECEIVE_RETURNED;
956 + if (!strcmp(head, "ng")) {
957 + if (p)
958 + hint->error_string = xstrdup(p);
959 + else
960 + hint->error_string = "failed";
961 + code = -1;
962 + continue;
963 + }
964 + new_report = 1;
965 + }
966 +
967 + for (cmd = commands; cmd; cmd = cmd->next)
968 + if (cmd->run_proc_receive && !cmd->error_string &&
969 + !(cmd->run_proc_receive & RUN_PROC_RECEIVE_RETURNED)) {
970 + cmd->error_string = "proc-receive failed to report status";
971 + code = -1;
972 + }
973 + return code;
974 +}
975 +
976 +static int run_proc_receive_hook(struct command *commands,
977 + const struct string_list *push_options)
978 +{
979 + struct child_process proc = CHILD_PROCESS_INIT;
980 + struct async muxer;
981 + struct command *cmd;
982 + const char *argv[2];
983 + struct packet_reader reader;
984 + struct strbuf cap = STRBUF_INIT;
985 + struct strbuf errmsg = STRBUF_INIT;
986 + int hook_use_push_options = 0;
987 + int version = 0;
988 + int code;
989 +
990 + argv[0] = find_hook("proc-receive");
991 + if (!argv[0]) {
992 + rp_error("cannot find hook 'proc-receive'");
993 + return -1;
994 + }
995 + argv[1] = NULL;
996 +
997 + proc.argv = argv;
998 + proc.in = -1;
999 + proc.out = -1;
1000 + proc.trace2_hook_name = "proc-receive";
1001 +
1002 + if (use_sideband) {
1003 + memset(&muxer, 0, sizeof(muxer));
1004 + muxer.proc = copy_to_sideband;
1005 + muxer.in = -1;
1006 + code = start_async(&muxer);
1007 + if (code)
1008 + return code;
1009 + proc.err = muxer.in;
1010 + } else {
1011 + proc.err = 0;
1012 + }
1013 +
1014 + code = start_command(&proc);
1015 + if (code) {
1016 + if (use_sideband)
1017 + finish_async(&muxer);
1018 + return code;
1019 + }
1020 +
1021 + sigchain_push(SIGPIPE, SIG_IGN);
1022 +
1023 + /* Version negotiaton */
1024 + packet_reader_init(&reader, proc.out, NULL, 0,
1025 + PACKET_READ_CHOMP_NEWLINE |
1026 + PACKET_READ_GENTLE_ON_EOF);
1027 + if (use_atomic)
1028 + strbuf_addstr(&cap, " atomic");
1029 + if (use_push_options)
1030 + strbuf_addstr(&cap, " push-options");
1031 + if (cap.len) {
1032 + packet_write_fmt(proc.in, "version=1%c%s\n", '\0', cap.buf + 1);
1033 + strbuf_release(&cap);
1034 + } else {
1035 + packet_write_fmt(proc.in, "version=1\n");
1036 + }
1037 + packet_flush(proc.in);
1038 +
1039 + for (;;) {
1040 + int linelen;
1041 +
1042 + if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
1043 + break;
1044 +
1045 + if (reader.pktlen > 8 && starts_with(reader.line, "version=")) {
1046 + version = atoi(reader.line + 8);
1047 + linelen = strlen(reader.line);
1048 + if (linelen < reader.pktlen) {
1049 + const char *feature_list = reader.line + linelen + 1;
1050 + if (parse_feature_request(feature_list, "push-options"))
1051 + hook_use_push_options = 1;
1052 + }
1053 + }
1054 + }
1055 +
1056 + if (version != 1) {
1057 + strbuf_addf(&errmsg, "proc-receive version '%d' is not supported",
1058 + version);
1059 + code = -1;
1060 + goto cleanup;
1061 + }
1062 +
1063 + /* Send commands */
1064 + for (cmd = commands; cmd; cmd = cmd->next) {
1065 + if (!cmd->run_proc_receive || cmd->skip_update || cmd->error_string)
1066 + continue;
1067 + packet_write_fmt(proc.in, "%s %s %s",
1068 + oid_to_hex(&cmd->old_oid),
1069 + oid_to_hex(&cmd->new_oid),
1070 + cmd->ref_name);
1071 + }
1072 + packet_flush(proc.in);
1073 +
1074 + /* Send push options */
1075 + if (hook_use_push_options) {
1076 + struct string_list_item *item;
1077 +
1078 + for_each_string_list_item(item, push_options)
1079 + packet_write_fmt(proc.in, "%s", item->string);
1080 + packet_flush(proc.in);
1081 + }
1082 +
1083 + /* Read result from proc-receive */
1084 + code = read_proc_receive_report(&reader, commands, &errmsg);
1085 +
1086 +cleanup:
1087 + close(proc.in);
1088 + close(proc.out);
1089 + if (use_sideband)
1090 + finish_async(&muxer);
1091 + if (finish_command(&proc))
1092 + code = -1;
1093 + if (errmsg.len >0) {
1094 + char *p = errmsg.buf;
1095 +
1096 + p += errmsg.len - 1;
1097 + if (*p == '\n')
1098 + *p = '\0';
1099 + rp_error("%s", errmsg.buf);
1100 + strbuf_release(&errmsg);
1101 + }
1102 + sigchain_pop(SIGPIPE);
1103 +
1104 + return code;
1105 +}
1106 +
1107 static char *refuse_unconfigured_deny_msg =
1108 N_("By default, updating the current branch in a non-bare repository\n"
1109 "is denied, because it will make the index and work tree inconsistent\n"
@@ -1413,7 +1679,7 @@ static void execute_commands_non_atomic(struct command *commands,
1679 struct strbuf err = STRBUF_INIT;
1680
1681 for (cmd = commands; cmd; cmd = cmd->next) {
1416 - if (!should_process_cmd(cmd))
1682 + if (!should_process_cmd(cmd) || cmd->run_proc_receive)
1683 continue;
1684
1685 transaction = ref_transaction_begin(&err);
@@ -1453,7 +1719,7 @@ static void execute_commands_atomic(struct command *commands,
1719 }
1720
1721 for (cmd = commands; cmd; cmd = cmd->next) {
1456 - if (!should_process_cmd(cmd))
1722 + if (!should_process_cmd(cmd) || cmd->run_proc_receive)
1723 continue;
1724
1725 cmd->error_string = update(cmd, si);
@@ -1489,6 +1755,7 @@ static void execute_commands(struct command *commands,
1755 struct iterate_data data;
1756 struct async muxer;
1757 int err_fd = 0;
1758 + int run_proc_receive = 0;
1759
1760 if (unpacker_error) {
1761 for (cmd = commands; cmd; cmd = cmd->next)
@@ -1518,6 +1785,21 @@ static void execute_commands(struct command *commands,
1785
1786 reject_updates_to_hidden(commands);
1787
1788 + /*
1789 + * Try to find commands that have special prefix in their reference names,
1790 + * and mark them to run an external "proc-receive" hook later.
1791 + */
1792 + for (cmd = commands; cmd; cmd = cmd->next) {
1793 + if (!should_process_cmd(cmd))
1794 + continue;
1795 +
1796 + /* TODO: replace the fixed prefix by looking up git config variables. */
1797 + if (!strncmp(cmd->ref_name, "refs/for/", 9)) {
1798 + cmd->run_proc_receive = RUN_PROC_RECEIVE_SCHEDULED;
1799 + run_proc_receive = 1;
1800 + }
1801 + }
1802 +
1803 if (run_receive_hook(commands, "pre-receive", 0, push_options)) {
1804 for (cmd = commands; cmd; cmd = cmd->next) {
1805 if (!cmd->error_string)
@@ -1544,6 +1826,14 @@ static void execute_commands(struct command *commands,
1826 free(head_name_to_free);
1827 head_name = head_name_to_free = resolve_refdup("HEAD", 0, NULL, NULL);
1828
1829 + if (run_proc_receive &&
1830 + run_proc_receive_hook(commands, push_options))
1831 + for (cmd = commands; cmd; cmd = cmd->next)
1832 + if (!cmd->error_string &&
1833 + !(cmd->run_proc_receive & RUN_PROC_RECEIVE_RETURNED) &&
1834 + (cmd->run_proc_receive || use_atomic))
1835 + cmd->error_string = "fail to run proc-receive hook";
1836 +
1837 if (use_atomic)
1838 execute_commands_atomic(commands, si);
1839 else
remote.h
+8
@@ -93,6 +93,14 @@ int for_each_remote(each_remote_fn fn, void *priv);
93
94 int remote_has_url(struct remote *remote, const char *url);
95
96 +struct ref_push_report {
97 + const char *ref_name;
98 + struct object_id *old_oid;
99 + struct object_id *new_oid;
100 + unsigned int forced_update:1;
101 + struct ref_push_report *next;
102 +};
103 +
104 struct ref {
105 struct ref *next;
106 struct object_id old_oid;
t/helper/test-proc-receive.c new
+176
@@ -0,0 +1,176 @@
1 +#include "cache.h"
2 +#include "connect.h"
3 +#include "parse-options.h"
4 +#include "pkt-line.h"
5 +#include "sigchain.h"
6 +#include "test-tool.h"
7 +
8 +static const char *proc_receive_usage[] = {
9 + "test-tool proc-receive [<options>...]",
10 + NULL
11 +};
12 +
13 +static int die_version;
14 +static int die_readline;
15 +static int no_push_options;
16 +static int use_atomic;
17 +static int use_push_options;
18 +static int verbose;
19 +static int version = 1;
20 +static struct string_list returns = STRING_LIST_INIT_NODUP;
21 +
22 +struct command {
23 + struct command *next;
24 + const char *error_string;
25 + unsigned int skip_update:1,
26 + did_not_exist:1;
27 + int index;
28 + struct object_id old_oid;
29 + struct object_id new_oid;
30 + char ref_name[FLEX_ARRAY]; /* more */
31 +};
32 +
33 +static void proc_receive_verison(struct packet_reader *reader) {
34 + int server_version = 0;
35 +
36 + for (;;) {
37 + int linelen;
38 +
39 + if (packet_reader_read(reader) != PACKET_READ_NORMAL)
40 + break;
41 +
42 + if (reader->pktlen > 8 && starts_with(reader->line, "version=")) {
43 + server_version = atoi(reader->line+8);
44 + linelen = strlen(reader->line);
45 + if (linelen < reader->pktlen) {
46 + const char *feature_list = reader->line + linelen + 1;
47 + if (parse_feature_request(feature_list, "atomic"))
48 + use_atomic= 1;
49 + if (parse_feature_request(feature_list, "push-options"))
50 + use_push_options = 1;
51 + }
52 + }
53 + }
54 +
55 + if (server_version != 1 || die_version)
56 + die("bad protocol version: %d", server_version);
57 +
58 + packet_write_fmt(1, "version=%d%c%s\n",
59 + version, '\0',
60 + use_push_options && !no_push_options ? "push-options": "");
61 + packet_flush(1);
62 +}
63 +
64 +static void proc_receive_read_commands(struct packet_reader *reader,
65 + struct command **commands)
66 +{
67 + struct command **tail = commands;
68 +
69 + for (;;) {
70 + struct object_id old_oid, new_oid;
71 + struct command *cmd;
72 + const char *refname;
73 + const char *p;
74 +
75 + if (packet_reader_read(reader) != PACKET_READ_NORMAL)
76 + break;
77 +
78 + if (parse_oid_hex(reader->line, &old_oid, &p) ||
79 + *p++ != ' ' ||
80 + parse_oid_hex(p, &new_oid, &p) ||
81 + *p++ != ' ' ||
82 + die_readline)
83 + die("protocol error: expected 'old new ref', got '%s'",
84 + reader->line);
85 + refname = p;
86 + FLEX_ALLOC_STR(cmd, ref_name, refname);
87 + oidcpy(&cmd->old_oid, &old_oid);
88 + oidcpy(&cmd->new_oid, &new_oid);
89 +
90 + *tail = cmd;
91 + tail = &cmd->next;
92 + }
93 +}
94 +
95 +static void proc_receive_read_push_options(struct packet_reader *reader,
96 + struct string_list *options)
97 +{
98 +
99 + if (no_push_options || !use_push_options)
100 + return;
101 +
102 + while (1) {
103 + if (packet_reader_read(reader) != PACKET_READ_NORMAL)
104 + break;
105 +
106 + string_list_append(options, reader->line);
107 + }
108 +}
109 +
110 +int cmd__proc_receive(int argc, const char **argv)
111 +{
112 + int nongit_ok = 0;
113 + struct packet_reader reader;
114 + struct command *commands = NULL;
115 + struct string_list push_options = STRING_LIST_INIT_DUP;
116 + struct string_list_item *item;
117 + struct option options[] = {
118 + OPT_BOOL(0, "no-push-options", &no_push_options,
119 + "disable push options"),
120 + OPT_BOOL(0, "die-version", &die_version,
121 + "die during version negotiation"),
122 + OPT_BOOL(0, "die-readline", &die_readline,
123 + "die when readline"),
124 + OPT_STRING_LIST('r', "return", &returns, "old/new/ref/status/msg",
125 + "return of results"),
126 + OPT__VERBOSE(&verbose, "be verbose"),
127 + OPT_INTEGER('V', "version", &version,
128 + "use this protocol version number"),
129 + OPT_END()
130 + };
131 +
132 + setup_git_directory_gently(&nongit_ok);
133 +
134 + argc = parse_options(argc, argv, "test-tools", options, proc_receive_usage, 0);
135 + if (argc > 0)
136 + usage_msg_opt("Too many arguments.", proc_receive_usage, options);
137 + packet_reader_init(&reader, 0, NULL, 0,
138 + PACKET_READ_CHOMP_NEWLINE |
139 + PACKET_READ_DIE_ON_ERR_PACKET);
140 +
141 + sigchain_push(SIGPIPE, SIG_IGN);
142 + proc_receive_verison(&reader);
143 + proc_receive_read_commands(&reader, &commands);
144 + proc_receive_read_push_options(&reader, &push_options);
145 +
146 + if (verbose) {
147 + struct command *cmd;
148 +
149 + if (use_push_options || use_atomic)
150 + fprintf(stderr, "proc-receive:%s%s\n",
151 + use_atomic? " atomic": "",
152 + use_push_options ? " push_options": "");
153 +
154 + for (cmd = commands; cmd; cmd = cmd->next)
155 + fprintf(stderr, "proc-receive< %s %s %s\n",
156 + oid_to_hex(&cmd->old_oid),
157 + oid_to_hex(&cmd->new_oid),
158 + cmd->ref_name);
159 +
160 + if (push_options.nr > 0)
161 + for_each_string_list_item(item, &push_options)
162 + fprintf(stderr, "proc-receive< %s\n", item->string);
163 +
164 + if (returns.nr)
165 + for_each_string_list_item(item, &returns)
166 + fprintf(stderr, "proc-receive> %s\n", item->string);
167 + }
168 +
169 + if (returns.nr)
170 + for_each_string_list_item(item, &returns)
171 + packet_write_fmt(1, "%s\n", item->string);
172 + packet_flush(1);
173 + sigchain_pop(SIGPIPE);
174 +
175 + return 0;
176 +}
t/helper/test-tool.c
+1
@@ -46,6 +46,7 @@ static struct test_cmd cmds[] = {
46 { "path-utils", cmd__path_utils },
47 { "pkt-line", cmd__pkt_line },
48 { "prio-queue", cmd__prio_queue },
49 + { "proc-receive", cmd__proc_receive},
50 { "progress", cmd__progress },
51 { "reach", cmd__reach },
52 { "read-cache", cmd__read_cache },
t/helper/test-tool.h
+1
@@ -35,6 +35,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);
35 int cmd__path_utils(int argc, const char **argv);
36 int cmd__pkt_line(int argc, const char **argv);
37 int cmd__prio_queue(int argc, const char **argv);
38 +int cmd__proc_receive(int argc, const char **argv);
39 int cmd__progress(int argc, const char **argv);
40 int cmd__reach(int argc, const char **argv);
41 int cmd__read_cache(int argc, const char **argv);
t/t5411/test-0011-no-hook-error.sh new
+64
@@ -0,0 +1,64 @@
1 +# Refs of upstream : master(A)
2 +# Refs of workbench: master(A) tags/v123
3 +# git push : next(A) refs/for/master/topic(A)
4 +test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)" '
5 + test_must_fail git -C workbench push origin \
6 + HEAD:next \
7 + HEAD:refs/for/master/topic \
8 + >out 2>&1 &&
9 + make_user_friendly_and_stable_output <out >actual &&
10 + cat >expect <<-EOF &&
11 + remote: # pre-receive hook
12 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
13 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
14 + remote: error: cannot find hook "proc-receive"
15 + remote: # post-receive hook
16 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
17 + To <URL/of/upstream.git>
18 + * [new branch] HEAD -> next
19 + ! [remote rejected] HEAD -> refs/for/master/topic (fail to run proc-receive hook)
20 + EOF
21 + test_cmp expect actual &&
22 + git -C "$upstream" show-ref >out &&
23 + make_user_friendly_and_stable_output <out >actual &&
24 + cat >expect <<-EOF &&
25 + <COMMIT-A> refs/heads/master
26 + <COMMIT-A> refs/heads/next
27 + EOF
28 + test_cmp expect actual
29 +'
30 +
31 +# Refs of upstream : master(A) next(A)
32 +# Refs of workbench: master(A) tags/v123
33 +test_expect_success "cleanup ($PROTOCOL)" '
34 + git -C "$upstream" update-ref -d refs/heads/next
35 +'
36 +
37 +# Refs of upstream : master(A)
38 +# Refs of workbench: master(A) tags/v123
39 +# git push --atomic: (B) next(A) refs/for/master/topic(A)
40 +test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCOL)" '
41 + test_must_fail git -C workbench push --atomic origin \
42 + $B:master \
43 + HEAD:next \
44 + HEAD:refs/for/master/topic >out 2>&1 &&
45 + make_user_friendly_and_stable_output <out >actual &&
46 + cat >expect <<-EOF &&
47 + remote: # pre-receive hook
48 + remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
49 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
50 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
51 + remote: error: cannot find hook "proc-receive"
52 + To <URL/of/upstream.git>
53 + ! [remote rejected] <COMMIT-B> -> master (fail to run proc-receive hook)
54 + ! [remote rejected] HEAD -> next (fail to run proc-receive hook)
55 + ! [remote rejected] HEAD -> refs/for/master/topic (fail to run proc-receive hook)
56 + EOF
57 + test_cmp expect actual &&
58 + git -C "$upstream" show-ref >out &&
59 + make_user_friendly_and_stable_output <out >actual &&
60 + cat >expect <<-EOF &&
61 + <COMMIT-A> refs/heads/master
62 + EOF
63 + test_cmp expect actual
64 +'
t/t5411/test-0012-no-hook-error--porcelain.sh new
+66
@@ -0,0 +1,66 @@
1 +# Refs of upstream : master(A)
2 +# Refs of workbench: master(A) tags/v123
3 +# git push : next(A) refs/for/master/topic(A)
4 +test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/porcelain)" '
5 + test_must_fail git -C workbench push --porcelain origin \
6 + HEAD:next \
7 + HEAD:refs/for/master/topic \
8 + >out 2>&1 &&
9 + make_user_friendly_and_stable_output <out >actual &&
10 + cat >expect <<-EOF &&
11 + remote: # pre-receive hook
12 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
13 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
14 + remote: error: cannot find hook "proc-receive"
15 + remote: # post-receive hook
16 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
17 + To <URL/of/upstream.git>
18 + * HEAD:refs/heads/next [new branch]
19 + ! HEAD:refs/for/master/topic [remote rejected] (fail to run proc-receive hook)
20 + Done
21 + EOF
22 + test_cmp expect actual &&
23 + git -C "$upstream" show-ref >out &&
24 + make_user_friendly_and_stable_output <out >actual &&
25 + cat >expect <<-EOF &&
26 + <COMMIT-A> refs/heads/master
27 + <COMMIT-A> refs/heads/next
28 + EOF
29 + test_cmp expect actual
30 +'
31 +
32 +# Refs of upstream : master(A) next(A)
33 +# Refs of workbench: master(A) tags/v123
34 +test_expect_success "cleanup ($PROTOCOL/porcelain)" '
35 + git -C "$upstream" update-ref -d refs/heads/next
36 +'
37 +
38 +# Refs of upstream : master(A)
39 +# Refs of workbench: master(A) tags/v123
40 +# git push --atomic: (B) next(A) refs/for/master/topic(A)
41 +test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCOL/porcelain)" '
42 + test_must_fail git -C workbench push --porcelain --atomic origin \
43 + $B:master \
44 + HEAD:next \
45 + HEAD:refs/for/master/topic >out 2>&1 &&
46 + make_user_friendly_and_stable_output <out >actual &&
47 + cat >expect <<-EOF &&
48 + remote: # pre-receive hook
49 + remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
50 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
51 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
52 + remote: error: cannot find hook "proc-receive"
53 + To <URL/of/upstream.git>
54 + ! <COMMIT-B>:refs/heads/master [remote rejected] (fail to run proc-receive hook)
55 + ! HEAD:refs/heads/next [remote rejected] (fail to run proc-receive hook)
56 + ! HEAD:refs/for/master/topic [remote rejected] (fail to run proc-receive hook)
57 + Done
58 + EOF
59 + test_cmp expect actual &&
60 + git -C "$upstream" show-ref >out &&
61 + make_user_friendly_and_stable_output <out >actual &&
62 + cat >expect <<-EOF &&
63 + <COMMIT-A> refs/heads/master
64 + EOF
65 + test_cmp expect actual
66 +'
t/t5411/test-0013-bad-protocol.sh new
+217
@@ -0,0 +1,217 @@
1 +test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v --version 2
5 + EOF
6 +'
7 +
8 +# Refs of upstream : master(A)
9 +# Refs of workbench: master(A) tags/v123
10 +# git push : refs/for/master/topic(A)
11 +test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" '
12 + test_must_fail git -C workbench push origin \
13 + HEAD:refs/for/master/topic \
14 + >out 2>&1 &&
15 + make_user_friendly_and_stable_output <out >actual &&
16 +
17 + # Check status report for git-push
18 + sed -n \
19 + -e "/^To / { p; n; p; }" \
20 + <actual >actual-report &&
21 + cat >expect <<-EOF &&
22 + To <URL/of/upstream.git>
23 + ! [remote rejected] HEAD -> refs/for/master/topic (fail to run proc-receive hook)
24 + EOF
25 + test_cmp expect actual-report &&
26 +
27 + # Check error message from "receive-pack", but ignore unstable fatal error
28 + # message ("remote: fatal: the remote end hung up unexpectedly") which
29 + # is different from the remote HTTP server with different locale settings.
30 + grep "^remote: error:" <actual >actual-error &&
31 + cat >expect <<-EOF &&
32 + remote: error: proc-receive version "2" is not supported
33 + EOF
34 + test_cmp expect actual-error &&
35 +
36 + git -C "$upstream" show-ref >out &&
37 + make_user_friendly_and_stable_output <out >actual &&
38 + cat >expect <<-EOF &&
39 + <COMMIT-A> refs/heads/master
40 + EOF
41 + test_cmp expect actual
42 +'
43 +
44 +test_expect_success "setup proc-receive hook (hook --die-version, $PROTOCOL)" '
45 + write_script "$upstream/hooks/proc-receive" <<-EOF
46 + printf >&2 "# proc-receive hook\n"
47 + test-tool proc-receive -v --die-version
48 + EOF
49 +'
50 +
51 +# Refs of upstream : master(A)
52 +# Refs of workbench: master(A) tags/v123
53 +# git push : refs/for/master/topic(A)
54 +test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" '
55 + test_must_fail git -C workbench push origin \
56 + HEAD:refs/for/master/topic \
57 + >out 2>&1 &&
58 + make_user_friendly_and_stable_output <out >actual &&
59 +
60 + cat >expect <<-EOF &&
61 + remote: # pre-receive hook
62 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
63 + remote: # proc-receive hook
64 + remote: fatal: bad protocol version: 1
65 + remote: error: proc-receive version "0" is not supported
66 + To <URL/of/upstream.git>
67 + ! [remote rejected] HEAD -> refs/for/master/topic (fail to run proc-receive hook)
68 + EOF
69 + test_cmp expect actual &&
70 +
71 + git -C "$upstream" show-ref >out &&
72 + make_user_friendly_and_stable_output <out >actual &&
73 + cat >expect <<-EOF &&
74 + <COMMIT-A> refs/heads/master
75 + EOF
76 + test_cmp expect actual
77 +'
78 +
79 +test_expect_success "setup proc-receive hook (hook --die-readline, $PROTOCOL)" '
80 + write_script "$upstream/hooks/proc-receive" <<-EOF
81 + printf >&2 "# proc-receive hook\n"
82 + test-tool proc-receive -v --die-readline
83 + EOF
84 +'
85 +
86 +# Refs of upstream : master(A)
87 +# Refs of workbench: master(A) tags/v123
88 +# git push : refs/for/master/topic(A)
89 +test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" '
90 + test_must_fail git -C workbench push origin \
91 + HEAD:refs/for/master/topic \
92 + >out 2>&1 &&
93 + make_user_friendly_and_stable_output <out >actual &&
94 +
95 + grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/master/topic\"" actual &&
96 +
97 + git -C "$upstream" show-ref >out &&
98 + make_user_friendly_and_stable_output <out >actual &&
99 + cat >expect <<-EOF &&
100 + <COMMIT-A> refs/heads/master
101 + EOF
102 + test_cmp expect actual
103 +'
104 +
105 +test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" '
106 + write_script "$upstream/hooks/proc-receive" <<-EOF
107 + printf >&2 "# proc-receive hook\n"
108 + test-tool proc-receive -v
109 + EOF
110 +'
111 +
112 +# Refs of upstream : master(A)
113 +# Refs of workbench: master(A) tags/v123
114 +# git push : next(A) refs/for/master/topic(A)
115 +test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
116 + test_must_fail git -C workbench push origin \
117 + HEAD:refs/heads/next \
118 + HEAD:refs/for/master/topic >out 2>&1 &&
119 + make_user_friendly_and_stable_output <out >actual &&
120 + cat >expect <<-EOF &&
121 + remote: # pre-receive hook
122 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
123 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
124 + remote: # proc-receive hook
125 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
126 + remote: # post-receive hook
127 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
128 + To <URL/of/upstream.git>
129 + * [new branch] HEAD -> next
130 + ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
131 + EOF
132 + test_cmp expect actual &&
133 + git -C "$upstream" show-ref >out &&
134 + make_user_friendly_and_stable_output <out >actual &&
135 + cat >expect <<-EOF &&
136 + <COMMIT-A> refs/heads/master
137 + <COMMIT-A> refs/heads/next
138 + EOF
139 + test_cmp expect actual
140 +'
141 +
142 +# Refs of upstream : master(A) next(A)
143 +# Refs of workbench: master(A) tags/v123
144 +test_expect_success "cleanup ($PROTOCOL)" '
145 + git -C "$upstream" update-ref -d refs/heads/next
146 +
147 +'
148 +
149 +test_expect_success "setup proc-receive hook (no ref, $PROTOCOL)" '
150 + write_script "$upstream/hooks/proc-receive" <<-EOF
151 + printf >&2 "# proc-receive hook\n"
152 + test-tool proc-receive -v \
153 + -r "ok"
154 + EOF
155 +'
156 +
157 +# Refs of upstream : master(A)
158 +# Refs of workbench: master(A) tags/v123
159 +# git push : refs/for/master/topic
160 +test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
161 + test_must_fail git -C workbench push origin \
162 + HEAD:refs/for/master/topic\
163 + >out 2>&1 &&
164 + make_user_friendly_and_stable_output <out >actual &&
165 + cat >expect <<-EOF &&
166 + remote: # pre-receive hook
167 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
168 + remote: # proc-receive hook
169 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
170 + remote: proc-receive> ok
171 + remote: error: proc-receive reported incomplete status line: "ok"
172 + To <URL/of/upstream.git>
173 + ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
174 + EOF
175 + test_cmp expect actual &&
176 + git -C "$upstream" show-ref >out &&
177 + make_user_friendly_and_stable_output <out >actual &&
178 + cat >expect <<-EOF &&
179 + <COMMIT-A> refs/heads/master
180 + EOF
181 + test_cmp expect actual
182 +'
183 +
184 +test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" '
185 + write_script "$upstream/hooks/proc-receive" <<-EOF
186 + printf >&2 "# proc-receive hook\n"
187 + test-tool proc-receive -v \
188 + -r "xx refs/for/master/topic"
189 + EOF
190 +'
191 +
192 +# Refs of upstream : master(A)
193 +# Refs of workbench: master(A) tags/v123
194 +# git push : refs/for/master/topic
195 +test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
196 + test_must_fail git -C workbench push origin \
197 + HEAD:refs/for/master/topic \
198 + >out 2>&1 &&
199 + make_user_friendly_and_stable_output <out >actual &&
200 + cat >expect <<-EOF &&
201 + remote: # pre-receive hook
202 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
203 + remote: # proc-receive hook
204 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
205 + remote: proc-receive> xx refs/for/master/topic
206 + remote: error: proc-receive reported bad status "xx" on ref "refs/for/master/topic"
207 + To <URL/of/upstream.git>
208 + ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
209 + EOF
210 + test_cmp expect actual &&
211 + git -C "$upstream" show-ref >out &&
212 + make_user_friendly_and_stable_output <out >actual &&
213 + cat >expect <<-EOF &&
214 + <COMMIT-A> refs/heads/master
215 + EOF
216 + test_cmp expect actual
217 +'
t/t5411/test-0014-bad-protocol--porcelain.sh new
+160
@@ -0,0 +1,160 @@
1 +test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v --version 2
5 + EOF
6 +'
7 +
8 +# Refs of upstream : master(A)
9 +# Refs of workbench: master(A) tags/v123
10 +# git push : refs/for/master/topic(A)
11 +test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL/porcelain)" '
12 + test_must_fail git -C workbench push --porcelain origin \
13 + HEAD:refs/for/master/topic \
14 + >out 2>&1 &&
15 + make_user_friendly_and_stable_output <out >actual &&
16 +
17 + # Check status report for git-push
18 + sed -n \
19 + -e "/^To / { p; n; p; n; p; }" \
20 + <actual >actual-report &&
21 + cat >expect <<-EOF &&
22 + To <URL/of/upstream.git>
23 + ! HEAD:refs/for/master/topic [remote rejected] (fail to run proc-receive hook)
24 + Done
25 + EOF
26 + test_cmp expect actual-report &&
27 +
28 + # Check error message from "receive-pack", but ignore unstable fatal error
29 + # message ("remote: fatal: the remote end hung up unexpectedly") which
30 + # is different from the remote HTTP server with different locale settings.
31 + grep "^remote: error:" <actual >actual-error &&
32 + cat >expect <<-EOF &&
33 + remote: error: proc-receive version "2" is not supported
34 + EOF
35 + test_cmp expect actual-error &&
36 +
37 + git -C "$upstream" show-ref >out &&
38 + make_user_friendly_and_stable_output <out >actual &&
39 + cat >expect <<-EOF &&
40 + <COMMIT-A> refs/heads/master
41 + EOF
42 + test_cmp expect actual
43 +'
44 +
45 +test_expect_success "setup proc-receive hook (no report, $PROTOCOL/porcelain)" '
46 + write_script "$upstream/hooks/proc-receive" <<-EOF
47 + printf >&2 "# proc-receive hook\n"
48 + test-tool proc-receive -v
49 + EOF
50 +'
51 +
52 +# Refs of upstream : master(A)
53 +# Refs of workbench: master(A) tags/v123
54 +# git push : next(A) refs/for/master/topic(A)
55 +test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain)" '
56 + test_must_fail git -C workbench push --porcelain origin \
57 + HEAD:refs/heads/next \
58 + HEAD:refs/for/master/topic >out 2>&1 &&
59 + make_user_friendly_and_stable_output <out >actual &&
60 + cat >expect <<-EOF &&
61 + remote: # pre-receive hook
62 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
63 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
64 + remote: # proc-receive hook
65 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
66 + remote: # post-receive hook
67 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
68 + To <URL/of/upstream.git>
69 + * HEAD:refs/heads/next [new branch]
70 + ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
71 + Done
72 + EOF
73 + test_cmp expect actual &&
74 + git -C "$upstream" show-ref >out &&
75 + make_user_friendly_and_stable_output <out >actual &&
76 + cat >expect <<-EOF &&
77 + <COMMIT-A> refs/heads/master
78 + <COMMIT-A> refs/heads/next
79 + EOF
80 + test_cmp expect actual
81 +'
82 +
83 +# Refs of upstream : master(A) next(A)
84 +# Refs of workbench: master(A) tags/v123
85 +test_expect_success "cleanup ($PROTOCOL/porcelain)" '
86 + git -C "$upstream" update-ref -d refs/heads/next
87 +
88 +'
89 +
90 +test_expect_success "setup proc-receive hook (no ref, $PROTOCOL/porcelain)" '
91 + write_script "$upstream/hooks/proc-receive" <<-EOF
92 + printf >&2 "# proc-receive hook\n"
93 + test-tool proc-receive -v \
94 + -r "ok"
95 + EOF
96 +'
97 +
98 +# Refs of upstream : master(A)
99 +# Refs of workbench: master(A) tags/v123
100 +# git push : refs/for/master/topic
101 +test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" '
102 + test_must_fail git -C workbench push --porcelain origin \
103 + HEAD:refs/for/master/topic\
104 + >out 2>&1 &&
105 + make_user_friendly_and_stable_output <out >actual &&
106 + cat >expect <<-EOF &&
107 + remote: # pre-receive hook
108 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
109 + remote: # proc-receive hook
110 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
111 + remote: proc-receive> ok
112 + remote: error: proc-receive reported incomplete status line: "ok"
113 + To <URL/of/upstream.git>
114 + ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
115 + Done
116 + EOF
117 + test_cmp expect actual &&
118 + git -C "$upstream" show-ref >out &&
119 + make_user_friendly_and_stable_output <out >actual &&
120 + cat >expect <<-EOF &&
121 + <COMMIT-A> refs/heads/master
122 + EOF
123 + test_cmp expect actual
124 +'
125 +
126 +test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL/porcelain)" '
127 + write_script "$upstream/hooks/proc-receive" <<-EOF
128 + printf >&2 "# proc-receive hook\n"
129 + test-tool proc-receive -v \
130 + -r "xx refs/for/master/topic"
131 + EOF
132 +'
133 +
134 +# Refs of upstream : master(A)
135 +# Refs of workbench: master(A) tags/v123
136 +# git push : refs/for/master/topic
137 +test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL/porcelain)" '
138 + test_must_fail git -C workbench push --porcelain origin \
139 + HEAD:refs/for/master/topic \
140 + >out 2>&1 &&
141 + make_user_friendly_and_stable_output <out >actual &&
142 + cat >expect <<-EOF &&
143 + remote: # pre-receive hook
144 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
145 + remote: # proc-receive hook
146 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
147 + remote: proc-receive> xx refs/for/master/topic
148 + remote: error: proc-receive reported bad status "xx" on ref "refs/for/master/topic"
149 + To <URL/of/upstream.git>
150 + ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
151 + Done
152 + EOF
153 + test_cmp expect actual &&
154 + git -C "$upstream" show-ref >out &&
155 + make_user_friendly_and_stable_output <out >actual &&
156 + cat >expect <<-EOF &&
157 + <COMMIT-A> refs/heads/master
158 + EOF
159 + test_cmp expect actual
160 +'
t/t5411/test-0020-report-ng.sh new
+67
@@ -0,0 +1,67 @@
1 +test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ng refs/for/master/topic"
6 + EOF
7 +'
8 +
9 +# Refs of upstream : master(A)
10 +# Refs of workbench: master(A) tags/v123
11 +# git push : refs/for/master/topic
12 +test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" '
13 + test_must_fail git -C workbench push origin \
14 + HEAD:refs/for/master/topic \
15 + >out 2>&1 &&
16 + make_user_friendly_and_stable_output <out >actual &&
17 + cat >expect <<-EOF &&
18 + remote: # pre-receive hook
19 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
20 + remote: # proc-receive hook
21 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
22 + remote: proc-receive> ng refs/for/master/topic
23 + To <URL/of/upstream.git>
24 + ! [remote rejected] HEAD -> refs/for/master/topic (failed)
25 + EOF
26 + test_cmp expect actual &&
27 + git -C "$upstream" show-ref >out &&
28 + make_user_friendly_and_stable_output <out >actual &&
29 + cat >expect <<-EOF &&
30 + <COMMIT-A> refs/heads/master
31 + EOF
32 + test_cmp expect actual
33 +'
34 +
35 +test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" '
36 + write_script "$upstream/hooks/proc-receive" <<-EOF
37 + printf >&2 "# proc-receive hook\n"
38 + test-tool proc-receive -v \
39 + -r "ng refs/for/master/topic error msg"
40 + EOF
41 +'
42 +
43 +# Refs of upstream : master(A)
44 +# Refs of workbench: master(A) tags/v123
45 +# git push : refs/for/master/topic
46 +test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)" '
47 + test_must_fail git -C workbench push origin \
48 + HEAD:refs/for/master/topic \
49 + >out 2>&1 &&
50 + make_user_friendly_and_stable_output <out >actual &&
51 + cat >expect <<-EOF &&
52 + remote: # pre-receive hook
53 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
54 + remote: # proc-receive hook
55 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
56 + remote: proc-receive> ng refs/for/master/topic error msg
57 + To <URL/of/upstream.git>
58 + ! [remote rejected] HEAD -> refs/for/master/topic (error msg)
59 + EOF
60 + test_cmp expect actual &&
61 + git -C "$upstream" show-ref >out &&
62 + make_user_friendly_and_stable_output <out >actual &&
63 + cat >expect <<-EOF &&
64 + <COMMIT-A> refs/heads/master
65 + EOF
66 + test_cmp expect actual
67 +'
t/t5411/test-0021-report-ng--porcelain.sh new
+69
@@ -0,0 +1,69 @@
1 +test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ng refs/for/master/topic"
6 + EOF
7 +'
8 +
9 +# Refs of upstream : master(A)
10 +# Refs of workbench: master(A) tags/v123
11 +# git push : refs/for/master/topic
12 +test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/porcelain)" '
13 + test_must_fail git -C workbench push --porcelain origin \
14 + HEAD:refs/for/master/topic \
15 + >out 2>&1 &&
16 + make_user_friendly_and_stable_output <out >actual &&
17 + cat >expect <<-EOF &&
18 + remote: # pre-receive hook
19 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
20 + remote: # proc-receive hook
21 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
22 + remote: proc-receive> ng refs/for/master/topic
23 + To <URL/of/upstream.git>
24 + ! HEAD:refs/for/master/topic [remote rejected] (failed)
25 + Done
26 + EOF
27 + test_cmp expect actual &&
28 + git -C "$upstream" show-ref >out &&
29 + make_user_friendly_and_stable_output <out >actual &&
30 + cat >expect <<-EOF &&
31 + <COMMIT-A> refs/heads/master
32 + EOF
33 + test_cmp expect actual
34 +'
35 +
36 +test_expect_success "setup proc-receive hook (ng message, $PROTOCOL/porcelain)" '
37 + write_script "$upstream/hooks/proc-receive" <<-EOF
38 + printf >&2 "# proc-receive hook\n"
39 + test-tool proc-receive -v \
40 + -r "ng refs/for/master/topic error msg"
41 + EOF
42 +'
43 +
44 +# Refs of upstream : master(A)
45 +# Refs of workbench: master(A) tags/v123
46 +# git push : refs/for/master/topic
47 +test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/porcelain)" '
48 + test_must_fail git -C workbench push --porcelain origin \
49 + HEAD:refs/for/master/topic \
50 + >out 2>&1 &&
51 + make_user_friendly_and_stable_output <out >actual &&
52 + cat >expect <<-EOF &&
53 + remote: # pre-receive hook
54 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
55 + remote: # proc-receive hook
56 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
57 + remote: proc-receive> ng refs/for/master/topic error msg
58 + To <URL/of/upstream.git>
59 + ! HEAD:refs/for/master/topic [remote rejected] (error msg)
60 + Done
61 + EOF
62 + test_cmp expect actual &&
63 + git -C "$upstream" show-ref >out &&
64 + make_user_friendly_and_stable_output <out >actual &&
65 + cat >expect <<-EOF &&
66 + <COMMIT-A> refs/heads/master
67 + EOF
68 + test_cmp expect actual
69 +'
t/t5411/test-0022-report-unexpect-ref.sh new
+45
@@ -0,0 +1,45 @@
1 +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/heads/master"
6 + EOF
7 +'
8 +
9 +# Refs of upstream : master(A)
10 +# Refs of workbench: master(A) tags/v123
11 +# git push : (B) refs/for/master/topic
12 +test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
13 + test_must_fail git -C workbench push origin \
14 + $B:refs/heads/master \
15 + HEAD:refs/for/master/topic \
16 + >out 2>&1 &&
17 + make_user_friendly_and_stable_output <out >actual &&
18 + cat >expect <<-EOF &&
19 + remote: # pre-receive hook
20 + remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
21 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
22 + remote: # proc-receive hook
23 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
24 + remote: proc-receive> ok refs/heads/master
25 + remote: error: proc-receive reported status on unexpected ref: refs/heads/master
26 + remote: # post-receive hook
27 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
28 + To <URL/of/upstream.git>
29 + <OID-A>..<OID-B> <COMMIT-B> -> master
30 + ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
31 + EOF
32 + test_cmp expect actual &&
33 + git -C "$upstream" show-ref >out &&
34 + make_user_friendly_and_stable_output <out >actual &&
35 + cat >expect <<-EOF &&
36 + <COMMIT-B> refs/heads/master
37 + EOF
38 + test_cmp expect actual
39 +'
40 +
41 +# Refs of upstream : master(B)
42 +# Refs of workbench: master(A) tags/v123
43 +test_expect_success "cleanup ($PROTOCOL)" '
44 + git -C "$upstream" update-ref refs/heads/master $A
45 +'
t/t5411/test-0023-report-unexpect-ref--porcelain.sh new
+46
@@ -0,0 +1,46 @@
1 +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/heads/master"
6 + EOF
7 +'
8 +
9 +# Refs of upstream : master(A)
10 +# Refs of workbench: master(A) tags/v123
11 +# git push : (B) refs/for/master/topic
12 +test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)" '
13 + test_must_fail git -C workbench push --porcelain origin \
14 + $B:refs/heads/master \
15 + HEAD:refs/for/master/topic \
16 + >out 2>&1 &&
17 + make_user_friendly_and_stable_output <out >actual &&
18 + cat >expect <<-EOF &&
19 + remote: # pre-receive hook
20 + remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
21 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
22 + remote: # proc-receive hook
23 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
24 + remote: proc-receive> ok refs/heads/master
25 + remote: error: proc-receive reported status on unexpected ref: refs/heads/master
26 + remote: # post-receive hook
27 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
28 + To <URL/of/upstream.git>
29 + <COMMIT-B>:refs/heads/master <OID-A>..<OID-B>
30 + ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
31 + Done
32 + EOF
33 + test_cmp expect actual &&
34 + git -C "$upstream" show-ref >out &&
35 + make_user_friendly_and_stable_output <out >actual &&
36 + cat >expect <<-EOF &&
37 + <COMMIT-B> refs/heads/master
38 + EOF
39 + test_cmp expect actual
40 +'
41 +
42 +# Refs of upstream : master(B)
43 +# Refs of workbench: master(A) tags/v123
44 +test_expect_success "cleanup ($PROTOCOL/porcelain)" '
45 + git -C "$upstream" update-ref refs/heads/master $A
46 +'
t/t5411/test-0024-report-unknown-ref.sh new
+34
@@ -0,0 +1,34 @@
1 +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/master/topic"
6 + EOF
7 +'
8 +
9 +# Refs of upstream : master(A)
10 +# Refs of workbench: master(A) tags/v123
11 +# git push : refs/for/a/b/c/my/topic
12 +test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
13 + test_must_fail git -C workbench push origin \
14 + HEAD:refs/for/a/b/c/my/topic \
15 + >out 2>&1 &&
16 + make_user_friendly_and_stable_output <out >actual &&
17 + cat >expect <<-EOF &&
18 + remote: # pre-receive hook
19 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
20 + remote: # proc-receive hook
21 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
22 + remote: proc-receive> ok refs/for/master/topic
23 + remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
24 + To <URL/of/upstream.git>
25 + ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
26 + EOF
27 + test_cmp expect actual &&
28 + git -C "$upstream" show-ref >out &&
29 + make_user_friendly_and_stable_output <out >actual &&
30 + cat >expect <<-EOF &&
31 + <COMMIT-A> refs/heads/master
32 + EOF
33 + test_cmp expect actual
34 +'
t/t5411/test-0025-report-unknown-ref--porcelain.sh new
+35
@@ -0,0 +1,35 @@
1 +test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/master/topic"
6 + EOF
7 +'
8 +
9 +# Refs of upstream : master(A)
10 +# Refs of workbench: master(A) tags/v123
11 +# git push : refs/for/a/b/c/my/topic
12 +test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain)" '
13 + test_must_fail git -C workbench push --porcelain origin \
14 + HEAD:refs/for/a/b/c/my/topic \
15 + >out 2>&1 &&
16 + make_user_friendly_and_stable_output <out >actual &&
17 + cat >expect <<-EOF &&
18 + remote: # pre-receive hook
19 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
20 + remote: # proc-receive hook
21 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
22 + remote: proc-receive> ok refs/for/master/topic
23 + remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
24 + To <URL/of/upstream.git>
25 + ! HEAD:refs/for/a/b/c/my/topic [remote rejected] (proc-receive failed to report status)
26 + Done
27 + EOF
28 + test_cmp expect actual &&
29 + git -C "$upstream" show-ref >out &&
30 + make_user_friendly_and_stable_output <out >actual &&
31 + cat >expect <<-EOF &&
32 + <COMMIT-A> refs/heads/master
33 + EOF
34 + test_cmp expect actual
35 +'
t/t5411/test-0026-push-options.sh new
+79
@@ -0,0 +1,79 @@
1 +test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL)" '
2 + git -C "$upstream" config receive.advertisePushOptions false &&
3 + write_script "$upstream/hooks/proc-receive" <<-EOF
4 + printf >&2 "# proc-receive hook\n"
5 + test-tool proc-receive -v \
6 + -r "ok refs/for/master/topic"
7 + EOF
8 +'
9 +
10 +# Refs of upstream : master(A)
11 +# Refs of workbench: master(A) tags/v123
12 +# git push -o ... : refs/for/master/topic
13 +test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
14 + test_must_fail git -C workbench push \
15 + -o issue=123 \
16 + -o reviewer=user1 \
17 + origin \
18 + HEAD:refs/for/master/topic \
19 + >out 2>&1 &&
20 + make_user_friendly_and_stable_output <out >actual &&
21 + test_i18ngrep "fatal: the receiving end does not support push options" \
22 + actual &&
23 + git -C "$upstream" show-ref >out &&
24 + make_user_friendly_and_stable_output <out >actual &&
25 + cat >expect <<-EOF &&
26 + <COMMIT-A> refs/heads/master
27 + EOF
28 + test_cmp expect actual
29 +'
30 +
31 +test_expect_success "enable push options ($PROTOCOL)" '
32 + git -C "$upstream" config receive.advertisePushOptions true
33 +'
34 +
35 +# Refs of upstream : master(A)
36 +# Refs of workbench: master(A) tags/v123
37 +# git push -o ... : next(A) refs/for/master/topic
38 +test_expect_success "proc-receive: push with options ($PROTOCOL)" '
39 + git -C workbench push \
40 + --atomic \
41 + -o issue=123 \
42 + -o reviewer=user1 \
43 + origin \
44 + HEAD:refs/heads/next \
45 + HEAD:refs/for/master/topic \
46 + >out 2>&1 &&
47 + make_user_friendly_and_stable_output <out >actual &&
48 + cat >expect <<-EOF &&
49 + remote: # pre-receive hook
50 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
51 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
52 + remote: # proc-receive hook
53 + remote: proc-receive: atomic push_options
54 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
55 + remote: proc-receive< issue=123
56 + remote: proc-receive< reviewer=user1
57 + remote: proc-receive> ok refs/for/master/topic
58 + remote: # post-receive hook
59 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
60 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
61 + To <URL/of/upstream.git>
62 + * [new branch] HEAD -> next
63 + * [new reference] HEAD -> refs/for/master/topic
64 + EOF
65 + test_cmp expect actual &&
66 + git -C "$upstream" show-ref >out &&
67 + make_user_friendly_and_stable_output <out >actual &&
68 + cat >expect <<-EOF &&
69 + <COMMIT-A> refs/heads/master
70 + <COMMIT-A> refs/heads/next
71 + EOF
72 + test_cmp expect actual
73 +'
74 +
75 +# Refs of upstream : master(A) next(A)
76 +# Refs of workbench: master(A) tags/v123
77 +test_expect_success "cleanup ($PROTOCOL)" '
78 + git -C "$upstream" update-ref -d refs/heads/next
79 +'
t/t5411/test-0027-push-options--porcelain.sh new
+82
@@ -0,0 +1,82 @@
1 +test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL/porcelain)" '
2 + git -C "$upstream" config receive.advertisePushOptions false &&
3 + write_script "$upstream/hooks/proc-receive" <<-EOF
4 + printf >&2 "# proc-receive hook\n"
5 + test-tool proc-receive -v \
6 + -r "ok refs/for/master/topic"
7 + EOF
8 +'
9 +
10 +# Refs of upstream : master(A)
11 +# Refs of workbench: master(A) tags/v123
12 +# git push -o ... : refs/for/master/topic
13 +test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain)" '
14 + test_must_fail git -C workbench push \
15 + --porcelain \
16 + -o issue=123 \
17 + -o reviewer=user1 \
18 + origin \
19 + HEAD:refs/for/master/topic \
20 + >out 2>&1 &&
21 + make_user_friendly_and_stable_output <out >actual &&
22 + test_i18ngrep "fatal: the receiving end does not support push options" \
23 + actual &&
24 + git -C "$upstream" show-ref >out &&
25 + make_user_friendly_and_stable_output <out >actual &&
26 + cat >expect <<-EOF &&
27 + <COMMIT-A> refs/heads/master
28 + EOF
29 + test_cmp expect actual
30 +'
31 +
32 +test_expect_success "enable push options ($PROTOCOL/porcelain)" '
33 + git -C "$upstream" config receive.advertisePushOptions true
34 +'
35 +
36 +# Refs of upstream : master(A)
37 +# Refs of workbench: master(A) tags/v123
38 +# git push -o ... : next(A) refs/for/master/topic
39 +test_expect_success "proc-receive: push with options ($PROTOCOL/porcelain)" '
40 + git -C workbench push \
41 + --porcelain \
42 + --atomic \
43 + -o issue=123 \
44 + -o reviewer=user1 \
45 + origin \
46 + HEAD:refs/heads/next \
47 + HEAD:refs/for/master/topic \
48 + >out 2>&1 &&
49 + make_user_friendly_and_stable_output <out >actual &&
50 + cat >expect <<-EOF &&
51 + remote: # pre-receive hook
52 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
53 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
54 + remote: # proc-receive hook
55 + remote: proc-receive: atomic push_options
56 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
57 + remote: proc-receive< issue=123
58 + remote: proc-receive< reviewer=user1
59 + remote: proc-receive> ok refs/for/master/topic
60 + remote: # post-receive hook
61 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
62 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
63 + To <URL/of/upstream.git>
64 + * HEAD:refs/heads/next [new branch]
65 + * HEAD:refs/for/master/topic [new reference]
66 + Done
67 + EOF
68 + test_cmp expect actual &&
69 + git -C "$upstream" show-ref >out &&
70 + make_user_friendly_and_stable_output <out >actual &&
71 + cat >expect <<-EOF &&
72 + <COMMIT-A> refs/heads/master
73 + <COMMIT-A> refs/heads/next
74 + EOF
75 + test_cmp expect actual
76 +'
77 +
78 +# Refs of upstream : master(A) next(A)
79 +# Refs of workbench: master(A) tags/v123
80 +test_expect_success "cleanup ($PROTOCOL/porcelain)" '
81 + git -C "$upstream" update-ref -d refs/heads/next
82 +'
t/t5411/test-0030-report-ok.sh new
+35
@@ -0,0 +1,35 @@
1 +test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/master/topic"
6 + EOF
7 +'
8 +
9 +# Refs of upstream : master(A)
10 +# Refs of workbench: master(A) tags/v123
11 +# git push : refs/for/master/topic
12 +test_expect_success "proc-receive: ok ($PROTOCOL)" '
13 + git -C workbench push origin \
14 + HEAD:refs/for/master/topic \
15 + >out 2>&1 &&
16 + make_user_friendly_and_stable_output <out >actual &&
17 + cat >expect <<-EOF &&
18 + remote: # pre-receive hook
19 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
20 + remote: # proc-receive hook
21 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
22 + remote: proc-receive> ok refs/for/master/topic
23 + remote: # post-receive hook
24 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
25 + To <URL/of/upstream.git>
26 + * [new reference] HEAD -> refs/for/master/topic
27 + EOF
28 + test_cmp expect actual &&
29 + git -C "$upstream" show-ref >out &&
30 + make_user_friendly_and_stable_output <out >actual &&
31 + cat >expect <<-EOF &&
32 + <COMMIT-A> refs/heads/master
33 + EOF
34 + test_cmp expect actual
35 +'
t/t5411/test-0031-report-ok--porcelain.sh new
+36
@@ -0,0 +1,36 @@
1 +test_expect_success "setup proc-receive hook (ok, $PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/master/topic"
6 + EOF
7 +'
8 +
9 +# Refs of upstream : master(A)
10 +# Refs of workbench: master(A) tags/v123
11 +# git push : refs/for/master/topic
12 +test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" '
13 + git -C workbench push --porcelain origin \
14 + HEAD:refs/for/master/topic \
15 + >out 2>&1 &&
16 + make_user_friendly_and_stable_output <out >actual &&
17 + cat >expect <<-EOF &&
18 + remote: # pre-receive hook
19 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
20 + remote: # proc-receive hook
21 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
22 + remote: proc-receive> ok refs/for/master/topic
23 + remote: # post-receive hook
24 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
25 + To <URL/of/upstream.git>
26 + * HEAD:refs/for/master/topic [new reference]
27 + Done
28 + EOF
29 + test_cmp expect actual &&
30 + git -C "$upstream" show-ref >out &&
31 + make_user_friendly_and_stable_output <out >actual &&
32 + cat >expect <<-EOF &&
33 + <COMMIT-A> refs/heads/master
34 + EOF
35 + test_cmp expect actual
36 +'
t/t5411/test-0032-report-with-options.sh new
+256
@@ -0,0 +1,256 @@
1 +test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "option refname refs/pull/123/head" \
6 + -r "option old-oid $B"
7 + EOF
8 +'
9 +
10 +# Refs of upstream : master(A)
11 +# Refs of workbench: master(A) tags/v123
12 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
13 +test_expect_success "proc-receive: report option without matching ok ($PROTOCOL)" '
14 + test_must_fail git -C workbench push origin \
15 + HEAD:refs/for/master/topic \
16 + >out 2>&1 &&
17 + make_user_friendly_and_stable_output <out >actual &&
18 + cat >expect <<-EOF &&
19 + remote: # pre-receive hook
20 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
21 + remote: # proc-receive hook
22 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
23 + remote: proc-receive> option refname refs/pull/123/head
24 + remote: proc-receive> option old-oid <COMMIT-B>
25 + remote: error: proc-receive reported "option" without a matching "ok/ng" directive
26 + To <URL/of/upstream.git>
27 + ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
28 + EOF
29 + test_cmp expect actual
30 +'
31 +
32 +test_expect_success "setup proc-receive hook (option refname, $PROTOCOL)" '
33 + write_script "$upstream/hooks/proc-receive" <<-EOF
34 + printf >&2 "# proc-receive hook\n"
35 + test-tool proc-receive -v \
36 + -r "ok refs/for/master/topic" \
37 + -r "option refname refs/pull/123/head"
38 + EOF
39 +'
40 +
41 +# Refs of upstream : master(A)
42 +# Refs of workbench: master(A) tags/v123
43 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
44 +test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
45 + git -C workbench push origin \
46 + HEAD:refs/for/master/topic \
47 + >out 2>&1 &&
48 + make_user_friendly_and_stable_output <out >actual &&
49 + cat >expect <<-EOF &&
50 + remote: # pre-receive hook
51 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
52 + remote: # proc-receive hook
53 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
54 + remote: proc-receive> ok refs/for/master/topic
55 + remote: proc-receive> option refname refs/pull/123/head
56 + remote: # post-receive hook
57 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
58 + To <URL/of/upstream.git>
59 + * [new reference] HEAD -> refs/for/master/topic
60 + EOF
61 + test_cmp expect actual
62 +'
63 +
64 +test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL)" '
65 + write_script "$upstream/hooks/proc-receive" <<-EOF
66 + printf >&2 "# proc-receive hook\n"
67 + test-tool proc-receive -v \
68 + -r "ok refs/for/master/topic" \
69 + -r "option refname refs/pull/123/head" \
70 + -r "option forced-update"
71 + EOF
72 +'
73 +# Refs of upstream : master(A)
74 +# Refs of workbench: master(A) tags/v123
75 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
76 +test_expect_success "proc-receive: report option refname and forced-update ($PROTOCOL)" '
77 + git -C workbench push origin \
78 + HEAD:refs/for/master/topic \
79 + >out 2>&1 &&
80 + make_user_friendly_and_stable_output <out >actual &&
81 + cat >expect <<-EOF &&
82 + remote: # pre-receive hook
83 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
84 + remote: # proc-receive hook
85 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
86 + remote: proc-receive> ok refs/for/master/topic
87 + remote: proc-receive> option refname refs/pull/123/head
88 + remote: proc-receive> option forced-update
89 + remote: # post-receive hook
90 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
91 + To <URL/of/upstream.git>
92 + * [new reference] HEAD -> refs/for/master/topic
93 + EOF
94 + test_cmp expect actual
95 +'
96 +
97 +test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL)" '
98 + write_script "$upstream/hooks/proc-receive" <<-EOF
99 + printf >&2 "# proc-receive hook\n"
100 + test-tool proc-receive -v \
101 + -r "ok refs/for/master/topic" \
102 + -r "option refname refs/pull/123/head" \
103 + -r "option old-oid $B"
104 + EOF
105 +'
106 +
107 +# Refs of upstream : master(A)
108 +# Refs of workbench: master(A) tags/v123
109 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
110 +test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)" '
111 + git -C workbench push origin \
112 + HEAD:refs/for/master/topic \
113 + >out 2>&1 &&
114 + make_user_friendly_and_stable_output <out >actual &&
115 + cat >expect <<-EOF &&
116 + remote: # pre-receive hook
117 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
118 + remote: # proc-receive hook
119 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
120 + remote: proc-receive> ok refs/for/master/topic
121 + remote: proc-receive> option refname refs/pull/123/head
122 + remote: proc-receive> option old-oid <COMMIT-B>
123 + remote: # post-receive hook
124 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
125 + To <URL/of/upstream.git>
126 + * [new reference] HEAD -> refs/for/master/topic
127 + EOF
128 + test_cmp expect actual
129 +'
130 +
131 +test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL)" '
132 + write_script "$upstream/hooks/proc-receive" <<-EOF
133 + printf >&2 "# proc-receive hook\n"
134 + test-tool proc-receive -v \
135 + -r "ok refs/for/master/topic" \
136 + -r "option old-oid $B"
137 + EOF
138 +'
139 +
140 +# Refs of upstream : master(A)
141 +# Refs of workbench: master(A) tags/v123
142 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
143 +test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
144 + git -C workbench push origin \
145 + HEAD:refs/for/master/topic \
146 + >out 2>&1 &&
147 + make_user_friendly_and_stable_output <out >actual &&
148 + cat >expect <<-EOF &&
149 + remote: # pre-receive hook
150 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
151 + remote: # proc-receive hook
152 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
153 + remote: proc-receive> ok refs/for/master/topic
154 + remote: proc-receive> option old-oid <COMMIT-B>
155 + remote: # post-receive hook
156 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
157 + To <URL/of/upstream.git>
158 + * [new reference] HEAD -> refs/for/master/topic
159 + EOF
160 + test_cmp expect actual
161 +'
162 +
163 +test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL)" '
164 + write_script "$upstream/hooks/proc-receive" <<-EOF
165 + printf >&2 "# proc-receive hook\n"
166 + test-tool proc-receive -v \
167 + -r "ok refs/for/master/topic" \
168 + -r "option old-oid $A" \
169 + -r "option new-oid $B"
170 + EOF
171 +'
172 +
173 +# Refs of upstream : master(A)
174 +# Refs of workbench: master(A) tags/v123
175 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
176 +test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)" '
177 + git -C workbench push origin \
178 + HEAD:refs/for/master/topic \
179 + >out 2>&1 &&
180 + make_user_friendly_and_stable_output <out >actual &&
181 + cat >expect <<-EOF &&
182 + remote: # pre-receive hook
183 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
184 + remote: # proc-receive hook
185 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
186 + remote: proc-receive> ok refs/for/master/topic
187 + remote: proc-receive> option old-oid <COMMIT-A>
188 + remote: proc-receive> option new-oid <COMMIT-B>
189 + remote: # post-receive hook
190 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
191 + To <URL/of/upstream.git>
192 + * [new reference] HEAD -> refs/for/master/topic
193 + EOF
194 + test_cmp expect actual
195 +'
196 +
197 +test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL)" '
198 + write_script "$upstream/hooks/proc-receive" <<-EOF
199 + printf >&2 "# proc-receive hook\n"
200 + test-tool proc-receive -v \
201 + -r "ok refs/for/a/b/c/topic" \
202 + -r "ok refs/for/next/topic" \
203 + -r "option refname refs/pull/123/head" \
204 + -r "ok refs/for/master/topic" \
205 + -r "option refname refs/pull/124/head" \
206 + -r "option old-oid $B" \
207 + -r "option forced-update" \
208 + -r "option new-oid $A"
209 + EOF
210 +'
211 +
212 +# Refs of upstream : master(A)
213 +# Refs of workbench: master(A) tags/v123
214 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
215 +test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
216 + git -C workbench push origin \
217 + HEAD:refs/for/next/topic \
218 + HEAD:refs/for/a/b/c/topic \
219 + HEAD:refs/for/master/topic \
220 + >out 2>&1 &&
221 + make_user_friendly_and_stable_output <out >actual &&
222 + cat >expect <<-EOF &&
223 + remote: # pre-receive hook
224 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
225 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
226 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
227 + remote: # proc-receive hook
228 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
229 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
230 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
231 + remote: proc-receive> ok refs/for/a/b/c/topic
232 + remote: proc-receive> ok refs/for/next/topic
233 + remote: proc-receive> option refname refs/pull/123/head
234 + remote: proc-receive> ok refs/for/master/topic
235 + remote: proc-receive> option refname refs/pull/124/head
236 + remote: proc-receive> option old-oid <COMMIT-B>
237 + remote: proc-receive> option forced-update
238 + remote: proc-receive> option new-oid <COMMIT-A>
239 + remote: # post-receive hook
240 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
241 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
242 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
243 + To <URL/of/upstream.git>
244 + * [new reference] HEAD -> refs/for/next/topic
245 + * [new reference] HEAD -> refs/for/a/b/c/topic
246 + * [new reference] HEAD -> refs/for/master/topic
247 + EOF
248 + test_cmp expect actual &&
249 +
250 + git -C "$upstream" show-ref >out &&
251 + make_user_friendly_and_stable_output <out >actual &&
252 + cat >expect <<-EOF &&
253 + <COMMIT-A> refs/heads/master
254 + EOF
255 + test_cmp expect actual
256 +'
t/t5411/test-0033-report-with-options--porcelain.sh new
+265
@@ -0,0 +1,265 @@
1 +test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "option refname refs/pull/123/head" \
6 + -r "option old-oid $B"
7 + EOF
8 +'
9 +
10 +# Refs of upstream : master(A)
11 +# Refs of workbench: master(A) tags/v123
12 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
13 +test_expect_success "proc-receive: report option without matching ok ($PROTOCOL/porcelain)" '
14 + test_must_fail git -C workbench push --porcelain origin \
15 + HEAD:refs/for/master/topic \
16 + >out 2>&1 &&
17 + make_user_friendly_and_stable_output <out >actual &&
18 + cat >expect <<-EOF &&
19 + remote: # pre-receive hook
20 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
21 + remote: # proc-receive hook
22 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
23 + remote: proc-receive> option refname refs/pull/123/head
24 + remote: proc-receive> option old-oid <COMMIT-B>
25 + remote: error: proc-receive reported "option" without a matching "ok/ng" directive
26 + To <URL/of/upstream.git>
27 + ! HEAD:refs/for/master/topic [remote rejected] (proc-receive failed to report status)
28 + Done
29 + EOF
30 + test_cmp expect actual
31 +'
32 +
33 +test_expect_success "setup proc-receive hook (option refname, $PROTOCOL/porcelain)" '
34 + write_script "$upstream/hooks/proc-receive" <<-EOF
35 + printf >&2 "# proc-receive hook\n"
36 + test-tool proc-receive -v \
37 + -r "ok refs/for/master/topic" \
38 + -r "option refname refs/pull/123/head"
39 + EOF
40 +'
41 +
42 +# Refs of upstream : master(A)
43 +# Refs of workbench: master(A) tags/v123
44 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
45 +test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)" '
46 + git -C workbench push --porcelain origin \
47 + HEAD:refs/for/master/topic \
48 + >out 2>&1 &&
49 + make_user_friendly_and_stable_output <out >actual &&
50 + cat >expect <<-EOF &&
51 + remote: # pre-receive hook
52 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
53 + remote: # proc-receive hook
54 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
55 + remote: proc-receive> ok refs/for/master/topic
56 + remote: proc-receive> option refname refs/pull/123/head
57 + remote: # post-receive hook
58 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
59 + To <URL/of/upstream.git>
60 + * HEAD:refs/for/master/topic [new reference]
61 + Done
62 + EOF
63 + test_cmp expect actual
64 +'
65 +
66 +test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL/porcelain)" '
67 + write_script "$upstream/hooks/proc-receive" <<-EOF
68 + printf >&2 "# proc-receive hook\n"
69 + test-tool proc-receive -v \
70 + -r "ok refs/for/master/topic" \
71 + -r "option refname refs/pull/123/head" \
72 + -r "option forced-update"
73 + EOF
74 +'
75 +
76 +# Refs of upstream : master(A)
77 +# Refs of workbench: master(A) tags/v123
78 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
79 +test_expect_success "proc-receive: report option refname and forced-update ($PROTOCOL/porcelain)" '
80 + git -C workbench push --porcelain origin \
81 + HEAD:refs/for/master/topic \
82 + >out 2>&1 &&
83 + make_user_friendly_and_stable_output <out >actual &&
84 + cat >expect <<-EOF &&
85 + remote: # pre-receive hook
86 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
87 + remote: # proc-receive hook
88 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
89 + remote: proc-receive> ok refs/for/master/topic
90 + remote: proc-receive> option refname refs/pull/123/head
91 + remote: proc-receive> option forced-update
92 + remote: # post-receive hook
93 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
94 + To <URL/of/upstream.git>
95 + * HEAD:refs/for/master/topic [new reference]
96 + Done
97 + EOF
98 + test_cmp expect actual
99 +'
100 +
101 +test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL/porcelain)" '
102 + write_script "$upstream/hooks/proc-receive" <<-EOF
103 + printf >&2 "# proc-receive hook\n"
104 + test-tool proc-receive -v \
105 + -r "ok refs/for/master/topic" \
106 + -r "option refname refs/pull/123/head" \
107 + -r "option old-oid $B"
108 + EOF
109 +'
110 +
111 +# Refs of upstream : master(A)
112 +# Refs of workbench: master(A) tags/v123
113 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
114 +test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/porcelain)" '
115 + git -C workbench push --porcelain origin \
116 + HEAD:refs/for/master/topic \
117 + >out 2>&1 &&
118 + make_user_friendly_and_stable_output <out >actual &&
119 + cat >expect <<-EOF &&
120 + remote: # pre-receive hook
121 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
122 + remote: # proc-receive hook
123 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
124 + remote: proc-receive> ok refs/for/master/topic
125 + remote: proc-receive> option refname refs/pull/123/head
126 + remote: proc-receive> option old-oid <COMMIT-B>
127 + remote: # post-receive hook
128 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
129 + To <URL/of/upstream.git>
130 + * HEAD:refs/for/master/topic [new reference]
131 + Done
132 + EOF
133 + test_cmp expect actual
134 +'
135 +
136 +test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL/porcelain)" '
137 + write_script "$upstream/hooks/proc-receive" <<-EOF
138 + printf >&2 "# proc-receive hook\n"
139 + test-tool proc-receive -v \
140 + -r "ok refs/for/master/topic" \
141 + -r "option old-oid $B"
142 + EOF
143 +'
144 +
145 +# Refs of upstream : master(A)
146 +# Refs of workbench: master(A) tags/v123
147 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
148 +test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)" '
149 + git -C workbench push --porcelain origin \
150 + HEAD:refs/for/master/topic \
151 + >out 2>&1 &&
152 + make_user_friendly_and_stable_output <out >actual &&
153 + cat >expect <<-EOF &&
154 + remote: # pre-receive hook
155 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
156 + remote: # proc-receive hook
157 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
158 + remote: proc-receive> ok refs/for/master/topic
159 + remote: proc-receive> option old-oid <COMMIT-B>
160 + remote: # post-receive hook
161 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
162 + To <URL/of/upstream.git>
163 + * HEAD:refs/for/master/topic [new reference]
164 + Done
165 + EOF
166 + test_cmp expect actual
167 +'
168 +
169 +test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL/porcelain)" '
170 + write_script "$upstream/hooks/proc-receive" <<-EOF
171 + printf >&2 "# proc-receive hook\n"
172 + test-tool proc-receive -v \
173 + -r "ok refs/for/master/topic" \
174 + -r "option old-oid $A" \
175 + -r "option new-oid $B"
176 + EOF
177 +'
178 +
179 +# Refs of upstream : master(A)
180 +# Refs of workbench: master(A) tags/v123
181 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
182 +test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/porcelain)" '
183 + git -C workbench push --porcelain origin \
184 + HEAD:refs/for/master/topic \
185 + >out 2>&1 &&
186 + make_user_friendly_and_stable_output <out >actual &&
187 + cat >expect <<-EOF &&
188 + remote: # pre-receive hook
189 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
190 + remote: # proc-receive hook
191 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
192 + remote: proc-receive> ok refs/for/master/topic
193 + remote: proc-receive> option old-oid <COMMIT-A>
194 + remote: proc-receive> option new-oid <COMMIT-B>
195 + remote: # post-receive hook
196 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
197 + To <URL/of/upstream.git>
198 + * HEAD:refs/for/master/topic [new reference]
199 + Done
200 + EOF
201 + test_cmp expect actual
202 +'
203 +
204 +test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL/porcelain)" '
205 + write_script "$upstream/hooks/proc-receive" <<-EOF
206 + printf >&2 "# proc-receive hook\n"
207 + test-tool proc-receive -v \
208 + -r "ok refs/for/a/b/c/topic" \
209 + -r "ok refs/for/next/topic" \
210 + -r "option refname refs/pull/123/head" \
211 + -r "ok refs/for/master/topic" \
212 + -r "option refname refs/pull/124/head" \
213 + -r "option old-oid $B" \
214 + -r "option forced-update" \
215 + -r "option new-oid $A"
216 +
217 + EOF
218 +'
219 +
220 +# Refs of upstream : master(A)
221 +# Refs of workbench: master(A) tags/v123
222 +# git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/master/topic(A)
223 +test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porcelain)" '
224 + git -C workbench push --porcelain origin \
225 + HEAD:refs/for/next/topic \
226 + HEAD:refs/for/a/b/c/topic \
227 + HEAD:refs/for/master/topic \
228 + >out 2>&1 &&
229 + make_user_friendly_and_stable_output <out >actual &&
230 + cat >expect <<-EOF &&
231 + remote: # pre-receive hook
232 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
233 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
234 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
235 + remote: # proc-receive hook
236 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
237 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
238 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
239 + remote: proc-receive> ok refs/for/a/b/c/topic
240 + remote: proc-receive> ok refs/for/next/topic
241 + remote: proc-receive> option refname refs/pull/123/head
242 + remote: proc-receive> ok refs/for/master/topic
243 + remote: proc-receive> option refname refs/pull/124/head
244 + remote: proc-receive> option old-oid <COMMIT-B>
245 + remote: proc-receive> option forced-update
246 + remote: proc-receive> option new-oid <COMMIT-A>
247 + remote: # post-receive hook
248 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
249 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
250 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
251 + To <URL/of/upstream.git>
252 + * HEAD:refs/for/next/topic [new reference]
253 + * HEAD:refs/for/a/b/c/topic [new reference]
254 + * HEAD:refs/for/master/topic [new reference]
255 + Done
256 + EOF
257 + test_cmp expect actual &&
258 +
259 + git -C "$upstream" show-ref >out &&
260 + make_user_friendly_and_stable_output <out >actual &&
261 + cat >expect <<-EOF &&
262 + <COMMIT-A> refs/heads/master
263 + EOF
264 + test_cmp expect actual
265 +'
t/t5411/test-0034-report-ft.sh new
+44
@@ -0,0 +1,44 @@
1 +test_expect_success "setup proc-receive hook (ft, $PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/master/topic" \
6 + -r "option fall-through"
7 + EOF
8 +'
9 +
10 +# Refs of upstream : master(A)
11 +# Refs of workbench: master(A) tags/v123
12 +# git push : refs/for/master/topic(B)
13 +test_expect_success "proc-receive: fall throught, let receive-pack to execute ($PROTOCOL)" '
14 + git -C workbench push origin \
15 + $B:refs/for/master/topic \
16 + >out 2>&1 &&
17 + make_user_friendly_and_stable_output <out >actual &&
18 + cat >expect <<-EOF &&
19 + remote: # pre-receive hook
20 + remote: pre-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
21 + remote: # proc-receive hook
22 + remote: proc-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
23 + remote: proc-receive> ok refs/for/master/topic
24 + remote: proc-receive> option fall-through
25 + remote: # post-receive hook
26 + remote: post-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
27 + To <URL/of/upstream.git>
28 + * [new reference] <COMMIT-B> -> refs/for/master/topic
29 + EOF
30 + test_cmp expect actual &&
31 + git -C "$upstream" show-ref >out &&
32 + make_user_friendly_and_stable_output <out >actual &&
33 + cat >expect <<-EOF &&
34 + <COMMIT-B> refs/for/master/topic
35 + <COMMIT-A> refs/heads/master
36 + EOF
37 + test_cmp expect actual
38 +'
39 +
40 +# Refs of upstream : master(A) refs/for/master/topic(A)
41 +# Refs of workbench: master(A) tags/v123
42 +test_expect_success "cleanup ($PROTOCOL)" '
43 + git -C "$upstream" update-ref -d refs/for/master/topic
44 +'
t/t5411/test-0035-report-ft--porcelain.sh new
+45
@@ -0,0 +1,45 @@
1 +test_expect_success "setup proc-receive hook (fall-through, $PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/master/topic" \
6 + -r "option fall-through"
7 + EOF
8 +'
9 +
10 +# Refs of upstream : master(A)
11 +# Refs of workbench: master(A) tags/v123
12 +# git push : refs/for/master/topic(B)
13 +test_expect_success "proc-receive: fall throught, let receive-pack to execute ($PROTOCOL/porcelain)" '
14 + git -C workbench push --porcelain origin \
15 + $B:refs/for/master/topic \
16 + >out 2>&1 &&
17 + make_user_friendly_and_stable_output <out >actual &&
18 + cat >expect <<-EOF &&
19 + remote: # pre-receive hook
20 + remote: pre-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
21 + remote: # proc-receive hook
22 + remote: proc-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
23 + remote: proc-receive> ok refs/for/master/topic
24 + remote: proc-receive> option fall-through
25 + remote: # post-receive hook
26 + remote: post-receive< <ZERO-OID> <COMMIT-B> refs/for/master/topic
27 + To <URL/of/upstream.git>
28 + * <COMMIT-B>:refs/for/master/topic [new reference]
29 + Done
30 + EOF
31 + test_cmp expect actual &&
32 + git -C "$upstream" show-ref >out &&
33 + make_user_friendly_and_stable_output <out >actual &&
34 + cat >expect <<-EOF &&
35 + <COMMIT-B> refs/for/master/topic
36 + <COMMIT-A> refs/heads/master
37 + EOF
38 + test_cmp expect actual
39 +'
40 +
41 +# Refs of upstream : master(A) refs/for/master/topic(A)
42 +# Refs of workbench: master(A) tags/v123
43 +test_expect_success "cleanup ($PROTOCOL/porcelain)" '
44 + git -C "$upstream" update-ref -d refs/for/master/topic
45 +'
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh new
+159
@@ -0,0 +1,159 @@
1 +test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/master/topic" \
6 + -r "option old-oid $A" \
7 + -r "option new-oid $B" \
8 + -r "ok refs/for/master/topic" \
9 + -r "option refname refs/changes/24/124/1" \
10 + -r "option old-oid $ZERO_OID" \
11 + -r "option new-oid $A" \
12 + -r "ok refs/for/master/topic" \
13 + -r "option refname refs/changes/25/125/1" \
14 + -r "option old-oid $A" \
15 + -r "option new-oid $B"
16 + EOF
17 +'
18 +
19 +# Refs of upstream : master(A)
20 +# Refs of workbench: master(A) tags/v123
21 +# git push : refs/for/master/topic(A)
22 +test_expect_success "proc-receive: multiple rewrite for one ref, no refname for the 1st rewrite ($PROTOCOL)" '
23 + git -C workbench push origin \
24 + HEAD:refs/for/master/topic \
25 + >out 2>&1 &&
26 + make_user_friendly_and_stable_output <out >actual &&
27 + cat >expect <<-EOF &&
28 + remote: # pre-receive hook
29 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
30 + remote: # proc-receive hook
31 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
32 + remote: proc-receive> ok refs/for/master/topic
33 + remote: proc-receive> option old-oid <COMMIT-A>
34 + remote: proc-receive> option new-oid <COMMIT-B>
35 + remote: proc-receive> ok refs/for/master/topic
36 + remote: proc-receive> option refname refs/changes/24/124/1
37 + remote: proc-receive> option old-oid <ZERO-OID>
38 + remote: proc-receive> option new-oid <COMMIT-A>
39 + remote: proc-receive> ok refs/for/master/topic
40 + remote: proc-receive> option refname refs/changes/25/125/1
41 + remote: proc-receive> option old-oid <COMMIT-A>
42 + remote: proc-receive> option new-oid <COMMIT-B>
43 + remote: # post-receive hook
44 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
45 + To <URL/of/upstream.git>
46 + * [new reference] HEAD -> refs/for/master/topic
47 + EOF
48 + test_cmp expect actual &&
49 + git -C "$upstream" show-ref >out &&
50 + make_user_friendly_and_stable_output <out >actual &&
51 + cat >expect <<-EOF &&
52 + <COMMIT-A> refs/heads/master
53 + EOF
54 + test_cmp expect actual
55 +'
56 +
57 +test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
58 + write_script "$upstream/hooks/proc-receive" <<-EOF
59 + printf >&2 "# proc-receive hook\n"
60 + test-tool proc-receive -v \
61 + -r "ok refs/for/master/topic" \
62 + -r "option refname refs/changes/24/124/1" \
63 + -r "option old-oid $ZERO_OID" \
64 + -r "option new-oid $A" \
65 + -r "ok refs/for/master/topic" \
66 + -r "option old-oid $A" \
67 + -r "option new-oid $B" \
68 + -r "ok refs/for/master/topic" \
69 + -r "option refname refs/changes/25/125/1" \
70 + -r "option old-oid $B" \
71 + -r "option new-oid $A" \
72 + -r "option forced-update"
73 + EOF
74 +'
75 +
76 +# Refs of upstream : master(A)
77 +# Refs of workbench: master(A) tags/v123
78 +# git push : refs/for/master/topic(A)
79 +test_expect_success "proc-receive: multiple rewrites for one ref, no refname for the 2nd rewrite ($PROTOCOL)" '
80 + git -C workbench push origin \
81 + HEAD:refs/for/master/topic \
82 + >out 2>&1 &&
83 + make_user_friendly_and_stable_output <out >actual &&
84 + cat >expect <<-EOF &&
85 + remote: # pre-receive hook
86 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
87 + remote: # proc-receive hook
88 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
89 + remote: proc-receive> ok refs/for/master/topic
90 + remote: proc-receive> option refname refs/changes/24/124/1
91 + remote: proc-receive> option old-oid <ZERO-OID>
92 + remote: proc-receive> option new-oid <COMMIT-A>
93 + remote: proc-receive> ok refs/for/master/topic
94 + remote: proc-receive> option old-oid <COMMIT-A>
95 + remote: proc-receive> option new-oid <COMMIT-B>
96 + remote: proc-receive> ok refs/for/master/topic
97 + remote: proc-receive> option refname refs/changes/25/125/1
98 + remote: proc-receive> option old-oid <COMMIT-B>
99 + remote: proc-receive> option new-oid <COMMIT-A>
100 + remote: proc-receive> option forced-update
101 + remote: # post-receive hook
102 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
103 + To <URL/of/upstream.git>
104 + * [new reference] HEAD -> refs/for/master/topic
105 + EOF
106 + test_cmp expect actual &&
107 + git -C "$upstream" show-ref >out &&
108 + make_user_friendly_and_stable_output <out >actual &&
109 + cat >expect <<-EOF &&
110 + <COMMIT-A> refs/heads/master
111 + EOF
112 + test_cmp expect actual
113 +'
114 +
115 +test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
116 + write_script "$upstream/hooks/proc-receive" <<-EOF
117 + printf >&2 "# proc-receive hook\n"
118 + test-tool proc-receive -v \
119 + -r "ok refs/for/master/topic" \
120 + -r "option refname refs/changes/23/123/1" \
121 + -r "ok refs/for/master/topic" \
122 + -r "option refname refs/changes/24/124/2" \
123 + -r "option old-oid $A" \
124 + -r "option new-oid $B"
125 + EOF
126 +'
127 +
128 +# Refs of upstream : master(A)
129 +# Refs of workbench: master(A) tags/v123
130 +# git push : refs/for/master/topic(A)
131 +test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
132 + git -C workbench push origin \
133 + HEAD:refs/for/master/topic \
134 + >out 2>&1 &&
135 + make_user_friendly_and_stable_output <out >actual &&
136 + cat >expect <<-EOF &&
137 + remote: # pre-receive hook
138 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
139 + remote: # proc-receive hook
140 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
141 + remote: proc-receive> ok refs/for/master/topic
142 + remote: proc-receive> option refname refs/changes/23/123/1
143 + remote: proc-receive> ok refs/for/master/topic
144 + remote: proc-receive> option refname refs/changes/24/124/2
145 + remote: proc-receive> option old-oid <COMMIT-A>
146 + remote: proc-receive> option new-oid <COMMIT-B>
147 + remote: # post-receive hook
148 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
149 + To <URL/of/upstream.git>
150 + * [new reference] HEAD -> refs/for/master/topic
151 + EOF
152 + test_cmp expect actual &&
153 + git -C "$upstream" show-ref >out &&
154 + make_user_friendly_and_stable_output <out >actual &&
155 + cat >expect <<-EOF &&
156 + <COMMIT-A> refs/heads/master
157 + EOF
158 + test_cmp expect actual
159 +'
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh new
+162
@@ -0,0 +1,162 @@
1 +test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/master/topic" \
6 + -r "option old-oid $A" \
7 + -r "option new-oid $B" \
8 + -r "ok refs/for/master/topic" \
9 + -r "option refname refs/changes/24/124/1" \
10 + -r "option old-oid $ZERO_OID" \
11 + -r "option new-oid $A" \
12 + -r "ok refs/for/master/topic" \
13 + -r "option refname refs/changes/25/125/1" \
14 + -r "option old-oid $A" \
15 + -r "option new-oid $B"
16 + EOF
17 +'
18 +
19 +# Refs of upstream : master(A)
20 +# Refs of workbench: master(A) tags/v123
21 +# git push : refs/for/master/topic(A)
22 +test_expect_success "proc-receive: multiple rewrite for one ref, no refname for the 1st rewrite ($PROTOCOL/porcelain)" '
23 + git -C workbench push --porcelain origin \
24 + HEAD:refs/for/master/topic \
25 + >out 2>&1 &&
26 + make_user_friendly_and_stable_output <out >actual &&
27 + cat >expect <<-EOF &&
28 + remote: # pre-receive hook
29 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
30 + remote: # proc-receive hook
31 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
32 + remote: proc-receive> ok refs/for/master/topic
33 + remote: proc-receive> option old-oid <COMMIT-A>
34 + remote: proc-receive> option new-oid <COMMIT-B>
35 + remote: proc-receive> ok refs/for/master/topic
36 + remote: proc-receive> option refname refs/changes/24/124/1
37 + remote: proc-receive> option old-oid <ZERO-OID>
38 + remote: proc-receive> option new-oid <COMMIT-A>
39 + remote: proc-receive> ok refs/for/master/topic
40 + remote: proc-receive> option refname refs/changes/25/125/1
41 + remote: proc-receive> option old-oid <COMMIT-A>
42 + remote: proc-receive> option new-oid <COMMIT-B>
43 + remote: # post-receive hook
44 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
45 + To <URL/of/upstream.git>
46 + * HEAD:refs/for/master/topic [new reference]
47 + Done
48 + EOF
49 + test_cmp expect actual &&
50 + git -C "$upstream" show-ref >out &&
51 + make_user_friendly_and_stable_output <out >actual &&
52 + cat >expect <<-EOF &&
53 + <COMMIT-A> refs/heads/master
54 + EOF
55 + test_cmp expect actual
56 +'
57 +
58 +test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL/porcelain)" '
59 + write_script "$upstream/hooks/proc-receive" <<-EOF
60 + printf >&2 "# proc-receive hook\n"
61 + test-tool proc-receive -v \
62 + -r "ok refs/for/master/topic" \
63 + -r "option refname refs/changes/24/124/1" \
64 + -r "option old-oid $ZERO_OID" \
65 + -r "option new-oid $A" \
66 + -r "ok refs/for/master/topic" \
67 + -r "option old-oid $A" \
68 + -r "option new-oid $B" \
69 + -r "ok refs/for/master/topic" \
70 + -r "option refname refs/changes/25/125/1" \
71 + -r "option old-oid $B" \
72 + -r "option new-oid $A" \
73 + -r "option forced-update"
74 + EOF
75 +'
76 +
77 +# Refs of upstream : master(A)
78 +# Refs of workbench: master(A) tags/v123
79 +# git push : refs/for/master/topic(A)
80 +test_expect_success "proc-receive: multiple rewrites for one ref, no refname for the 2nd rewrite ($PROTOCOL/porcelain)" '
81 + git -C workbench push --porcelain origin \
82 + HEAD:refs/for/master/topic \
83 + >out 2>&1 &&
84 + make_user_friendly_and_stable_output <out >actual &&
85 + cat >expect <<-EOF &&
86 + remote: # pre-receive hook
87 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
88 + remote: # proc-receive hook
89 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
90 + remote: proc-receive> ok refs/for/master/topic
91 + remote: proc-receive> option refname refs/changes/24/124/1
92 + remote: proc-receive> option old-oid <ZERO-OID>
93 + remote: proc-receive> option new-oid <COMMIT-A>
94 + remote: proc-receive> ok refs/for/master/topic
95 + remote: proc-receive> option old-oid <COMMIT-A>
96 + remote: proc-receive> option new-oid <COMMIT-B>
97 + remote: proc-receive> ok refs/for/master/topic
98 + remote: proc-receive> option refname refs/changes/25/125/1
99 + remote: proc-receive> option old-oid <COMMIT-B>
100 + remote: proc-receive> option new-oid <COMMIT-A>
101 + remote: proc-receive> option forced-update
102 + remote: # post-receive hook
103 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
104 + To <URL/of/upstream.git>
105 + * HEAD:refs/for/master/topic [new reference]
106 + Done
107 + EOF
108 + test_cmp expect actual &&
109 + git -C "$upstream" show-ref >out &&
110 + make_user_friendly_and_stable_output <out >actual &&
111 + cat >expect <<-EOF &&
112 + <COMMIT-A> refs/heads/master
113 + EOF
114 + test_cmp expect actual
115 +'
116 +
117 +test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL/porcelain)" '
118 + write_script "$upstream/hooks/proc-receive" <<-EOF
119 + printf >&2 "# proc-receive hook\n"
120 + test-tool proc-receive -v \
121 + -r "ok refs/for/master/topic" \
122 + -r "option refname refs/changes/23/123/1" \
123 + -r "ok refs/for/master/topic" \
124 + -r "option refname refs/changes/24/124/2" \
125 + -r "option old-oid $A" \
126 + -r "option new-oid $B"
127 + EOF
128 +'
129 +
130 +# Refs of upstream : master(A)
131 +# Refs of workbench: master(A) tags/v123
132 +# git push : refs/for/master/topic(A)
133 +test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porcelain)" '
134 + git -C workbench push --porcelain origin \
135 + HEAD:refs/for/master/topic \
136 + >out 2>&1 &&
137 + make_user_friendly_and_stable_output <out >actual &&
138 + cat >expect <<-EOF &&
139 + remote: # pre-receive hook
140 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
141 + remote: # proc-receive hook
142 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
143 + remote: proc-receive> ok refs/for/master/topic
144 + remote: proc-receive> option refname refs/changes/23/123/1
145 + remote: proc-receive> ok refs/for/master/topic
146 + remote: proc-receive> option refname refs/changes/24/124/2
147 + remote: proc-receive> option old-oid <COMMIT-A>
148 + remote: proc-receive> option new-oid <COMMIT-B>
149 + remote: # post-receive hook
150 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
151 + To <URL/of/upstream.git>
152 + * HEAD:refs/for/master/topic [new reference]
153 + Done
154 + EOF
155 + test_cmp expect actual &&
156 + git -C "$upstream" show-ref >out &&
157 + make_user_friendly_and_stable_output <out >actual &&
158 + cat >expect <<-EOF &&
159 + <COMMIT-A> refs/heads/master
160 + EOF
161 + test_cmp expect actual
162 +'
t/t5411/test-0038-report-mixed-refs.sh new
+89
@@ -0,0 +1,89 @@
1 +test_expect_success "setup proc-receive hook ($PROTOCOL)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/next/topic2" \
6 + -r "ng refs/for/next/topic1 fail to call Web API" \
7 + -r "ok refs/for/master/topic" \
8 + -r "option refname refs/for/master/topic" \
9 + -r "option old-oid $A" \
10 + -r "option new-oid $B"
11 + EOF
12 +'
13 +
14 +# Refs of upstream : master(A)
15 +# Refs of workbench: master(A) tags/v123
16 +# git push : (B) bar(A) baz(A) refs/for/next/topic(A) foo(A) refs/for/master/topic(A)
17 +test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
18 + test_must_fail git -C workbench push origin \
19 + $B:refs/heads/master \
20 + HEAD:refs/heads/bar \
21 + HEAD:refs/heads/baz \
22 + HEAD:refs/for/next/topic2 \
23 + HEAD:refs/for/next/topic1 \
24 + HEAD:refs/heads/foo \
25 + HEAD:refs/for/master/topic \
26 + HEAD:refs/for/next/topic3 \
27 + >out 2>&1 &&
28 + make_user_friendly_and_stable_output <out >actual &&
29 + cat >expect <<-EOF &&
30 + remote: # pre-receive hook
31 + remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
32 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
33 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
34 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
35 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic1
36 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
37 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
38 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic3
39 + remote: # proc-receive hook
40 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
41 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic1
42 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
43 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic3
44 + remote: proc-receive> ok refs/for/next/topic2
45 + remote: proc-receive> ng refs/for/next/topic1 fail to call Web API
46 + remote: proc-receive> ok refs/for/master/topic
47 + remote: proc-receive> option refname refs/for/master/topic
48 + remote: proc-receive> option old-oid <COMMIT-A>
49 + remote: proc-receive> option new-oid <COMMIT-B>
50 + remote: # post-receive hook
51 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
52 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
53 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
54 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
55 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
56 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
57 + To <URL/of/upstream.git>
58 + <OID-A>..<OID-B> <COMMIT-B> -> master
59 + * [new branch] HEAD -> bar
60 + * [new branch] HEAD -> baz
61 + * [new reference] HEAD -> refs/for/next/topic2
62 + * [new branch] HEAD -> foo
63 + * [new reference] HEAD -> refs/for/master/topic
64 + ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API)
65 + ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
66 + EOF
67 + test_cmp expect actual &&
68 + git -C "$upstream" show-ref >out &&
69 + make_user_friendly_and_stable_output <out >actual &&
70 + cat >expect <<-EOF &&
71 + <COMMIT-A> refs/heads/bar
72 + <COMMIT-A> refs/heads/baz
73 + <COMMIT-A> refs/heads/foo
74 + <COMMIT-B> refs/heads/master
75 + EOF
76 + test_cmp expect actual
77 +'
78 +
79 +# Refs of upstream : master(B) foo(A) bar(A)) baz(A)
80 +# Refs of workbench: master(A) tags/v123
81 +test_expect_success "cleanup ($PROTOCOL)" '
82 + (
83 + cd "$upstream" &&
84 + git update-ref refs/heads/master $A &&
85 + git update-ref -d refs/heads/foo &&
86 + git update-ref -d refs/heads/bar &&
87 + git update-ref -d refs/heads/baz
88 + )
89 +'
t/t5411/test-0039-report-mixed-refs--porcelain.sh new
+91
@@ -0,0 +1,91 @@
1 +test_expect_success "setup proc-receive hook ($PROTOCOL/porcelain)" '
2 + write_script "$upstream/hooks/proc-receive" <<-EOF
3 + printf >&2 "# proc-receive hook\n"
4 + test-tool proc-receive -v \
5 + -r "ok refs/for/next/topic2" \
6 + -r "ng refs/for/next/topic1 fail to call Web API" \
7 + -r "ok refs/for/master/topic" \
8 + -r "option refname refs/for/master/topic" \
9 + -r "option old-oid $A" \
10 + -r "option new-oid $B"
11 + EOF
12 +'
13 +
14 +# Refs of upstream : master(A)
15 +# Refs of workbench: master(A) tags/v123
16 +# git push : (B) bar(A) baz(A) refs/for/next/topic(A) foo(A) refs/for/master/topic(A)
17 +test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcelain)" '
18 + test_must_fail git -C workbench push --porcelain origin \
19 + $B:refs/heads/master \
20 + HEAD:refs/heads/bar \
21 + HEAD:refs/heads/baz \
22 + HEAD:refs/for/next/topic2 \
23 + HEAD:refs/for/next/topic1 \
24 + HEAD:refs/heads/foo \
25 + HEAD:refs/for/master/topic \
26 + HEAD:refs/for/next/topic3 \
27 + >out 2>&1 &&
28 + make_user_friendly_and_stable_output <out >actual &&
29 + cat >expect <<-EOF &&
30 + remote: # pre-receive hook
31 + remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
32 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
33 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
34 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
35 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic1
36 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
37 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
38 + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic3
39 + remote: # proc-receive hook
40 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
41 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic1
42 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
43 + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic3
44 + remote: proc-receive> ok refs/for/next/topic2
45 + remote: proc-receive> ng refs/for/next/topic1 fail to call Web API
46 + remote: proc-receive> ok refs/for/master/topic
47 + remote: proc-receive> option refname refs/for/master/topic
48 + remote: proc-receive> option old-oid <COMMIT-A>
49 + remote: proc-receive> option new-oid <COMMIT-B>
50 + remote: # post-receive hook
51 + remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
52 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/bar
53 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
54 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
55 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
56 + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
57 + To <URL/of/upstream.git>
58 + <COMMIT-B>:refs/heads/master <OID-A>..<OID-B>
59 + * HEAD:refs/heads/bar [new branch]
60 + * HEAD:refs/heads/baz [new branch]
61 + * HEAD:refs/for/next/topic2 [new reference]
62 + * HEAD:refs/heads/foo [new branch]
63 + * HEAD:refs/for/master/topic [new reference]
64 + ! HEAD:refs/for/next/topic1 [remote rejected] (fail to call Web API)
65 + ! HEAD:refs/for/next/topic3 [remote rejected] (proc-receive failed to report status)
66 + Done
67 + EOF
68 + test_cmp expect actual &&
69 + git -C "$upstream" show-ref >out &&
70 + make_user_friendly_and_stable_output <out >actual &&
71 + cat >expect <<-EOF &&
72 + <COMMIT-A> refs/heads/bar
73 + <COMMIT-A> refs/heads/baz
74 + <COMMIT-A> refs/heads/foo
75 + <COMMIT-B> refs/heads/master
76 + EOF
77 + test_cmp expect actual
78 +'
79 +
80 +# Refs of upstream : master(B) foo(A) bar(A)) baz(A)
81 +# Refs of workbench: master(A) tags/v123
82 +test_expect_success "cleanup ($PROTOCOL/porcelain)" '
83 + (
84 + cd "$upstream" &&
85 + git update-ref refs/heads/master $A &&
86 + git update-ref -d refs/heads/foo &&
87 + git update-ref -d refs/heads/bar &&
88 + git update-ref -d refs/heads/baz
89 + )
90 +
91 +'