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