| 1 | test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL)" ' |
| 2 | test_hook -C "$upstream" --clobber 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 : main(A) |
| 11 | # Refs of workbench: main(A) tags/v123 |
| 12 | # git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/main/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/main/topic \ |
| 16 | >out-$test_count 2>&1 && |
| 17 | make_user_friendly_and_stable_output <out-$test_count >actual && |
| 18 | format_and_save_expect <<-EOF && |
| 19 | > remote: # pre-receive hook Z |
| 20 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 21 | > remote: # proc-receive hook Z |
| 22 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 23 | > remote: proc-receive> option refname refs/pull/123/head Z |
| 24 | > remote: proc-receive> option old-oid <COMMIT-B> Z |
| 25 | > remote: error: proc-receive reported "option" without a matching "ok/ng" directive Z |
| 26 | > To <URL/of/upstream.git> |
| 27 | > ! [remote rejected] HEAD -> refs/for/main/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 | test_hook -C "$upstream" --clobber proc-receive <<-\EOF |
| 34 | printf >&2 "# proc-receive hook\n" |
| 35 | test-tool proc-receive -v \ |
| 36 | -r "ok refs/for/main/topic" \ |
| 37 | -r "option refname refs/pull/123/head" |
| 38 | EOF |
| 39 | ' |
| 40 | |
| 41 | # Refs of upstream : main(A) |
| 42 | # Refs of workbench: main(A) tags/v123 |
| 43 | # git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/main/topic(A) |
| 44 | test_expect_success "proc-receive: report option refname ($PROTOCOL)" ' |
| 45 | git -C workbench push origin \ |
| 46 | HEAD:refs/for/main/topic \ |
| 47 | >out 2>&1 && |
| 48 | make_user_friendly_and_stable_output <out >actual && |
| 49 | format_and_save_expect <<-EOF && |
| 50 | > remote: # pre-receive hook Z |
| 51 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 52 | > remote: # proc-receive hook Z |
| 53 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 54 | > remote: proc-receive> ok refs/for/main/topic Z |
| 55 | > remote: proc-receive> option refname refs/pull/123/head Z |
| 56 | > remote: # post-receive hook Z |
| 57 | > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head Z |
| 58 | > To <URL/of/upstream.git> |
| 59 | > * [new reference] HEAD -> refs/pull/123/head |
| 60 | EOF |
| 61 | test_cmp expect actual |
| 62 | ' |
| 63 | |
| 64 | test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL)" ' |
| 65 | test_hook -C "$upstream" --clobber proc-receive <<-\EOF |
| 66 | printf >&2 "# proc-receive hook\n" |
| 67 | test-tool proc-receive -v \ |
| 68 | -r "ok refs/for/main/topic" \ |
| 69 | -r "option refname refs/pull/123/head" \ |
| 70 | -r "option forced-update" |
| 71 | EOF |
| 72 | ' |
| 73 | # Refs of upstream : main(A) |
| 74 | # Refs of workbench: main(A) tags/v123 |
| 75 | # git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/main/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/main/topic \ |
| 79 | >out 2>&1 && |
| 80 | make_user_friendly_and_stable_output <out >actual && |
| 81 | format_and_save_expect <<-EOF && |
| 82 | > remote: # pre-receive hook Z |
| 83 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 84 | > remote: # proc-receive hook Z |
| 85 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 86 | > remote: proc-receive> ok refs/for/main/topic Z |
| 87 | > remote: proc-receive> option refname refs/pull/123/head Z |
| 88 | > remote: proc-receive> option forced-update Z |
| 89 | > remote: # post-receive hook Z |
| 90 | > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head Z |
| 91 | > To <URL/of/upstream.git> |
| 92 | > * [new reference] HEAD -> refs/pull/123/head |
| 93 | EOF |
| 94 | test_cmp expect actual |
| 95 | ' |
| 96 | |
| 97 | test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL)" ' |
| 98 | test_hook -C "$upstream" --clobber proc-receive <<-EOF |
| 99 | printf >&2 "# proc-receive hook\n" |
| 100 | test-tool proc-receive -v \ |
| 101 | -r "ok refs/for/main/topic" \ |
| 102 | -r "option refname refs/pull/123/head" \ |
| 103 | -r "option old-oid $B" |
| 104 | EOF |
| 105 | ' |
| 106 | |
| 107 | # Refs of upstream : main(A) |
| 108 | # Refs of workbench: main(A) tags/v123 |
| 109 | # git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/main/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/main/topic \ |
| 113 | >out 2>&1 && |
| 114 | make_user_friendly_and_stable_output <out >actual && |
| 115 | format_and_save_expect <<-EOF && |
| 116 | > remote: # pre-receive hook Z |
| 117 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 118 | > remote: # proc-receive hook Z |
| 119 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 120 | > remote: proc-receive> ok refs/for/main/topic Z |
| 121 | > remote: proc-receive> option refname refs/pull/123/head Z |
| 122 | > remote: proc-receive> option old-oid <COMMIT-B> Z |
| 123 | > remote: # post-receive hook Z |
| 124 | > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head Z |
| 125 | > To <URL/of/upstream.git> |
| 126 | > <COMMIT-B>..<COMMIT-A> HEAD -> refs/pull/123/head |
| 127 | EOF |
| 128 | test_cmp expect actual |
| 129 | ' |
| 130 | |
| 131 | test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL)" ' |
| 132 | test_hook -C "$upstream" --clobber proc-receive <<-EOF |
| 133 | printf >&2 "# proc-receive hook\n" |
| 134 | test-tool proc-receive -v \ |
| 135 | -r "ok refs/for/main/topic" \ |
| 136 | -r "option old-oid $B" |
| 137 | EOF |
| 138 | ' |
| 139 | |
| 140 | # Refs of upstream : main(A) |
| 141 | # Refs of workbench: main(A) tags/v123 |
| 142 | # git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/main/topic(A) |
| 143 | test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" ' |
| 144 | git -C workbench push origin \ |
| 145 | HEAD:refs/for/main/topic \ |
| 146 | >out 2>&1 && |
| 147 | make_user_friendly_and_stable_output <out >actual && |
| 148 | format_and_save_expect <<-EOF && |
| 149 | > remote: # pre-receive hook Z |
| 150 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 151 | > remote: # proc-receive hook Z |
| 152 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 153 | > remote: proc-receive> ok refs/for/main/topic Z |
| 154 | > remote: proc-receive> option old-oid <COMMIT-B> Z |
| 155 | > remote: # post-receive hook Z |
| 156 | > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/main/topic Z |
| 157 | > To <URL/of/upstream.git> |
| 158 | > <COMMIT-B>..<COMMIT-A> HEAD -> refs/for/main/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 | test_hook -C "$upstream" --clobber proc-receive <<-EOF |
| 165 | printf >&2 "# proc-receive hook\n" |
| 166 | test-tool proc-receive -v \ |
| 167 | -r "ok refs/for/main/topic" \ |
| 168 | -r "option old-oid $A" \ |
| 169 | -r "option new-oid $B" |
| 170 | EOF |
| 171 | ' |
| 172 | |
| 173 | # Refs of upstream : main(A) |
| 174 | # Refs of workbench: main(A) tags/v123 |
| 175 | # git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/main/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/main/topic \ |
| 179 | >out 2>&1 && |
| 180 | make_user_friendly_and_stable_output <out >actual && |
| 181 | format_and_save_expect <<-EOF && |
| 182 | > remote: # pre-receive hook Z |
| 183 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 184 | > remote: # proc-receive hook Z |
| 185 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 186 | > remote: proc-receive> ok refs/for/main/topic Z |
| 187 | > remote: proc-receive> option old-oid <COMMIT-A> Z |
| 188 | > remote: proc-receive> option new-oid <COMMIT-B> Z |
| 189 | > remote: # post-receive hook Z |
| 190 | > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic Z |
| 191 | > To <URL/of/upstream.git> |
| 192 | > <COMMIT-A>..<COMMIT-B> HEAD -> refs/for/main/topic |
| 193 | EOF |
| 194 | test_cmp expect actual |
| 195 | ' |
| 196 | |
| 197 | test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL)" ' |
| 198 | test_hook -C "$upstream" --clobber 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/main/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 : main(A) |
| 213 | # Refs of workbench: main(A) tags/v123 |
| 214 | # git push : refs/for/next/topic(A) refs/for/a/b/c/topic(A) refs/for/main/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/main/topic \ |
| 220 | >out 2>&1 && |
| 221 | make_user_friendly_and_stable_output <out >actual && |
| 222 | format_and_save_expect <<-EOF && |
| 223 | > remote: # pre-receive hook Z |
| 224 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic Z |
| 225 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic Z |
| 226 | > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 227 | > remote: # proc-receive hook Z |
| 228 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic Z |
| 229 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic Z |
| 230 | > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z |
| 231 | > remote: proc-receive> ok refs/for/a/b/c/topic Z |
| 232 | > remote: proc-receive> ok refs/for/next/topic Z |
| 233 | > remote: proc-receive> option refname refs/pull/123/head Z |
| 234 | > remote: proc-receive> ok refs/for/main/topic Z |
| 235 | > remote: proc-receive> option refname refs/pull/124/head Z |
| 236 | > remote: proc-receive> option old-oid <COMMIT-B> Z |
| 237 | > remote: proc-receive> option forced-update Z |
| 238 | > remote: proc-receive> option new-oid <COMMIT-A> Z |
| 239 | > remote: # post-receive hook Z |
| 240 | > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head Z |
| 241 | > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic Z |
| 242 | > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head Z |
| 243 | > To <URL/of/upstream.git> |
| 244 | > * [new reference] HEAD -> refs/pull/123/head |
| 245 | > * [new reference] HEAD -> refs/for/a/b/c/topic |
| 246 | > + <COMMIT-B>...<COMMIT-A> HEAD -> refs/pull/124/head (forced update) |
| 247 | EOF |
| 248 | test_cmp expect actual && |
| 249 | |
| 250 | test_cmp_refs -C "$upstream" <<-EOF |
| 251 | <COMMIT-A> refs/heads/main |
| 252 | EOF |
| 253 | ' |