Windows ANSI - hook write()
[git/mingw/4msysgit/peterh.git] / t / t5505-remote.sh
blob881efabd2bb7afef180f1d53d8eee402d87f1f41
1 #!/bin/sh
3 test_description='git remote porcelain-ish'
5 . ./test-lib.sh
7 setup_repository () {
8 mkdir "$1" && (
9 cd "$1" &&
10 git init &&
11 >file &&
12 git add file &&
13 test_tick &&
14 git commit -m "Initial" &&
15 git checkout -b side &&
16 >elif &&
17 git add elif &&
18 test_tick &&
19 git commit -m "Second" &&
20 git checkout master
24 tokens_match () {
25 echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
26 echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
27 test_cmp expect actual
30 check_remote_track () {
31 actual=$(git remote show "$1" | sed -n -e '$p') &&
32 shift &&
33 tokens_match "$*" "$actual"
36 check_tracking_branch () {
37 f="" &&
38 r=$(git for-each-ref "--format=%(refname)" |
39 sed -ne "s|^refs/remotes/$1/||p") &&
40 shift &&
41 tokens_match "$*" "$r"
44 test_expect_success setup '
46 setup_repository one &&
47 setup_repository two &&
49 cd two && git branch another
50 ) &&
51 git clone one test
55 test_expect_success 'remote information for the origin' '
57 cd test &&
58 tokens_match origin "$(git remote)" &&
59 check_remote_track origin master side &&
60 check_tracking_branch origin HEAD master side
64 test_expect_success 'add another remote' '
66 cd test &&
67 git remote add -f second ../two &&
68 tokens_match "origin second" "$(git remote)" &&
69 check_remote_track origin master side &&
70 check_remote_track second master side another &&
71 check_tracking_branch second master side another &&
72 git for-each-ref "--format=%(refname)" refs/remotes |
73 sed -e "/^refs\/remotes\/origin\//d" \
74 -e "/^refs\/remotes\/second\//d" >actual &&
75 >expect &&
76 test_cmp expect actual
80 test_expect_success 'remote forces tracking branches' '
82 cd test &&
83 case `git config remote.second.fetch` in
84 +*) true ;;
85 *) false ;;
86 esac
90 test_expect_success 'remove remote' '
92 cd test &&
93 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
94 git remote rm second
98 test_expect_success 'remove remote' '
100 cd test &&
101 tokens_match origin "$(git remote)" &&
102 check_remote_track origin master side &&
103 git for-each-ref "--format=%(refname)" refs/remotes |
104 sed -e "/^refs\/remotes\/origin\//d" >actual &&
105 >expect &&
106 test_cmp expect actual
110 case $(uname -s) in
111 *MINGW*) pwd() { builtin pwd -W; } ;;
112 esac
113 cat > test/expect << EOF
114 * remote origin
115 URL: $(pwd)/one/.git
116 Remote branch merged with 'git pull' while on branch master
117 master
118 New remote branch (next fetch will store in remotes/origin)
119 master
120 Tracked remote branches
121 side master
122 Local branches pushed with 'git push'
123 master:upstream +refs/tags/lastbackup
126 test_expect_success 'show' '
127 (cd test &&
128 git config --add remote.origin.fetch \
129 refs/heads/master:refs/heads/upstream &&
130 git fetch &&
131 git branch -d -r origin/master &&
132 (cd ../one &&
133 echo 1 > file &&
134 test_tick &&
135 git commit -m update file) &&
136 git config remote.origin.push \
137 refs/heads/master:refs/heads/upstream &&
138 git config --add remote.origin.push \
139 +refs/tags/lastbackup &&
140 git remote show origin > output &&
141 test_cmp expect output)
144 cat > test/expect << EOF
145 * remote origin
146 URL: $(pwd)/one/.git
147 Remote branch merged with 'git pull' while on branch master
148 master
149 Tracked remote branches
150 master side
151 Local branches pushed with 'git push'
152 master:upstream +refs/tags/lastbackup
155 test_expect_success 'show -n' '
156 (mv one one.unreachable &&
157 cd test &&
158 git remote show -n origin > output &&
159 mv ../one.unreachable ../one &&
160 test_cmp expect output)
163 test_expect_success 'prune' '
164 (cd one &&
165 git branch -m side side2) &&
166 (cd test &&
167 git fetch origin &&
168 git remote prune origin &&
169 git rev-parse refs/remotes/origin/side2 &&
170 ! git rev-parse refs/remotes/origin/side)
173 cat > test/expect << EOF
174 Pruning origin
175 URL: $(pwd)/one/.git
176 * [would prune] origin/side2
179 test_expect_success 'prune --dry-run' '
180 (cd one &&
181 git branch -m side2 side) &&
182 (cd test &&
183 git remote prune --dry-run origin > output &&
184 git rev-parse refs/remotes/origin/side2 &&
185 ! git rev-parse refs/remotes/origin/side &&
186 (cd ../one &&
187 git branch -m side side2) &&
188 test_cmp expect output)
191 test_expect_success 'add --mirror && prune' '
192 (mkdir mirror &&
193 cd mirror &&
194 git init &&
195 git remote add --mirror -f origin ../one) &&
196 (cd one &&
197 git branch -m side2 side) &&
198 (cd mirror &&
199 git rev-parse --verify refs/heads/side2 &&
200 ! git rev-parse --verify refs/heads/side &&
201 git fetch origin &&
202 git remote prune origin &&
203 ! git rev-parse --verify refs/heads/side2 &&
204 git rev-parse --verify refs/heads/side)
207 test_expect_success 'add alt && prune' '
208 (mkdir alttst &&
209 cd alttst &&
210 git init &&
211 git remote add -f origin ../one &&
212 git config remote.alt.url ../one &&
213 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
214 (cd one &&
215 git branch -m side side2) &&
216 (cd alttst &&
217 git rev-parse --verify refs/remotes/origin/side &&
218 ! git rev-parse --verify refs/remotes/origin/side2 &&
219 git fetch alt &&
220 git remote prune alt &&
221 ! git rev-parse --verify refs/remotes/origin/side &&
222 git rev-parse --verify refs/remotes/origin/side2)
225 cat > one/expect << EOF
226 apis/master
227 apis/side
228 drosophila/another
229 drosophila/master
230 drosophila/side
233 test_expect_success 'update' '
235 (cd one &&
236 git remote add drosophila ../two &&
237 git remote add apis ../mirror &&
238 git remote update &&
239 git branch -r > output &&
240 test_cmp expect output)
244 cat > one/expect << EOF
245 drosophila/another
246 drosophila/master
247 drosophila/side
248 manduca/master
249 manduca/side
250 megaloprepus/master
251 megaloprepus/side
254 test_expect_success 'update with arguments' '
256 (cd one &&
257 for b in $(git branch -r)
259 git branch -r -d $b || break
260 done &&
261 git remote add manduca ../mirror &&
262 git remote add megaloprepus ../mirror &&
263 git config remotes.phobaeticus "drosophila megaloprepus" &&
264 git config remotes.titanus manduca &&
265 git remote update phobaeticus titanus &&
266 git branch -r > output &&
267 test_cmp expect output)
271 cat > one/expect << EOF
272 apis/master
273 apis/side
274 manduca/master
275 manduca/side
276 megaloprepus/master
277 megaloprepus/side
280 test_expect_success 'update default' '
282 (cd one &&
283 for b in $(git branch -r)
285 git branch -r -d $b || break
286 done &&
287 git config remote.drosophila.skipDefaultUpdate true &&
288 git remote update default &&
289 git branch -r > output &&
290 test_cmp expect output)
294 cat > one/expect << EOF
295 drosophila/another
296 drosophila/master
297 drosophila/side
300 test_expect_success 'update default (overridden, with funny whitespace)' '
302 (cd one &&
303 for b in $(git branch -r)
305 git branch -r -d $b || break
306 done &&
307 git config remotes.default "$(printf "\t drosophila \n")" &&
308 git remote update default &&
309 git branch -r > output &&
310 test_cmp expect output)
314 test_expect_success '"remote show" does not show symbolic refs' '
316 git clone one three &&
317 (cd three &&
318 git remote show origin > output &&
319 ! grep HEAD < output &&
320 ! grep -i stale < output)
324 test_expect_success 'reject adding remote with an invalid name' '
326 ! git remote add some:url desired-name
330 test_done