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