rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t5517-push-mirror.sh
bloba448e169bd029f21ec77cd89dc087c8e637578f8
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-lib.sh
10 D=$(pwd)
12 invert () {
13 if "$@"; then
14 return 1
15 else
16 return 0
20 mk_repo_pair () {
21 rm -rf main mirror &&
22 mkdir mirror &&
24 cd mirror &&
25 git init &&
26 git config receive.denyCurrentBranch warn
27 ) &&
28 mkdir main &&
30 cd main &&
31 git init &&
32 git remote add $1 up ../mirror
37 # BRANCH tests
38 test_expect_success 'push mirror creates new branches' '
40 mk_repo_pair &&
42 cd main &&
43 echo one >foo && git add foo && git commit -m one &&
44 git push --mirror up
45 ) &&
46 main_main=$(cd main && git show-ref -s --verify refs/heads/main) &&
47 mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) &&
48 test "$main_main" = "$mirror_main"
52 test_expect_success 'push mirror updates existing branches' '
54 mk_repo_pair &&
56 cd main &&
57 echo one >foo && git add foo && git commit -m one &&
58 git push --mirror up &&
59 echo two >foo && git add foo && git commit -m two &&
60 git push --mirror up
61 ) &&
62 main_main=$(cd main && git show-ref -s --verify refs/heads/main) &&
63 mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) &&
64 test "$main_main" = "$mirror_main"
68 test_expect_success 'push mirror force updates existing branches' '
70 mk_repo_pair &&
72 cd main &&
73 echo one >foo && git add foo && git commit -m one &&
74 git push --mirror up &&
75 echo two >foo && git add foo && git commit -m two &&
76 git push --mirror up &&
77 git reset --hard HEAD^ &&
78 git push --mirror up
79 ) &&
80 main_main=$(cd main && git show-ref -s --verify refs/heads/main) &&
81 mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) &&
82 test "$main_main" = "$mirror_main"
86 test_expect_success 'push mirror removes branches' '
88 mk_repo_pair &&
90 cd main &&
91 echo one >foo && git add foo && git commit -m one &&
92 git branch remove main &&
93 git push --mirror up &&
94 git branch -D remove &&
95 git push --mirror up
96 ) &&
98 cd mirror &&
99 invert git show-ref -s --verify refs/heads/remove
104 test_expect_success 'push mirror adds, updates and removes branches together' '
106 mk_repo_pair &&
108 cd main &&
109 echo one >foo && git add foo && git commit -m one &&
110 git branch remove main &&
111 git push --mirror up &&
112 git branch -D remove &&
113 git branch add main &&
114 echo two >foo && git add foo && git commit -m two &&
115 git push --mirror up
116 ) &&
117 main_main=$(cd main && git show-ref -s --verify refs/heads/main) &&
118 main_add=$(cd main && git show-ref -s --verify refs/heads/add) &&
119 mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) &&
120 mirror_add=$(cd mirror && git show-ref -s --verify refs/heads/add) &&
121 test "$main_main" = "$mirror_main" &&
122 test "$main_add" = "$mirror_add" &&
124 cd mirror &&
125 invert git show-ref -s --verify refs/heads/remove
131 # TAG tests
132 test_expect_success 'push mirror creates new tags' '
134 mk_repo_pair &&
136 cd main &&
137 echo one >foo && git add foo && git commit -m one &&
138 git tag -f tmain main &&
139 git push --mirror up
140 ) &&
141 main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) &&
142 mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) &&
143 test "$main_main" = "$mirror_main"
147 test_expect_success 'push mirror updates existing tags' '
149 mk_repo_pair &&
151 cd main &&
152 echo one >foo && git add foo && git commit -m one &&
153 git tag -f tmain main &&
154 git push --mirror up &&
155 echo two >foo && git add foo && git commit -m two &&
156 git tag -f tmain main &&
157 git push --mirror up
158 ) &&
159 main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) &&
160 mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) &&
161 test "$main_main" = "$mirror_main"
165 test_expect_success 'push mirror force updates existing tags' '
167 mk_repo_pair &&
169 cd main &&
170 echo one >foo && git add foo && git commit -m one &&
171 git tag -f tmain main &&
172 git push --mirror up &&
173 echo two >foo && git add foo && git commit -m two &&
174 git tag -f tmain main &&
175 git push --mirror up &&
176 git reset --hard HEAD^ &&
177 git tag -f tmain main &&
178 git push --mirror up
179 ) &&
180 main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) &&
181 mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) &&
182 test "$main_main" = "$mirror_main"
186 test_expect_success 'push mirror removes tags' '
188 mk_repo_pair &&
190 cd main &&
191 echo one >foo && git add foo && git commit -m one &&
192 git tag -f tremove main &&
193 git push --mirror up &&
194 git tag -d tremove &&
195 git push --mirror up
196 ) &&
198 cd mirror &&
199 invert git show-ref -s --verify refs/tags/tremove
204 test_expect_success 'push mirror adds, updates and removes tags together' '
206 mk_repo_pair &&
208 cd main &&
209 echo one >foo && git add foo && git commit -m one &&
210 git tag -f tmain main &&
211 git tag -f tremove main &&
212 git push --mirror up &&
213 git tag -d tremove &&
214 git tag tadd main &&
215 echo two >foo && git add foo && git commit -m two &&
216 git tag -f tmain main &&
217 git push --mirror up
218 ) &&
219 main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) &&
220 main_add=$(cd main && git show-ref -s --verify refs/tags/tadd) &&
221 mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) &&
222 mirror_add=$(cd mirror && git show-ref -s --verify refs/tags/tadd) &&
223 test "$main_main" = "$mirror_main" &&
224 test "$main_add" = "$mirror_add" &&
226 cd mirror &&
227 invert git show-ref -s --verify refs/tags/tremove
232 test_expect_success 'remote.foo.mirror adds and removes branches' '
234 mk_repo_pair --mirror &&
236 cd main &&
237 echo one >foo && git add foo && git commit -m one &&
238 git branch keep main &&
239 git branch remove main &&
240 git push up &&
241 git branch -D remove &&
242 git push up
243 ) &&
245 cd mirror &&
246 git show-ref -s --verify refs/heads/keep &&
247 invert git show-ref -s --verify refs/heads/remove
252 test_expect_success 'remote.foo.mirror=no has no effect' '
254 mk_repo_pair &&
256 cd main &&
257 echo one >foo && git add foo && git commit -m one &&
258 git config --add remote.up.mirror no &&
259 git branch keep main &&
260 git push --mirror up &&
261 git branch -D keep &&
262 git push up :
263 ) &&
265 cd mirror &&
266 git show-ref -s --verify refs/heads/keep
271 test_expect_success 'push to mirrored repository with refspec fails' '
272 mk_repo_pair &&
274 cd main &&
275 echo one >foo && git add foo && git commit -m one &&
276 git config --add remote.up.mirror true &&
277 test_must_fail git push up main
281 test_done