Merge branch 'ab/config-based-hooks-base' into seen
[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         format_and_save_expect <<-EOF &&
11         > remote: # pre-receive hook        Z
12         > remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main        Z
13         > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next        Z
14         > remote: # post-receive hook        Z
15         > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main        Z
16         > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next        Z
17         > To <URL/of/upstream.git>
18         >       <COMMIT-B>:refs/heads/main      <COMMIT-A>..<COMMIT-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         format_and_save_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         format_and_save_expect <<-EOF &&
69         > remote: # pre-receive hook        Z
70         > remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next        Z
71         > remote: # post-receive hook        Z
72         > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/next        Z
73         > To <URL/of/upstream.git>
74         >       <COMMIT-B>:refs/heads/next      <COMMIT-A>..<COMMIT-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         format_and_save_expect <<-EOF &&
99         > remote: # pre-receive hook        Z
100         > remote: pre-receive< <COMMIT-B> <COMMIT-A> refs/heads/main        Z
101         > remote: pre-receive< <COMMIT-B> <ZERO-OID> refs/heads/next        Z
102         > remote: pre-receive< <ZERO-OID> <TAG-v123> refs/tags/v123        Z
103         > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/review/main/topic        Z
104         > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/a/b/c        Z
105         > remote: # post-receive hook        Z
106         > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/heads/main        Z
107         > remote: post-receive< <COMMIT-B> <ZERO-OID> refs/heads/next        Z
108         > remote: post-receive< <ZERO-OID> <TAG-v123> refs/tags/v123        Z
109         > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/main/topic        Z
110         > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/a/b/c        Z
111         > To <URL/of/upstream.git>
112         > +     refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-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 '