Start the 2.46 cycle
[git/gitster.git] / t / t5517-push-mirror.sh
blob6d4944a72826401d3e698ad4c1b6982c4a233eae
1 #!/bin/sh
3 test_description='pushing to a mirror repository'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 D=$(pwd)
13 invert () {
14 if "$@"; then
15 return 1
16 else
17 return 0
21 mk_repo_pair () {
22 rm -rf main mirror &&
23 mkdir mirror &&
25 cd mirror &&
26 git init &&
27 git config receive.denyCurrentBranch warn
28 ) &&
29 mkdir main &&
31 cd main &&
32 git init &&
33 git remote add $1 up ../mirror
38 # BRANCH tests
39 test_expect_success 'push mirror creates new branches' '
41 mk_repo_pair &&
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"
53 test_expect_success 'push mirror updates existing branches' '
55 mk_repo_pair &&
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"
69 test_expect_success 'push mirror force updates existing branches' '
71 mk_repo_pair &&
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"
87 test_expect_success 'push mirror removes branches' '
89 mk_repo_pair &&
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 ) &&
99 cd mirror &&
100 invert git show-ref -s --verify refs/heads/remove
105 test_expect_success 'push mirror adds, updates and removes branches together' '
107 mk_repo_pair &&
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" &&
125 cd mirror &&
126 invert git show-ref -s --verify refs/heads/remove
132 # TAG tests
133 test_expect_success 'push mirror creates new tags' '
135 mk_repo_pair &&
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"
148 test_expect_success 'push mirror updates existing tags' '
150 mk_repo_pair &&
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"
166 test_expect_success 'push mirror force updates existing tags' '
168 mk_repo_pair &&
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"
187 test_expect_success 'push mirror removes tags' '
189 mk_repo_pair &&
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 ) &&
199 cd mirror &&
200 invert git show-ref -s --verify refs/tags/tremove
205 test_expect_success 'push mirror adds, updates and removes tags together' '
207 mk_repo_pair &&
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" &&
227 cd mirror &&
228 invert git show-ref -s --verify refs/tags/tremove
233 test_expect_success 'remote.foo.mirror adds and removes branches' '
235 mk_repo_pair --mirror &&
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 ) &&
246 cd mirror &&
247 git show-ref -s --verify refs/heads/keep &&
248 invert git show-ref -s --verify refs/heads/remove
253 test_expect_success 'remote.foo.mirror=no has no effect' '
255 mk_repo_pair &&
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 ) &&
266 cd mirror &&
267 git show-ref -s --verify refs/heads/keep
272 test_expect_success 'push to mirrored repository with refspec fails' '
273 mk_repo_pair &&
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
282 test_done