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