]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5517-push-mirror.sh
The second batch
[thirdparty/git.git] / t / t5517-push-mirror.sh
1 #!/bin/sh
2
3 test_description='pushing to a mirror repository'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 D=$(pwd)
12
13 invert () {
14 if "$@"; then
15 return 1
16 else
17 return 0
18 fi
19 }
20
21 mk_repo_pair () {
22 rm -rf main mirror &&
23 mkdir mirror &&
24 (
25 cd mirror &&
26 git init &&
27 git config receive.denyCurrentBranch warn
28 ) &&
29 mkdir main &&
30 (
31 cd main &&
32 git init &&
33 git remote add $1 up ../mirror
34 )
35 }
36
37
38 # BRANCH tests
39 test_expect_success 'push mirror creates new branches' '
40
41 mk_repo_pair &&
42 (
43 cd main &&
44 echo one >foo && git add foo && git commit -m one &&
45 git push --mirror up
46 ) &&
47 main_main=$(cd main && git show-ref -s --verify refs/heads/main) &&
48 mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) &&
49 test "$main_main" = "$mirror_main"
50
51 '
52
53 test_expect_success 'push mirror updates existing branches' '
54
55 mk_repo_pair &&
56 (
57 cd main &&
58 echo one >foo && git add foo && git commit -m one &&
59 git push --mirror up &&
60 echo two >foo && git add foo && git commit -m two &&
61 git push --mirror up
62 ) &&
63 main_main=$(cd main && git show-ref -s --verify refs/heads/main) &&
64 mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) &&
65 test "$main_main" = "$mirror_main"
66
67 '
68
69 test_expect_success 'push mirror force updates existing branches' '
70
71 mk_repo_pair &&
72 (
73 cd main &&
74 echo one >foo && git add foo && git commit -m one &&
75 git push --mirror up &&
76 echo two >foo && git add foo && git commit -m two &&
77 git push --mirror up &&
78 git reset --hard HEAD^ &&
79 git push --mirror up
80 ) &&
81 main_main=$(cd main && git show-ref -s --verify refs/heads/main) &&
82 mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) &&
83 test "$main_main" = "$mirror_main"
84
85 '
86
87 test_expect_success 'push mirror removes branches' '
88
89 mk_repo_pair &&
90 (
91 cd main &&
92 echo one >foo && git add foo && git commit -m one &&
93 git branch remove main &&
94 git push --mirror up &&
95 git branch -D remove &&
96 git push --mirror up
97 ) &&
98 (
99 cd mirror &&
100 invert git show-ref -s --verify refs/heads/remove
101 )
102
103 '
104
105 test_expect_success 'push mirror adds, updates and removes branches together' '
106
107 mk_repo_pair &&
108 (
109 cd main &&
110 echo one >foo && git add foo && git commit -m one &&
111 git branch remove main &&
112 git push --mirror up &&
113 git branch -D remove &&
114 git branch add main &&
115 echo two >foo && git add foo && git commit -m two &&
116 git push --mirror up
117 ) &&
118 main_main=$(cd main && git show-ref -s --verify refs/heads/main) &&
119 main_add=$(cd main && git show-ref -s --verify refs/heads/add) &&
120 mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) &&
121 mirror_add=$(cd mirror && git show-ref -s --verify refs/heads/add) &&
122 test "$main_main" = "$mirror_main" &&
123 test "$main_add" = "$mirror_add" &&
124 (
125 cd mirror &&
126 invert git show-ref -s --verify refs/heads/remove
127 )
128
129 '
130
131
132 # TAG tests
133 test_expect_success 'push mirror creates new tags' '
134
135 mk_repo_pair &&
136 (
137 cd main &&
138 echo one >foo && git add foo && git commit -m one &&
139 git tag -f tmain main &&
140 git push --mirror up
141 ) &&
142 main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) &&
143 mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) &&
144 test "$main_main" = "$mirror_main"
145
146 '
147
148 test_expect_success 'push mirror updates existing tags' '
149
150 mk_repo_pair &&
151 (
152 cd main &&
153 echo one >foo && git add foo && git commit -m one &&
154 git tag -f tmain main &&
155 git push --mirror up &&
156 echo two >foo && git add foo && git commit -m two &&
157 git tag -f tmain main &&
158 git push --mirror up
159 ) &&
160 main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) &&
161 mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) &&
162 test "$main_main" = "$mirror_main"
163
164 '
165
166 test_expect_success 'push mirror force updates existing tags' '
167
168 mk_repo_pair &&
169 (
170 cd main &&
171 echo one >foo && git add foo && git commit -m one &&
172 git tag -f tmain main &&
173 git push --mirror up &&
174 echo two >foo && git add foo && git commit -m two &&
175 git tag -f tmain main &&
176 git push --mirror up &&
177 git reset --hard HEAD^ &&
178 git tag -f tmain main &&
179 git push --mirror up
180 ) &&
181 main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) &&
182 mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) &&
183 test "$main_main" = "$mirror_main"
184
185 '
186
187 test_expect_success 'push mirror removes tags' '
188
189 mk_repo_pair &&
190 (
191 cd main &&
192 echo one >foo && git add foo && git commit -m one &&
193 git tag -f tremove main &&
194 git push --mirror up &&
195 git tag -d tremove &&
196 git push --mirror up
197 ) &&
198 (
199 cd mirror &&
200 invert git show-ref -s --verify refs/tags/tremove
201 )
202
203 '
204
205 test_expect_success 'push mirror adds, updates and removes tags together' '
206
207 mk_repo_pair &&
208 (
209 cd main &&
210 echo one >foo && git add foo && git commit -m one &&
211 git tag -f tmain main &&
212 git tag -f tremove main &&
213 git push --mirror up &&
214 git tag -d tremove &&
215 git tag tadd main &&
216 echo two >foo && git add foo && git commit -m two &&
217 git tag -f tmain main &&
218 git push --mirror up
219 ) &&
220 main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) &&
221 main_add=$(cd main && git show-ref -s --verify refs/tags/tadd) &&
222 mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) &&
223 mirror_add=$(cd mirror && git show-ref -s --verify refs/tags/tadd) &&
224 test "$main_main" = "$mirror_main" &&
225 test "$main_add" = "$mirror_add" &&
226 (
227 cd mirror &&
228 invert git show-ref -s --verify refs/tags/tremove
229 )
230
231 '
232
233 test_expect_success 'remote.foo.mirror adds and removes branches' '
234
235 mk_repo_pair --mirror &&
236 (
237 cd main &&
238 echo one >foo && git add foo && git commit -m one &&
239 git branch keep main &&
240 git branch remove main &&
241 git push up &&
242 git branch -D remove &&
243 git push up
244 ) &&
245 (
246 cd mirror &&
247 git show-ref -s --verify refs/heads/keep &&
248 invert git show-ref -s --verify refs/heads/remove
249 )
250
251 '
252
253 test_expect_success 'remote.foo.mirror=no has no effect' '
254
255 mk_repo_pair &&
256 (
257 cd main &&
258 echo one >foo && git add foo && git commit -m one &&
259 git config --add remote.up.mirror no &&
260 git branch keep main &&
261 git push --mirror up &&
262 git branch -D keep &&
263 git push up :
264 ) &&
265 (
266 cd mirror &&
267 git show-ref -s --verify refs/heads/keep
268 )
269
270 '
271
272 test_expect_success 'push to mirrored repository with refspec fails' '
273 mk_repo_pair &&
274 (
275 cd main &&
276 echo one >foo && git add foo && git commit -m one &&
277 git config --add remote.up.mirror true &&
278 test_must_fail git push up main
279 )
280 '
281
282 test_done