Add zlib
[git/pclouds.git] / t / t5516-fetch-push.sh
blobca46aafe72fbf74d0569e68a0e7920655d98f9f5
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:master &&
149 check_push_result $the_commit remotes/origin/master
153 test_expect_success 'push with weak ambiguity (1)' '
155 mk_test heads/master remotes/origin/master &&
156 git push testrepo master:master &&
157 check_push_result $the_commit heads/master &&
158 check_push_result $the_first_commit remotes/origin/master
162 test_expect_success 'push with weak ambiguity (2)' '
164 mk_test heads/master remotes/origin/master remotes/another/master &&
165 git push testrepo master:master &&
166 check_push_result $the_commit heads/master &&
167 check_push_result $the_first_commit remotes/origin/master remotes/another/master
171 test_expect_success 'push with ambiguity (1)' '
173 mk_test remotes/origin/master remotes/frotz/master &&
174 if git push testrepo master:master
175 then
176 echo "Oops, should have failed"
177 false
178 else
179 check_push_result $the_first_commit remotes/origin/master remotes/frotz/master
183 test_expect_success 'push with ambiguity (2)' '
185 mk_test heads/frotz tags/frotz &&
186 if git push testrepo master:frotz
187 then
188 echo "Oops, should have failed"
189 false
190 else
191 check_push_result $the_first_commit heads/frotz tags/frotz
196 test_expect_success 'push with colon-less refspec (1)' '
198 mk_test heads/frotz tags/frotz &&
199 git branch -f frotz master &&
200 git push testrepo frotz &&
201 check_push_result $the_commit heads/frotz &&
202 check_push_result $the_first_commit tags/frotz
206 test_expect_success 'push with colon-less refspec (2)' '
208 mk_test heads/frotz tags/frotz &&
209 if git show-ref --verify -q refs/heads/frotz
210 then
211 git branch -D frotz
212 fi &&
213 git tag -f frotz &&
214 git push testrepo frotz &&
215 check_push_result $the_commit tags/frotz &&
216 check_push_result $the_first_commit heads/frotz
220 test_expect_success 'push with colon-less refspec (3)' '
222 mk_test &&
223 if git show-ref --verify -q refs/tags/frotz
224 then
225 git tag -d frotz
226 fi &&
227 git branch -f frotz master &&
228 git push testrepo frotz &&
229 check_push_result $the_commit heads/frotz &&
230 test 1 = $( cd testrepo && git show-ref | wc -l )
233 test_expect_success 'push with colon-less refspec (4)' '
235 mk_test &&
236 if git show-ref --verify -q refs/heads/frotz
237 then
238 git branch -D frotz
239 fi &&
240 git tag -f frotz &&
241 git push testrepo frotz &&
242 check_push_result $the_commit tags/frotz &&
243 test 1 = $( cd testrepo && git show-ref | wc -l )
247 test_done