Merge branch 'ab/config-based-hooks-base' into seen
[git] / t / t5411 / test-0037-report-multi-rewrite-for-one-ref--porcelain.sh
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/main/topic" \
6                 -r "option old-oid $A" \
7                 -r "option new-oid $B" \
8                 -r "ok refs/for/main/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/main/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 : main(A)
20 # Refs of workbench: main(A)  tags/v123
21 # git push         :                       refs/for/main/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/main/topic \
25                 >out 2>&1 &&
26         make_user_friendly_and_stable_output <out >actual &&
27         format_and_save_expect <<-EOF &&
28         > remote: # pre-receive hook        Z
29         > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic        Z
30         > remote: # proc-receive hook        Z
31         > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic        Z
32         > remote: proc-receive> ok refs/for/main/topic        Z
33         > remote: proc-receive> option old-oid <COMMIT-A>        Z
34         > remote: proc-receive> option new-oid <COMMIT-B>        Z
35         > remote: proc-receive> ok refs/for/main/topic        Z
36         > remote: proc-receive> option refname refs/changes/24/124/1        Z
37         > remote: proc-receive> option old-oid <ZERO-OID>        Z
38         > remote: proc-receive> option new-oid <COMMIT-A>        Z
39         > remote: proc-receive> ok refs/for/main/topic        Z
40         > remote: proc-receive> option refname refs/changes/25/125/1        Z
41         > remote: proc-receive> option old-oid <COMMIT-A>        Z
42         > remote: proc-receive> option new-oid <COMMIT-B>        Z
43         > remote: # post-receive hook        Z
44         > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic        Z
45         > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1        Z
46         > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1        Z
47         > To <URL/of/upstream.git>
48         >       HEAD:refs/for/main/topic        <COMMIT-A>..<COMMIT-B>
49         > *     HEAD:refs/changes/24/124/1      [new reference]
50         >       HEAD:refs/changes/25/125/1      <COMMIT-A>..<COMMIT-B>
51         > Done
52         EOF
53         test_cmp expect actual &&
54
55         test_cmp_refs -C "$upstream" <<-EOF
56         <COMMIT-A> refs/heads/main
57         EOF
58 '
59
60 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL/porcelain)" '
61         write_script "$upstream/hooks/proc-receive" <<-EOF
62         printf >&2 "# proc-receive hook\n"
63         test-tool proc-receive -v \
64                 -r "ok refs/for/main/topic" \
65                 -r "option refname refs/changes/24/124/1" \
66                 -r "option old-oid $ZERO_OID" \
67                 -r "option new-oid $A" \
68                 -r "ok refs/for/main/topic" \
69                 -r "option old-oid $A" \
70                 -r "option new-oid $B" \
71                 -r "ok refs/for/main/topic" \
72                 -r "option refname refs/changes/25/125/1" \
73                 -r "option old-oid $B" \
74                 -r "option new-oid $A" \
75                 -r "option forced-update"
76         EOF
77 '
78
79 # Refs of upstream : main(A)
80 # Refs of workbench: main(A)  tags/v123
81 # git push         :                       refs/for/main/topic(A)
82 test_expect_success "proc-receive: multiple rewrites for one ref, no refname for the 2nd rewrite ($PROTOCOL/porcelain)" '
83         git -C workbench push --porcelain origin \
84                 HEAD:refs/for/main/topic \
85                 >out 2>&1 &&
86         make_user_friendly_and_stable_output <out >actual &&
87         format_and_save_expect <<-EOF &&
88         > remote: # pre-receive hook        Z
89         > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic        Z
90         > remote: # proc-receive hook        Z
91         > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic        Z
92         > remote: proc-receive> ok refs/for/main/topic        Z
93         > remote: proc-receive> option refname refs/changes/24/124/1        Z
94         > remote: proc-receive> option old-oid <ZERO-OID>        Z
95         > remote: proc-receive> option new-oid <COMMIT-A>        Z
96         > remote: proc-receive> ok refs/for/main/topic        Z
97         > remote: proc-receive> option old-oid <COMMIT-A>        Z
98         > remote: proc-receive> option new-oid <COMMIT-B>        Z
99         > remote: proc-receive> ok refs/for/main/topic        Z
100         > remote: proc-receive> option refname refs/changes/25/125/1        Z
101         > remote: proc-receive> option old-oid <COMMIT-B>        Z
102         > remote: proc-receive> option new-oid <COMMIT-A>        Z
103         > remote: proc-receive> option forced-update        Z
104         > remote: # post-receive hook        Z
105         > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1        Z
106         > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic        Z
107         > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1        Z
108         > To <URL/of/upstream.git>
109         > *     HEAD:refs/changes/24/124/1      [new reference]
110         >       HEAD:refs/for/main/topic        <COMMIT-A>..<COMMIT-B>
111         > +     HEAD:refs/changes/25/125/1      <COMMIT-B>...<COMMIT-A> (forced update)
112         > Done
113         EOF
114         test_cmp expect actual &&
115
116         test_cmp_refs -C "$upstream" <<-EOF
117         <COMMIT-A> refs/heads/main
118         EOF
119 '
120
121 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL/porcelain)" '
122         write_script "$upstream/hooks/proc-receive" <<-EOF
123         printf >&2 "# proc-receive hook\n"
124         test-tool proc-receive -v \
125                 -r "ok refs/for/main/topic" \
126                 -r "option refname refs/changes/23/123/1" \
127                 -r "ok refs/for/main/topic" \
128                 -r "option refname refs/changes/24/124/2" \
129                 -r "option old-oid $A" \
130                 -r "option new-oid $B"
131         EOF
132 '
133
134 # Refs of upstream : main(A)
135 # Refs of workbench: main(A)  tags/v123
136 # git push         :                       refs/for/main/topic(A)
137 test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porcelain)" '
138         git -C workbench push --porcelain origin \
139                 HEAD:refs/for/main/topic \
140                 >out 2>&1 &&
141         make_user_friendly_and_stable_output <out >actual &&
142         format_and_save_expect <<-EOF &&
143         > remote: # pre-receive hook        Z
144         > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic        Z
145         > remote: # proc-receive hook        Z
146         > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic        Z
147         > remote: proc-receive> ok refs/for/main/topic        Z
148         > remote: proc-receive> option refname refs/changes/23/123/1        Z
149         > remote: proc-receive> ok refs/for/main/topic        Z
150         > remote: proc-receive> option refname refs/changes/24/124/2        Z
151         > remote: proc-receive> option old-oid <COMMIT-A>        Z
152         > remote: proc-receive> option new-oid <COMMIT-B>        Z
153         > remote: # post-receive hook        Z
154         > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1        Z
155         > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2        Z
156         > To <URL/of/upstream.git>
157         > *     HEAD:refs/changes/23/123/1      [new reference]
158         >       HEAD:refs/changes/24/124/2      <COMMIT-A>..<COMMIT-B>
159         > Done
160         EOF
161         test_cmp expect actual &&
162
163         test_cmp_refs -C "$upstream" <<-EOF
164         <COMMIT-A> refs/heads/main
165         EOF
166 '