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