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: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
176 echo "Oops, should have failed"
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
188 echo "Oops, should have failed"
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
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)' '
223 if git show-ref --verify -q refs/tags/frotz
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)' '
236 if git show-ref --verify -q refs/heads/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_expect_success
'push with dry-run' '
249 mk_test heads/master &&
251 old_commit=$(git show-ref -s --verify refs/heads/master) &&
253 git push --dry-run testrepo &&
254 check_push_result $old_commit heads/master
257 test_expect_success
'push updates local refs' '
259 rm -rf parent child &&
260 mkdir parent && cd parent && git init &&
261 echo one >foo && git add foo && git commit -m one &&
263 git clone parent child && cd child &&
264 echo two >foo && git commit -a -m two &&
266 test $(git rev-parse master) = $(git rev-parse remotes/origin/master)
270 test_expect_success
'push does not update local refs on failure' '
272 rm -rf parent child &&
273 mkdir parent && cd parent && git init &&
274 echo one >foo && git add foo && git commit -m one &&
275 echo exit 1 >.git/hooks/pre-receive &&
276 chmod +x .git/hooks/pre-receive &&
278 git clone parent child && cd child &&
279 echo two >foo && git commit -a -m two || exit 1
281 test $(git rev-parse master) != $(git rev-parse remotes/origin/master)