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