Merge commit 'junio/next' into next
[git/platforms/storm.git] / t / t5505-remote.sh
blob0e1226137dcb1ddf540a8773ca3ecf50bb13b3c4
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="pwd -W";;
112 *) PWD=pwd;;
113 esac
114 cat > test/expect << EOF
115 * remote origin
116 URL: $($PWD)/one/.git
117 Remote branch merged with 'git pull' while on branch master
118 master
119 New remote branch (next fetch will store in remotes/origin)
120 master
121 Tracked remote branches
122 side master
123 Local branches pushed with 'git push'
124 master:upstream +refs/tags/lastbackup
127 test_expect_success 'show' '
128 (cd test &&
129 git config --add remote.origin.fetch \
130 refs/heads/master:refs/heads/upstream &&
131 git fetch &&
132 git branch -d -r origin/master &&
133 (cd ../one &&
134 echo 1 > file &&
135 test_tick &&
136 git commit -m update file) &&
137 git config remote.origin.push \
138 refs/heads/master:refs/heads/upstream &&
139 git config --add remote.origin.push \
140 +refs/tags/lastbackup &&
141 git remote show origin > output &&
142 git diff expect output)
145 test_expect_success 'prune' '
146 (cd one &&
147 git branch -m side side2) &&
148 (cd test &&
149 git fetch origin &&
150 git remote prune origin &&
151 git rev-parse refs/remotes/origin/side2 &&
152 ! git rev-parse refs/remotes/origin/side)
155 test_expect_success 'add --mirror && prune' '
156 (mkdir mirror &&
157 cd mirror &&
158 git init &&
159 git remote add --mirror -f origin ../one) &&
160 (cd one &&
161 git branch -m side2 side) &&
162 (cd mirror &&
163 git rev-parse --verify refs/heads/side2 &&
164 ! git rev-parse --verify refs/heads/side &&
165 git fetch origin &&
166 git remote prune origin &&
167 ! git rev-parse --verify refs/heads/side2 &&
168 git rev-parse --verify refs/heads/side)
171 cat > one/expect << EOF
172 apis/master
173 apis/side
174 drosophila/another
175 drosophila/master
176 drosophila/side
179 test_expect_success 'update' '
181 (cd one &&
182 git remote add drosophila ../two &&
183 git remote add apis ../mirror &&
184 git remote update &&
185 git branch -r > output &&
186 git diff expect output)
190 cat > one/expect << EOF
191 drosophila/another
192 drosophila/master
193 drosophila/side
194 manduca/master
195 manduca/side
196 megaloprepus/master
197 megaloprepus/side
200 test_expect_success 'update with arguments' '
202 (cd one &&
203 for b in $(git branch -r)
205 git branch -r -d $b || break
206 done &&
207 git remote add manduca ../mirror &&
208 git remote add megaloprepus ../mirror &&
209 git config remotes.phobaeticus "drosophila megaloprepus" &&
210 git config remotes.titanus manduca &&
211 git remote update phobaeticus titanus &&
212 git branch -r > output &&
213 git diff expect output)
217 cat > one/expect << EOF
218 apis/master
219 apis/side
220 manduca/master
221 manduca/side
222 megaloprepus/master
223 megaloprepus/side
226 test_expect_success 'update default' '
228 (cd one &&
229 for b in $(git branch -r)
231 git branch -r -d $b || break
232 done &&
233 git config remote.drosophila.skipDefaultUpdate true &&
234 git remote update default &&
235 git branch -r > output &&
236 git diff expect output)
240 cat > one/expect << EOF
241 drosophila/another
242 drosophila/master
243 drosophila/side
246 test_expect_success 'update default (overridden, with funny whitespace)' '
248 (cd one &&
249 for b in $(git branch -r)
251 git branch -r -d $b || break
252 done &&
253 git config remotes.default "$(printf "\t drosophila \n")" &&
254 git remote update default &&
255 git branch -r > output &&
256 git diff expect output)
260 test_expect_success '"remote show" does not show symbolic refs' '
262 git clone one three &&
263 (cd three &&
264 git remote show origin > output &&
265 ! grep HEAD < output &&
266 ! grep -i stale < output)
270 test_expect_success 'reject adding remote with an invalid name' '
272 ! git remote add some:url desired-name
276 test_done