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