Merge branch 'js/t4015-wo-master'
[git] / t / t5411 / test-0001-standard-git-push--porcelain.sh
1 # Refs of upstream : main(A)  
2 # Refs of workbench: main(A)  tags/v123
3 # git-push         : main(B)             next(A)
4 test_expect_success "git-push ($PROTOCOL/porcelain)" '
5         git -C workbench push --porcelain origin \
6                 $B:refs/heads/main \
7                 HEAD:refs/heads/next \
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< <COMMIT-A> <COMMIT-B> refs/heads/main
13         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
14         remote: # post-receive hook
15         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
16         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
17         To <URL/of/upstream.git>
18              <COMMIT-B>:refs/heads/main    <OID-A>..<OID-B>
19         *    HEAD:refs/heads/next    [new branch]
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-B> refs/heads/main
27         <COMMIT-A> refs/heads/next
28         EOF
29         test_cmp expect actual
30 '
31
32 # Refs of upstream : main(B)  next(A)
33 # Refs of workbench: main(A)           tags/v123
34 # git-push --atomic: main(A)  next(B)
35 test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
36         test_must_fail git -C workbench push --atomic --porcelain origin \
37                 main \
38                 $B:refs/heads/next \
39                 >out 2>&1 &&
40         filter_out_user_friendly_and_stable_output \
41                 -e "s/^# GETTEXT POISON #//" \
42                 -e "/^To / { p; }" \
43                 -e "/^! / { p; }" \
44                 <out >actual &&
45         cat >expect <<-EOF &&
46         To <URL/of/upstream.git>
47         !    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
48         !    <COMMIT-B>:refs/heads/next    [rejected] (atomic push failed)
49         EOF
50         test_cmp expect actual &&
51         git -C "$upstream" show-ref >out &&
52         make_user_friendly_and_stable_output <out >actual &&
53         cat >expect <<-EOF &&
54         <COMMIT-B> refs/heads/main
55         <COMMIT-A> refs/heads/next
56         EOF
57         test_cmp expect actual
58 '
59
60 # Refs of upstream : main(B)  next(A)
61 # Refs of workbench: main(A)           tags/v123
62 # git-push         : main(A)  next(B)
63 test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
64         test_must_fail git \
65                 -C workbench \
66                 -c advice.pushUpdateRejected=false \
67                 push --porcelain origin \
68                 main \
69                 $B:refs/heads/next \
70                 >out 2>&1 &&
71         make_user_friendly_and_stable_output <out >actual &&
72         cat >expect <<-EOF &&
73         remote: # pre-receive hook
74         remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next
75         remote: # post-receive hook
76         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/next
77         To <URL/of/upstream.git>
78              <COMMIT-B>:refs/heads/next    <OID-A>..<OID-B>
79         !    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
80         Done
81         EOF
82         test_cmp expect actual &&
83         git -C "$upstream" show-ref >out &&
84         make_user_friendly_and_stable_output <out >actual &&
85         cat >expect <<-EOF &&
86         <COMMIT-B> refs/heads/main
87         <COMMIT-B> refs/heads/next
88         EOF
89         test_cmp expect actual
90 '
91
92 # Refs of upstream : main(B)  next(B)
93 # Refs of workbench: main(A)           tags/v123
94 # git-push -f      : main(A)  NULL     tags/v123  refs/review/main/topic(A)  a/b/c(A)
95 test_expect_success "git-push -f ($PROTOCOL/porcelain)" '
96         git -C workbench push --porcelain -f origin \
97                 refs/tags/v123 \
98                 :refs/heads/next \
99                 main \
100                 main:refs/review/main/topic \
101                 HEAD:refs/heads/a/b/c \
102                 >out 2>&1 &&
103         make_user_friendly_and_stable_output <out >actual &&
104         cat >expect <<-EOF &&
105         remote: # pre-receive hook
106         remote: pre-receive< <COMMIT-B> <COMMIT-A> refs/heads/main
107         remote: pre-receive< <COMMIT-B> <ZERO-OID> refs/heads/next
108         remote: pre-receive< <ZERO-OID> <TAG-v123> refs/tags/v123
109         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/review/main/topic
110         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/a/b/c
111         remote: # post-receive hook
112         remote: post-receive< <COMMIT-B> <COMMIT-A> refs/heads/main
113         remote: post-receive< <COMMIT-B> <ZERO-OID> refs/heads/next
114         remote: post-receive< <ZERO-OID> <TAG-v123> refs/tags/v123
115         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/main/topic
116         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/a/b/c
117         To <URL/of/upstream.git>
118         +    refs/heads/main:refs/heads/main    <OID-B>...<OID-A> (forced update)
119         -    :refs/heads/next    [deleted]
120         *    refs/tags/v123:refs/tags/v123    [new tag]
121         *    refs/heads/main:refs/review/main/topic    [new reference]
122         *    HEAD:refs/heads/a/b/c    [new branch]
123         Done
124         EOF
125         test_cmp expect actual &&
126         git -C "$upstream" show-ref >out &&
127         make_user_friendly_and_stable_output <out >actual &&
128         cat >expect <<-EOF &&
129         <COMMIT-A> refs/heads/a/b/c
130         <COMMIT-A> refs/heads/main
131         <COMMIT-A> refs/review/main/topic
132         <TAG-v123> refs/tags/v123
133         EOF
134         test_cmp expect actual
135 '
136
137 # Refs of upstream : main(A)  tags/v123  refs/review/main/topic(A)  a/b/c(A)
138 # Refs of workbench: main(A)  tags/v123
139 test_expect_success "cleanup ($PROTOCOL/porcelain)" '
140         (
141                 cd "$upstream" &&
142                 git update-ref -d refs/review/main/topic &&
143                 git update-ref -d refs/tags/v123 &&
144                 git update-ref -d refs/heads/a/b/c
145         )
146 '