3 test_description='fetching and pushing, with or without wildcard'
15 mv .git/hooks .git/hooks-disabled
24 git push testrepo $the_first_commit:refs/$ref || {
25 echo "Oops, push refs/$ref failure"
32 r=$(git show-ref -s --verify refs/$ref) &&
33 test "z$r" = "z$the_first_commit" || {
34 echo "Oops, refs/$ref is wrong"
42 check_push_result () {
49 r=$(git show-ref -s --verify refs/$ref) &&
50 test "z$r" = "z$it" || {
51 echo "Oops, refs/$ref is wrong"
59 test_expect_success setup '
64 git commit -a -m repo &&
65 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
70 git commit -a -m second &&
71 the_commit=$(git show-ref -s --verify refs/heads/master)
75 test_expect_success 'fetch without wildcard' '
79 git fetch .. refs/heads/master:refs/remotes/origin/master &&
81 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
82 test "z$r" = "z$the_commit" &&
84 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
88 test_expect_success 'fetch with wildcard' '
92 git config remote.up.url .. &&
93 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
96 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
97 test "z$r" = "z$the_commit" &&
99 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
103 test_expect_success 'fetch with insteadOf' '
108 git config url./$TRASH/.insteadOf trash/
109 git config remote.up.url trash/. &&
110 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
113 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
114 test "z$r" = "z$the_commit" &&
116 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
120 test_expect_success 'push without wildcard' '
123 git push testrepo refs/heads/master:refs/remotes/origin/master &&
126 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
127 test "z$r" = "z$the_commit" &&
129 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
133 test_expect_success 'push with wildcard' '
136 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
139 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
140 test "z$r" = "z$the_commit" &&
142 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
146 test_expect_success 'push with insteadOf' '
149 git config url./$TRASH/.insteadOf trash/ &&
150 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
153 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
154 test "z$r" = "z$the_commit" &&
156 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
160 test_expect_success 'push with matching heads' '
162 mk_test heads/master &&
164 check_push_result $the_commit heads/master
168 test_expect_success 'push with no ambiguity (1)' '
170 mk_test heads/master &&
171 git push testrepo master:master &&
172 check_push_result $the_commit heads/master
176 test_expect_success 'push with no ambiguity (2)' '
178 mk_test remotes/origin/master &&
179 git push testrepo master:origin/master &&
180 check_push_result $the_commit remotes/origin/master
184 test_expect_success 'push with colon-less refspec, no ambiguity' '
186 mk_test heads/master heads/t/master &&
187 git branch -f t/master master &&
188 git push testrepo master &&
189 check_push_result $the_commit heads/master &&
190 check_push_result $the_first_commit heads/t/master
194 test_expect_success 'push with weak ambiguity (1)' '
196 mk_test heads/master remotes/origin/master &&
197 git push testrepo master:master &&
198 check_push_result $the_commit heads/master &&
199 check_push_result $the_first_commit remotes/origin/master
203 test_expect_success 'push with weak ambiguity (2)' '
205 mk_test heads/master remotes/origin/master remotes/another/master &&
206 git push testrepo master:master &&
207 check_push_result $the_commit heads/master &&
208 check_push_result $the_first_commit remotes/origin/master remotes/another/master
212 test_expect_success 'push with ambiguity (1)' '
214 mk_test remotes/origin/master remotes/frotz/master &&
215 if git push testrepo master:master
217 echo "Oops, should have failed"
220 check_push_result $the_first_commit remotes/origin/master remotes/frotz/master
224 test_expect_success 'push with ambiguity (2)' '
226 mk_test heads/frotz tags/frotz &&
227 if git push testrepo master:frotz
229 echo "Oops, should have failed"
232 check_push_result $the_first_commit heads/frotz tags/frotz
237 test_expect_success 'push with colon-less refspec (1)' '
239 mk_test heads/frotz tags/frotz &&
240 git branch -f frotz master &&
241 git push testrepo frotz &&
242 check_push_result $the_commit heads/frotz &&
243 check_push_result $the_first_commit tags/frotz
247 test_expect_success 'push with colon-less refspec (2)' '
249 mk_test heads/frotz tags/frotz &&
250 if git show-ref --verify -q refs/heads/frotz
255 git push testrepo frotz &&
256 check_push_result $the_commit tags/frotz &&
257 check_push_result $the_first_commit heads/frotz
261 test_expect_success 'push with colon-less refspec (3)' '
264 if git show-ref --verify -q refs/tags/frotz
268 git branch -f frotz master &&
269 git push testrepo frotz &&
270 check_push_result $the_commit heads/frotz &&
271 test 1 = $( cd testrepo && git show-ref | wc -l )
274 test_expect_success 'push with colon-less refspec (4)' '
277 if git show-ref --verify -q refs/heads/frotz
282 git push testrepo frotz &&
283 check_push_result $the_commit tags/frotz &&
284 test 1 = $( cd testrepo && git show-ref | wc -l )
288 test_expect_success 'push with HEAD' '
290 mk_test heads/master &&
291 git checkout master &&
292 git push testrepo HEAD &&
293 check_push_result $the_commit heads/master
297 test_expect_success 'push with HEAD nonexisting at remote' '
299 mk_test heads/master &&
300 git checkout -b local master &&
301 git push testrepo HEAD &&
302 check_push_result $the_commit heads/local
305 test_expect_success 'push with dry-run' '
307 mk_test heads/master &&
309 old_commit=$(git show-ref -s --verify refs/heads/master)) &&
310 git push --dry-run testrepo &&
311 check_push_result $old_commit heads/master
314 test_expect_success 'push updates local refs' '
316 rm -rf parent child &&
318 (cd parent && git init &&
319 echo one >foo && git add foo && git commit -m one) &&
320 git clone parent child &&
322 echo two >foo && git commit -a -m two &&
324 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
328 test_expect_success 'push does not update local refs on failure' '
330 rm -rf parent child &&
332 (cd parent && git init &&
333 echo one >foo && git add foo && git commit -m one &&
334 echo exit 1 >.git/hooks/pre-receive &&
335 chmod +x .git/hooks/pre-receive) &&
336 git clone parent child &&
338 echo two >foo && git commit -a -m two &&
340 test $(git rev-parse master) != \
341 $(git rev-parse remotes/origin/master))
345 test_expect_success 'allow deleting an invalid remote ref' '
348 rm -f testrepo/.git/objects/??/* &&
349 git push testrepo :refs/heads/master &&
350 (cd testrepo && ! git rev-parse --verify refs/heads/master)