filter-branch: Avoid an error message in the map function.
[git/git.git] / t / t5516-fetch-push.sh
CommitLineData
bcdb34f7
JH
1#!/bin/sh
2
3test_description='fetching and pushing, with or without wildcard'
4
5. ./test-lib.sh
6
7D=`pwd`
8
9mk_empty () {
10 rm -fr testrepo &&
11 mkdir testrepo &&
12 (
13 cd testrepo &&
14 git init
15 )
16}
17
6125796f
JH
18mk_test () {
19 mk_empty &&
20 (
21 for ref in "$@"
22 do
23 git push testrepo $the_first_commit:refs/$ref || {
24 echo "Oops, push refs/$ref failure"
25 exit 1
26 }
27 done &&
28 cd testrepo &&
29 for ref in "$@"
30 do
31 r=$(git show-ref -s --verify refs/$ref) &&
32 test "z$r" = "z$the_first_commit" || {
33 echo "Oops, refs/$ref is wrong"
34 exit 1
35 }
36 done &&
37 git fsck --full
38 )
39}
40
41check_push_result () {
42 (
43 cd testrepo &&
44 it="$1" &&
45 shift
46 for ref in "$@"
47 do
48 r=$(git show-ref -s --verify refs/$ref) &&
49 test "z$r" = "z$it" || {
50 echo "Oops, refs/$ref is wrong"
51 exit 1
52 }
53 done &&
54 git fsck --full
55 )
56}
57
bcdb34f7
JH
58test_expect_success setup '
59
60 : >path1 &&
61 git add path1 &&
62 test_tick &&
63 git commit -a -m repo &&
6125796f
JH
64 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
65
66 : >path2 &&
67 git add path2 &&
68 test_tick &&
69 git commit -a -m second &&
bcdb34f7
JH
70 the_commit=$(git show-ref -s --verify refs/heads/master)
71
72'
73
74test_expect_success 'fetch without wildcard' '
75 mk_empty &&
76 (
77 cd testrepo &&
78 git fetch .. refs/heads/master:refs/remotes/origin/master &&
79
80 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
81 test "z$r" = "z$the_commit" &&
82
83 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
84 )
85'
86
87test_expect_success 'fetch with wildcard' '
88 mk_empty &&
89 (
90 cd testrepo &&
91 git config remote.up.url .. &&
92 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
93 git fetch up &&
94
95 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
96 test "z$r" = "z$the_commit" &&
97
98 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
99 )
100'
101
102test_expect_success 'push without wildcard' '
103 mk_empty &&
104
105 git push testrepo refs/heads/master:refs/remotes/origin/master &&
106 (
107 cd testrepo &&
108 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
109 test "z$r" = "z$the_commit" &&
110
111 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
112 )
113'
114
115test_expect_success 'push with wildcard' '
116 mk_empty &&
117
118 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
119 (
120 cd testrepo &&
121 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
122 test "z$r" = "z$the_commit" &&
123
124 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
125 )
126'
127
6125796f
JH
128test_expect_success 'push with matching heads' '
129
130 mk_test heads/master &&
131 git push testrepo &&
132 check_push_result $the_commit heads/master
133
134'
135
136test_expect_success 'push with no ambiguity (1)' '
137
138 mk_test heads/master &&
139 git push testrepo master:master &&
140 check_push_result $the_commit heads/master
141
142'
143
144test_expect_success 'push with no ambiguity (2)' '
145
146 mk_test remotes/origin/master &&
147 git push testrepo master:master &&
148 check_push_result $the_commit remotes/origin/master
149
150'
151
152test_expect_success 'push with weak ambiguity (1)' '
153
154 mk_test heads/master remotes/origin/master &&
155 git push testrepo master:master &&
156 check_push_result $the_commit heads/master &&
157 check_push_result $the_first_commit remotes/origin/master
158
159'
160
161test_expect_success 'push with weak ambiguity (2)' '
162
163 mk_test heads/master remotes/origin/master remotes/another/master &&
164 git push testrepo master:master &&
165 check_push_result $the_commit heads/master &&
166 check_push_result $the_first_commit remotes/origin/master remotes/another/master
167
168'
169
170test_expect_success 'push with ambiguity (1)' '
171
172 mk_test remotes/origin/master remotes/frotz/master &&
173 if git push testrepo master:master
174 then
175 echo "Oops, should have failed"
176 false
177 else
178 check_push_result $the_first_commit remotes/origin/master remotes/frotz/master
179 fi
180'
181
182test_expect_success 'push with ambiguity (2)' '
183
184 mk_test heads/frotz tags/frotz &&
185 if git push testrepo master:frotz
186 then
187 echo "Oops, should have failed"
188 false
189 else
190 check_push_result $the_first_commit heads/frotz tags/frotz
191 fi
1ed10b88
JH
192
193'
194
195test_expect_success 'push with colon-less refspec (1)' '
196
197 mk_test heads/frotz tags/frotz &&
198 git branch -f frotz master &&
199 git push testrepo frotz &&
200 check_push_result $the_commit heads/frotz &&
201 check_push_result $the_first_commit tags/frotz
202
203'
204
205test_expect_success 'push with colon-less refspec (2)' '
206
207 mk_test heads/frotz tags/frotz &&
208 if git show-ref --verify -q refs/heads/frotz
209 then
210 git branch -D frotz
211 fi &&
212 git tag -f frotz &&
213 git push testrepo frotz &&
214 check_push_result $the_commit tags/frotz &&
215 check_push_result $the_first_commit heads/frotz
216
217'
218
219test_expect_success 'push with colon-less refspec (3)' '
220
221 mk_test &&
222 if git show-ref --verify -q refs/tags/frotz
223 then
224 git tag -d frotz
225 fi &&
226 git branch -f frotz master &&
227 git push testrepo frotz &&
228 check_push_result $the_commit heads/frotz &&
9a3c6f7b 229 test 1 = $( cd testrepo && git show-ref | wc -l )
1ed10b88
JH
230'
231
232test_expect_success 'push with colon-less refspec (4)' '
233
234 mk_test &&
235 if git show-ref --verify -q refs/heads/frotz
236 then
237 git branch -D frotz
238 fi &&
239 git tag -f frotz &&
240 git push testrepo frotz &&
241 check_push_result $the_commit tags/frotz &&
9a3c6f7b 242 test 1 = $( cd testrepo && git show-ref | wc -l )
1ed10b88 243
6125796f
JH
244'
245
bcdb34f7 246test_done