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 'push without wildcard' '
106 git push testrepo refs/heads/master:refs/remotes/origin/master &&
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' '
119 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
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 &&
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' '
183 mk_test heads/frotz tags/frotz &&
184 if git push testrepo master:frotz
186 echo "Oops, should have failed"
189 check_push_result $the_first_commit heads/frotz tags/frotz
194 test_expect_success 'push with colon-less refspec (1)' '
196 mk_test heads/frotz tags/frotz &&
197 git branch -f frotz master &&
198 git push testrepo frotz &&
199 check_push_result $the_commit heads/frotz &&
200 check_push_result $the_first_commit tags/frotz
204 test_expect_success 'push with colon-less refspec (2)' '
206 mk_test heads/frotz tags/frotz &&
207 if git show-ref --verify -q refs/heads/frotz
212 git push testrepo frotz &&
213 check_push_result $the_commit tags/frotz &&
214 check_push_result $the_first_commit heads/frotz
218 test_expect_success 'push with colon-less refspec (3)' '
221 if git show-ref --verify -q refs/tags/frotz
225 git branch -f frotz master &&
226 git push testrepo frotz &&
227 check_push_result $the_commit heads/frotz &&
228 test 1 = $( cd testrepo && git show-ref | wc -l )
231 test_expect_success 'push with colon-less refspec (4)' '
234 if git show-ref --verify -q refs/heads/frotz
239 git push testrepo frotz &&
240 check_push_result $the_commit tags/frotz &&
241 test 1 = $( cd testrepo && git show-ref | wc -l )
245 test_expect_success 'push with HEAD' '
247 mk_test heads/master &&
248 git checkout master &&
249 git push testrepo HEAD &&
250 check_push_result $the_commit heads/master
254 test_expect_success 'push with HEAD nonexisting at remote' '
256 mk_test heads/master &&
257 git checkout -b local master &&
258 git push testrepo HEAD &&
259 check_push_result $the_commit heads/local
262 test_expect_success 'push with dry-run' '
264 mk_test heads/master &&
266 old_commit=$(git show-ref -s --verify refs/heads/master)) &&
267 git push --dry-run testrepo &&
268 check_push_result $old_commit heads/master
271 test_expect_success 'push updates local refs' '
273 rm -rf parent child &&
275 (cd parent && git init &&
276 echo one >foo && git add foo && git commit -m one) &&
277 git clone parent child &&
279 echo two >foo && git commit -a -m two &&
281 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
285 test_expect_success 'push does not update local refs on failure' '
287 rm -rf parent child &&
289 (cd parent && git init &&
290 echo one >foo && git add foo && git commit -m one &&
291 echo exit 1 >.git/hooks/pre-receive &&
292 chmod +x .git/hooks/pre-receive) &&
293 git clone parent child &&
295 echo two >foo && git commit -a -m two &&
297 test $(git rev-parse master) != \
298 $(git rev-parse remotes/origin/master))
302 test_expect_success 'allow deleting an invalid remote ref' '
305 rm -f testrepo/.git/objects/??/* &&
306 git push testrepo :refs/heads/master &&
307 (cd testrepo && ! git rev-parse --verify refs/heads/master)