Merge branch 'jc/maint-am-keep'
[git/vmiklos.git] / t / t5517-push-mirror.sh
blobea49dedbf8867694d83cd550c8212ff107361920
1 #!/bin/sh
3 test_description='pushing to a mirror repository'
5 . ./test-lib.sh
7 D=`pwd`
9 invert () {
10 if "$@"; then
11 return 1
12 else
13 return 0
17 mk_repo_pair () {
18 rm -rf master mirror &&
19 mkdir mirror &&
21 cd mirror &&
22 git init
23 ) &&
24 mkdir master &&
26 cd master &&
27 git init &&
28 git remote add $1 up ../mirror
33 # BRANCH tests
34 test_expect_success 'push mirror creates new branches' '
36 mk_repo_pair &&
38 cd master &&
39 echo one >foo && git add foo && git commit -m one &&
40 git push --mirror up
41 ) &&
42 master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
43 mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&
44 test "$master_master" = "$mirror_master"
48 test_expect_success 'push mirror updates existing branches' '
50 mk_repo_pair &&
52 cd master &&
53 echo one >foo && git add foo && git commit -m one &&
54 git push --mirror up &&
55 echo two >foo && git add foo && git commit -m two &&
56 git push --mirror up
57 ) &&
58 master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
59 mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&
60 test "$master_master" = "$mirror_master"
64 test_expect_success 'push mirror force updates existing branches' '
66 mk_repo_pair &&
68 cd master &&
69 echo one >foo && git add foo && git commit -m one &&
70 git push --mirror up &&
71 echo two >foo && git add foo && git commit -m two &&
72 git push --mirror up &&
73 git reset --hard HEAD^
74 git push --mirror up
75 ) &&
76 master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
77 mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&
78 test "$master_master" = "$mirror_master"
82 test_expect_success 'push mirror removes branches' '
84 mk_repo_pair &&
86 cd master &&
87 echo one >foo && git add foo && git commit -m one &&
88 git branch remove master &&
89 git push --mirror up &&
90 git branch -D remove
91 git push --mirror up
92 ) &&
94 cd mirror &&
95 invert git show-ref -s --verify refs/heads/remove
100 test_expect_success 'push mirror adds, updates and removes branches together' '
102 mk_repo_pair &&
104 cd master &&
105 echo one >foo && git add foo && git commit -m one &&
106 git branch remove master &&
107 git push --mirror up &&
108 git branch -D remove &&
109 git branch add master &&
110 echo two >foo && git add foo && git commit -m two &&
111 git push --mirror up
112 ) &&
113 master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
114 master_add=$(cd master && git show-ref -s --verify refs/heads/add) &&
115 mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&
116 mirror_add=$(cd mirror && git show-ref -s --verify refs/heads/add) &&
117 test "$master_master" = "$mirror_master" &&
118 test "$master_add" = "$mirror_add" &&
120 cd mirror &&
121 invert git show-ref -s --verify refs/heads/remove
127 # TAG tests
128 test_expect_success 'push mirror creates new tags' '
130 mk_repo_pair &&
132 cd master &&
133 echo one >foo && git add foo && git commit -m one &&
134 git tag -f tmaster master &&
135 git push --mirror up
136 ) &&
137 master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&
138 mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&
139 test "$master_master" = "$mirror_master"
143 test_expect_success 'push mirror updates existing tags' '
145 mk_repo_pair &&
147 cd master &&
148 echo one >foo && git add foo && git commit -m one &&
149 git tag -f tmaster master &&
150 git push --mirror up &&
151 echo two >foo && git add foo && git commit -m two &&
152 git tag -f tmaster master &&
153 git push --mirror up
154 ) &&
155 master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&
156 mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&
157 test "$master_master" = "$mirror_master"
161 test_expect_success 'push mirror force updates existing tags' '
163 mk_repo_pair &&
165 cd master &&
166 echo one >foo && git add foo && git commit -m one &&
167 git tag -f tmaster master &&
168 git push --mirror up &&
169 echo two >foo && git add foo && git commit -m two &&
170 git tag -f tmaster master &&
171 git push --mirror up &&
172 git reset --hard HEAD^
173 git tag -f tmaster master &&
174 git push --mirror up
175 ) &&
176 master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&
177 mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&
178 test "$master_master" = "$mirror_master"
182 test_expect_success 'push mirror removes tags' '
184 mk_repo_pair &&
186 cd master &&
187 echo one >foo && git add foo && git commit -m one &&
188 git tag -f tremove master &&
189 git push --mirror up &&
190 git tag -d tremove
191 git push --mirror up
192 ) &&
194 cd mirror &&
195 invert git show-ref -s --verify refs/tags/tremove
200 test_expect_success 'push mirror adds, updates and removes tags together' '
202 mk_repo_pair &&
204 cd master &&
205 echo one >foo && git add foo && git commit -m one &&
206 git tag -f tmaster master &&
207 git tag -f tremove master &&
208 git push --mirror up &&
209 git tag -d tremove &&
210 git tag tadd master &&
211 echo two >foo && git add foo && git commit -m two &&
212 git tag -f tmaster master &&
213 git push --mirror up
214 ) &&
215 master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&
216 master_add=$(cd master && git show-ref -s --verify refs/tags/tadd) &&
217 mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&
218 mirror_add=$(cd mirror && git show-ref -s --verify refs/tags/tadd) &&
219 test "$master_master" = "$mirror_master" &&
220 test "$master_add" = "$mirror_add" &&
222 cd mirror &&
223 invert git show-ref -s --verify refs/tags/tremove
228 test_expect_success 'remote.foo.mirror adds and removes branches' '
230 mk_repo_pair --mirror &&
232 cd master &&
233 echo one >foo && git add foo && git commit -m one &&
234 git branch keep master &&
235 git branch remove master &&
236 git push up &&
237 git branch -D remove
238 git push up
239 ) &&
241 cd mirror &&
242 git show-ref -s --verify refs/heads/keep &&
243 invert git show-ref -s --verify refs/heads/remove
248 test_expect_success 'remote.foo.mirror=no has no effect' '
250 mk_repo_pair &&
252 cd master &&
253 echo one >foo && git add foo && git commit -m one &&
254 git config --add remote.up.mirror no &&
255 git branch keep master &&
256 git push --mirror up &&
257 git branch -D keep &&
258 git push up
259 ) &&
261 cd mirror &&
262 git show-ref -s --verify refs/heads/keep
267 test_done