Resolve value supplied for no-colon push refspecs
[git/dscho.git] / t / t5516-fetch-push.sh
blobb0d97db71c5ebeaecb019e0443ac10cb2c173361
1 #!/bin/sh
3 test_description='fetching and pushing, with or without wildcard'
5 . ./test-lib.sh
7 D=`pwd`
9 mk_empty () {
10 rm -fr testrepo &&
11 mkdir testrepo &&
13 cd testrepo &&
14 git init &&
15 mv .git/hooks .git/hooks-disabled
19 mk_test () {
20 mk_empty &&
22 for ref in "$@"
24 git push testrepo $the_first_commit:refs/$ref || {
25 echo "Oops, push refs/$ref failure"
26 exit 1
28 done &&
29 cd testrepo &&
30 for ref in "$@"
32 r=$(git show-ref -s --verify refs/$ref) &&
33 test "z$r" = "z$the_first_commit" || {
34 echo "Oops, refs/$ref is wrong"
35 exit 1
37 done &&
38 git fsck --full
42 check_push_result () {
44 cd testrepo &&
45 it="$1" &&
46 shift
47 for ref in "$@"
49 r=$(git show-ref -s --verify refs/$ref) &&
50 test "z$r" = "z$it" || {
51 echo "Oops, refs/$ref is wrong"
52 exit 1
54 done &&
55 git fsck --full
59 test_expect_success setup '
61 : >path1 &&
62 git add path1 &&
63 test_tick &&
64 git commit -a -m repo &&
65 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
67 : >path2 &&
68 git add path2 &&
69 test_tick &&
70 git commit -a -m second &&
71 the_commit=$(git show-ref -s --verify refs/heads/master)
75 test_expect_success 'fetch without wildcard' '
76 mk_empty &&
78 cd testrepo &&
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' '
89 mk_empty &&
91 cd testrepo &&
92 git config remote.up.url .. &&
93 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
94 git fetch up &&
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 'push without wildcard' '
104 mk_empty &&
106 git push testrepo refs/heads/master:refs/remotes/origin/master &&
108 cd testrepo &&
109 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
110 test "z$r" = "z$the_commit" &&
112 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
116 test_expect_success 'push with wildcard' '
117 mk_empty &&
119 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
121 cd testrepo &&
122 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
123 test "z$r" = "z$the_commit" &&
125 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
129 test_expect_success 'push with matching heads' '
131 mk_test heads/master &&
132 git push testrepo &&
133 check_push_result $the_commit heads/master
137 test_expect_success 'push with no ambiguity (1)' '
139 mk_test heads/master &&
140 git push testrepo master:master &&
141 check_push_result $the_commit heads/master
145 test_expect_success 'push with no ambiguity (2)' '
147 mk_test remotes/origin/master &&
148 git push testrepo master:origin/master &&
149 check_push_result $the_commit remotes/origin/master
153 test_expect_success 'push with colon-less refspec, no ambiguity' '
155 mk_test heads/master heads/t/master &&
156 git branch -f t/master master &&
157 git push testrepo master &&
158 check_push_result $the_commit heads/master &&
159 check_push_result $the_first_commit heads/t/master
163 test_expect_success 'push with weak ambiguity (1)' '
165 mk_test heads/master remotes/origin/master &&
166 git push testrepo master:master &&
167 check_push_result $the_commit heads/master &&
168 check_push_result $the_first_commit remotes/origin/master
172 test_expect_success 'push with weak ambiguity (2)' '
174 mk_test heads/master remotes/origin/master remotes/another/master &&
175 git push testrepo master:master &&
176 check_push_result $the_commit heads/master &&
177 check_push_result $the_first_commit remotes/origin/master remotes/another/master
181 test_expect_success 'push with ambiguity (1)' '
183 mk_test remotes/origin/master remotes/frotz/master &&
184 if git push testrepo master:master
185 then
186 echo "Oops, should have failed"
187 false
188 else
189 check_push_result $the_first_commit remotes/origin/master remotes/frotz/master
193 test_expect_success 'push with ambiguity (2)' '
195 mk_test heads/frotz tags/frotz &&
196 if git push testrepo master:frotz
197 then
198 echo "Oops, should have failed"
199 false
200 else
201 check_push_result $the_first_commit heads/frotz tags/frotz
206 test_expect_success 'push with colon-less refspec (1)' '
208 mk_test heads/frotz tags/frotz &&
209 git branch -f frotz master &&
210 git push testrepo frotz &&
211 check_push_result $the_commit heads/frotz &&
212 check_push_result $the_first_commit tags/frotz
216 test_expect_success 'push with colon-less refspec (2)' '
218 mk_test heads/frotz tags/frotz &&
219 if git show-ref --verify -q refs/heads/frotz
220 then
221 git branch -D frotz
222 fi &&
223 git tag -f frotz &&
224 git push testrepo frotz &&
225 check_push_result $the_commit tags/frotz &&
226 check_push_result $the_first_commit heads/frotz
230 test_expect_success 'push with colon-less refspec (3)' '
232 mk_test &&
233 if git show-ref --verify -q refs/tags/frotz
234 then
235 git tag -d frotz
236 fi &&
237 git branch -f frotz master &&
238 git push testrepo frotz &&
239 check_push_result $the_commit heads/frotz &&
240 test 1 = $( cd testrepo && git show-ref | wc -l )
243 test_expect_success 'push with colon-less refspec (4)' '
245 mk_test &&
246 if git show-ref --verify -q refs/heads/frotz
247 then
248 git branch -D frotz
249 fi &&
250 git tag -f frotz &&
251 git push testrepo frotz &&
252 check_push_result $the_commit tags/frotz &&
253 test 1 = $( cd testrepo && git show-ref | wc -l )
257 test_expect_success 'push with HEAD' '
259 mk_test heads/master &&
260 git checkout master &&
261 git push testrepo HEAD &&
262 check_push_result $the_commit heads/master
266 test_expect_success 'push with HEAD nonexisting at remote' '
268 mk_test heads/master &&
269 git checkout -b local master &&
270 git push testrepo HEAD &&
271 check_push_result $the_commit heads/local
274 test_expect_success 'push with +HEAD' '
276 mk_test heads/master &&
277 git checkout master &&
278 git branch -D local &&
279 git checkout -b local &&
280 git push testrepo master local &&
281 check_push_result $the_commit heads/master &&
282 check_push_result $the_commit heads/local &&
284 # Without force rewinding should fail
285 git reset --hard HEAD^ &&
286 ! git push testrepo HEAD &&
287 check_push_result $the_commit heads/local &&
289 # With force rewinding should succeed
290 git push testrepo +HEAD &&
291 check_push_result $the_first_commit heads/local
295 test_expect_success 'push with config remote.*.push = HEAD' '
297 mk_test heads/local &&
298 git checkout master &&
299 git branch -f local $the_commit &&
301 cd testrepo &&
302 git checkout local &&
303 git reset --hard $the_first_commit
304 ) &&
305 git config remote.there.url testrepo &&
306 git config remote.there.push HEAD &&
307 git config branch.master.remote there &&
308 git push &&
309 check_push_result $the_commit heads/master &&
310 check_push_result $the_first_commit heads/local
313 # clean up the cruft left with the previous one
314 git config --remove-section remote.there
315 git config --remove-section branch.master
317 test_expect_success 'push with dry-run' '
319 mk_test heads/master &&
320 (cd testrepo &&
321 old_commit=$(git show-ref -s --verify refs/heads/master)) &&
322 git push --dry-run testrepo &&
323 check_push_result $old_commit heads/master
326 test_expect_success 'push updates local refs' '
328 rm -rf parent child &&
329 mkdir parent &&
330 (cd parent && git init &&
331 echo one >foo && git add foo && git commit -m one) &&
332 git clone parent child &&
333 (cd child &&
334 echo two >foo && git commit -a -m two &&
335 git push &&
336 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
340 test_expect_success 'push does not update local refs on failure' '
342 rm -rf parent child &&
343 mkdir parent &&
344 (cd parent && git init &&
345 echo one >foo && git add foo && git commit -m one &&
346 echo exit 1 >.git/hooks/pre-receive &&
347 chmod +x .git/hooks/pre-receive) &&
348 git clone parent child &&
349 (cd child &&
350 echo two >foo && git commit -a -m two &&
351 ! git push &&
352 test $(git rev-parse master) != \
353 $(git rev-parse remotes/origin/master))
357 test_expect_success 'allow deleting an invalid remote ref' '
359 pwd &&
360 rm -f testrepo/.git/objects/??/* &&
361 git push testrepo :refs/heads/master &&
362 (cd testrepo && ! git rev-parse --verify refs/heads/master)
366 test_done