3 test_description
='pushing to a mirror repository'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
26 git config receive.denyCurrentBranch warn
32 git remote add
$1 up ..
/mirror
38 test_expect_success
'push mirror creates new branches' '
43 echo one >foo && git add foo && git commit -m one &&
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' '
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 &&
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' '
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^ &&
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' '
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 &&
99 invert git show-ref -s --verify refs/heads/remove
104 test_expect_success
'push mirror adds, updates and removes branches together' '
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 &&
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" &&
125 invert git show-ref -s --verify refs/heads/remove
132 test_expect_success
'push mirror creates new tags' '
137 echo one >foo && git add foo && git commit -m one &&
138 git tag -f tmain main &&
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' '
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 &&
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' '
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 &&
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' '
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 &&
199 invert git show-ref -s --verify refs/tags/tremove
204 test_expect_success
'push mirror adds, updates and removes tags together' '
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 &&
215 echo two >foo && git add foo && git commit -m two &&
216 git tag -f tmain main &&
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" &&
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 &&
237 echo one >foo && git add foo && git commit -m one &&
238 git branch keep main &&
239 git branch remove main &&
241 git branch -D remove &&
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' '
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 &&
266 git show-ref -s --verify refs/heads/keep
271 test_expect_success
'push to mirrored repository with refspec fails' '
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