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
27 git config receive.denyCurrentBranch warn
33 git remote add
$1 up ..
/mirror
39 test_expect_success
'push mirror creates new branches' '
44 echo one >foo && git add foo && git commit -m one &&
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' '
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 &&
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' '
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^ &&
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' '
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 &&
100 invert git show-ref -s --verify refs/heads/remove
105 test_expect_success
'push mirror adds, updates and removes branches together' '
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 &&
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" &&
126 invert git show-ref -s --verify refs/heads/remove
133 test_expect_success
'push mirror creates new tags' '
138 echo one >foo && git add foo && git commit -m one &&
139 git tag -f tmain main &&
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' '
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 &&
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' '
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 &&
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' '
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 &&
200 invert git show-ref -s --verify refs/tags/tremove
205 test_expect_success
'push mirror adds, updates and removes tags together' '
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 &&
216 echo two >foo && git add foo && git commit -m two &&
217 git tag -f tmain main &&
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" &&
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 &&
238 echo one >foo && git add foo && git commit -m one &&
239 git branch keep main &&
240 git branch remove main &&
242 git branch -D remove &&
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' '
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 &&
267 git show-ref -s --verify refs/heads/keep
272 test_expect_success
'push to mirrored repository with refspec fails' '
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