Merge branch 'mg/maint-difftool-vim-readonly' into maint
[git/jnareb-git.git] / t / t5517-push-mirror.sh
blobe2ad2605084194868fc23e23fec1636af622b47f
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 git config receive.denyCurrentBranch warn
24 ) &&
25 mkdir master &&
27 cd master &&
28 git init &&
29 git remote add $1 up ../mirror
34 # BRANCH tests
35 test_expect_success 'push mirror creates new branches' '
37 mk_repo_pair &&
39 cd master &&
40 echo one >foo && git add foo && git commit -m one &&
41 git push --mirror up
42 ) &&
43 master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
44 mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&
45 test "$master_master" = "$mirror_master"
49 test_expect_success 'push mirror updates existing branches' '
51 mk_repo_pair &&
53 cd master &&
54 echo one >foo && git add foo && git commit -m one &&
55 git push --mirror up &&
56 echo two >foo && git add foo && git commit -m two &&
57 git push --mirror up
58 ) &&
59 master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
60 mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&
61 test "$master_master" = "$mirror_master"
65 test_expect_success 'push mirror force updates existing branches' '
67 mk_repo_pair &&
69 cd master &&
70 echo one >foo && git add foo && git commit -m one &&
71 git push --mirror up &&
72 echo two >foo && git add foo && git commit -m two &&
73 git push --mirror up &&
74 git reset --hard HEAD^
75 git push --mirror up
76 ) &&
77 master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
78 mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&
79 test "$master_master" = "$mirror_master"
83 test_expect_success 'push mirror removes branches' '
85 mk_repo_pair &&
87 cd master &&
88 echo one >foo && git add foo && git commit -m one &&
89 git branch remove master &&
90 git push --mirror up &&
91 git branch -D remove
92 git push --mirror up
93 ) &&
95 cd mirror &&
96 invert git show-ref -s --verify refs/heads/remove
101 test_expect_success 'push mirror adds, updates and removes branches together' '
103 mk_repo_pair &&
105 cd master &&
106 echo one >foo && git add foo && git commit -m one &&
107 git branch remove master &&
108 git push --mirror up &&
109 git branch -D remove &&
110 git branch add master &&
111 echo two >foo && git add foo && git commit -m two &&
112 git push --mirror up
113 ) &&
114 master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
115 master_add=$(cd master && git show-ref -s --verify refs/heads/add) &&
116 mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&
117 mirror_add=$(cd mirror && git show-ref -s --verify refs/heads/add) &&
118 test "$master_master" = "$mirror_master" &&
119 test "$master_add" = "$mirror_add" &&
121 cd mirror &&
122 invert git show-ref -s --verify refs/heads/remove
128 # TAG tests
129 test_expect_success 'push mirror creates new tags' '
131 mk_repo_pair &&
133 cd master &&
134 echo one >foo && git add foo && git commit -m one &&
135 git tag -f tmaster master &&
136 git push --mirror up
137 ) &&
138 master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&
139 mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&
140 test "$master_master" = "$mirror_master"
144 test_expect_success 'push mirror updates existing tags' '
146 mk_repo_pair &&
148 cd master &&
149 echo one >foo && git add foo && git commit -m one &&
150 git tag -f tmaster master &&
151 git push --mirror up &&
152 echo two >foo && git add foo && git commit -m two &&
153 git tag -f tmaster master &&
154 git push --mirror up
155 ) &&
156 master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&
157 mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&
158 test "$master_master" = "$mirror_master"
162 test_expect_success 'push mirror force updates existing tags' '
164 mk_repo_pair &&
166 cd master &&
167 echo one >foo && git add foo && git commit -m one &&
168 git tag -f tmaster master &&
169 git push --mirror up &&
170 echo two >foo && git add foo && git commit -m two &&
171 git tag -f tmaster master &&
172 git push --mirror up &&
173 git reset --hard HEAD^
174 git tag -f tmaster master &&
175 git push --mirror up
176 ) &&
177 master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&
178 mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&
179 test "$master_master" = "$mirror_master"
183 test_expect_success 'push mirror removes tags' '
185 mk_repo_pair &&
187 cd master &&
188 echo one >foo && git add foo && git commit -m one &&
189 git tag -f tremove master &&
190 git push --mirror up &&
191 git tag -d tremove
192 git push --mirror up
193 ) &&
195 cd mirror &&
196 invert git show-ref -s --verify refs/tags/tremove
201 test_expect_success 'push mirror adds, updates and removes tags together' '
203 mk_repo_pair &&
205 cd master &&
206 echo one >foo && git add foo && git commit -m one &&
207 git tag -f tmaster master &&
208 git tag -f tremove master &&
209 git push --mirror up &&
210 git tag -d tremove &&
211 git tag tadd master &&
212 echo two >foo && git add foo && git commit -m two &&
213 git tag -f tmaster master &&
214 git push --mirror up
215 ) &&
216 master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&
217 master_add=$(cd master && git show-ref -s --verify refs/tags/tadd) &&
218 mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&
219 mirror_add=$(cd mirror && git show-ref -s --verify refs/tags/tadd) &&
220 test "$master_master" = "$mirror_master" &&
221 test "$master_add" = "$mirror_add" &&
223 cd mirror &&
224 invert git show-ref -s --verify refs/tags/tremove
229 test_expect_success 'remote.foo.mirror adds and removes branches' '
231 mk_repo_pair --mirror &&
233 cd master &&
234 echo one >foo && git add foo && git commit -m one &&
235 git branch keep master &&
236 git branch remove master &&
237 git push up &&
238 git branch -D remove
239 git push up
240 ) &&
242 cd mirror &&
243 git show-ref -s --verify refs/heads/keep &&
244 invert git show-ref -s --verify refs/heads/remove
249 test_expect_success 'remote.foo.mirror=no has no effect' '
251 mk_repo_pair &&
253 cd master &&
254 echo one >foo && git add foo && git commit -m one &&
255 git config --add remote.up.mirror no &&
256 git branch keep master &&
257 git push --mirror up &&
258 git branch -D keep &&
259 git push up
260 ) &&
262 cd mirror &&
263 git show-ref -s --verify refs/heads/keep
268 test_done