]>
Commit | Line | Data |
---|---|---|
683b5679 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git remote porcelain-ish' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
683b5679 JH |
7 | setup_repository () { |
8 | mkdir "$1" && ( | |
9 | cd "$1" && | |
10 | git init && | |
11 | >file && | |
12 | git add file && | |
84521ed6 | 13 | test_tick && |
683b5679 JH |
14 | git commit -m "Initial" && |
15 | git checkout -b side && | |
16 | >elif && | |
17 | git add elif && | |
84521ed6 | 18 | test_tick && |
683b5679 JH |
19 | git commit -m "Second" && |
20 | git checkout master | |
21 | ) | |
22 | } | |
23 | ||
24 | tokens_match () { | |
25 | echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect && | |
26 | echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual && | |
82ebb0b6 | 27 | test_cmp expect actual |
683b5679 JH |
28 | } |
29 | ||
30 | check_remote_track () { | |
31 | actual=$(git remote show "$1" | sed -n -e '$p') && | |
32 | shift && | |
33 | tokens_match "$*" "$actual" | |
34 | } | |
35 | ||
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" | |
42 | } | |
43 | ||
44 | test_expect_success setup ' | |
45 | ||
46 | setup_repository one && | |
47 | setup_repository two && | |
48 | ( | |
49 | cd two && git branch another | |
50 | ) && | |
51 | git clone one test | |
52 | ||
53 | ' | |
54 | ||
55 | test_expect_success 'remote information for the origin' ' | |
56 | ( | |
57 | cd test && | |
58 | tokens_match origin "$(git remote)" && | |
59 | check_remote_track origin master side && | |
60 | check_tracking_branch origin HEAD master side | |
61 | ) | |
62 | ' | |
63 | ||
64 | test_expect_success 'add another remote' ' | |
65 | ( | |
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 && | |
82ebb0b6 | 76 | test_cmp expect actual |
683b5679 JH |
77 | ) |
78 | ' | |
79 | ||
1ce89cc4 JK |
80 | test_expect_success 'remote forces tracking branches' ' |
81 | ( | |
82 | cd test && | |
83 | case `git config remote.second.fetch` in | |
84 | +*) true ;; | |
85 | *) false ;; | |
86 | esac | |
87 | ) | |
88 | ' | |
89 | ||
683b5679 JH |
90 | test_expect_success 'remove remote' ' |
91 | ( | |
92 | cd test && | |
3b9dcff5 | 93 | git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master && |
683b5679 JH |
94 | git remote rm second |
95 | ) | |
96 | ' | |
97 | ||
98 | test_expect_success 'remove remote' ' | |
99 | ( | |
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 && | |
82ebb0b6 | 106 | test_cmp expect actual |
683b5679 JH |
107 | ) |
108 | ' | |
109 | ||
4704640b JS |
110 | cat > test/expect << EOF |
111 | * remote origin | |
112 | URL: $(pwd)/one/.git | |
211c8968 | 113 | Remote branch merged with 'git pull' while on branch master |
4704640b | 114 | master |
211c8968 | 115 | New remote branch (next fetch will store in remotes/origin) |
4704640b JS |
116 | master |
117 | Tracked remote branches | |
118 | side master | |
ec31b0ce JS |
119 | Local branches pushed with 'git push' |
120 | master:upstream +refs/tags/lastbackup | |
4704640b JS |
121 | EOF |
122 | ||
123 | test_expect_success 'show' ' | |
124 | (cd test && | |
125 | git config --add remote.origin.fetch \ | |
126 | refs/heads/master:refs/heads/upstream && | |
127 | git fetch && | |
128 | git branch -d -r origin/master && | |
129 | (cd ../one && | |
130 | echo 1 > file && | |
84521ed6 | 131 | test_tick && |
4704640b | 132 | git commit -m update file) && |
ec31b0ce JS |
133 | git config remote.origin.push \ |
134 | refs/heads/master:refs/heads/upstream && | |
135 | git config --add remote.origin.push \ | |
136 | +refs/tags/lastbackup && | |
4704640b | 137 | git remote show origin > output && |
3af82863 | 138 | test_cmp expect output) |
4704640b JS |
139 | ' |
140 | ||
141 | test_expect_success 'prune' ' | |
142 | (cd one && | |
143 | git branch -m side side2) && | |
144 | (cd test && | |
145 | git fetch origin && | |
146 | git remote prune origin && | |
147 | git rev-parse refs/remotes/origin/side2 && | |
148 | ! git rev-parse refs/remotes/origin/side) | |
149 | ' | |
150 | ||
4ebc914c JS |
151 | test_expect_success 'add --mirror && prune' ' |
152 | (mkdir mirror && | |
153 | cd mirror && | |
154 | git init && | |
155 | git remote add --mirror -f origin ../one) && | |
156 | (cd one && | |
157 | git branch -m side2 side) && | |
158 | (cd mirror && | |
159 | git rev-parse --verify refs/heads/side2 && | |
160 | ! git rev-parse --verify refs/heads/side && | |
161 | git fetch origin && | |
162 | git remote prune origin && | |
163 | ! git rev-parse --verify refs/heads/side2 && | |
164 | git rev-parse --verify refs/heads/side) | |
165 | ' | |
166 | ||
c175a7ad SP |
167 | test_expect_success 'add alt && prune' ' |
168 | (mkdir alttst && | |
169 | cd alttst && | |
170 | git init && | |
171 | git remote add -f origin ../one && | |
172 | git config remote.alt.url ../one && | |
173 | git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") && | |
174 | (cd one && | |
175 | git branch -m side side2) && | |
176 | (cd alttst && | |
177 | git rev-parse --verify refs/remotes/origin/side && | |
178 | ! git rev-parse --verify refs/remotes/origin/side2 && | |
179 | git fetch alt && | |
180 | git remote prune alt && | |
181 | ! git rev-parse --verify refs/remotes/origin/side && | |
182 | git rev-parse --verify refs/remotes/origin/side2) | |
183 | ' | |
184 | ||
84521ed6 JS |
185 | cat > one/expect << EOF |
186 | apis/master | |
187 | apis/side | |
188 | drosophila/another | |
189 | drosophila/master | |
190 | drosophila/side | |
191 | EOF | |
192 | ||
193 | test_expect_success 'update' ' | |
194 | ||
195 | (cd one && | |
196 | git remote add drosophila ../two && | |
197 | git remote add apis ../mirror && | |
198 | git remote update && | |
199 | git branch -r > output && | |
3af82863 | 200 | test_cmp expect output) |
84521ed6 JS |
201 | |
202 | ' | |
203 | ||
204 | cat > one/expect << EOF | |
205 | drosophila/another | |
206 | drosophila/master | |
207 | drosophila/side | |
208 | manduca/master | |
209 | manduca/side | |
210 | megaloprepus/master | |
211 | megaloprepus/side | |
212 | EOF | |
213 | ||
214 | test_expect_success 'update with arguments' ' | |
215 | ||
216 | (cd one && | |
217 | for b in $(git branch -r) | |
218 | do | |
219 | git branch -r -d $b || break | |
220 | done && | |
221 | git remote add manduca ../mirror && | |
222 | git remote add megaloprepus ../mirror && | |
223 | git config remotes.phobaeticus "drosophila megaloprepus" && | |
224 | git config remotes.titanus manduca && | |
225 | git remote update phobaeticus titanus && | |
226 | git branch -r > output && | |
3af82863 | 227 | test_cmp expect output) |
84521ed6 JS |
228 | |
229 | ' | |
230 | ||
231 | cat > one/expect << EOF | |
232 | apis/master | |
233 | apis/side | |
234 | manduca/master | |
235 | manduca/side | |
236 | megaloprepus/master | |
237 | megaloprepus/side | |
238 | EOF | |
239 | ||
240 | test_expect_success 'update default' ' | |
241 | ||
242 | (cd one && | |
243 | for b in $(git branch -r) | |
244 | do | |
245 | git branch -r -d $b || break | |
246 | done && | |
247 | git config remote.drosophila.skipDefaultUpdate true && | |
248 | git remote update default && | |
249 | git branch -r > output && | |
3af82863 | 250 | test_cmp expect output) |
84521ed6 JS |
251 | |
252 | ' | |
253 | ||
254 | cat > one/expect << EOF | |
255 | drosophila/another | |
256 | drosophila/master | |
257 | drosophila/side | |
258 | EOF | |
259 | ||
260 | test_expect_success 'update default (overridden, with funny whitespace)' ' | |
261 | ||
262 | (cd one && | |
263 | for b in $(git branch -r) | |
264 | do | |
265 | git branch -r -d $b || break | |
266 | done && | |
267 | git config remotes.default "$(printf "\t drosophila \n")" && | |
268 | git remote update default && | |
269 | git branch -r > output && | |
3af82863 | 270 | test_cmp expect output) |
84521ed6 JS |
271 | |
272 | ' | |
273 | ||
740fdd27 JS |
274 | test_expect_success '"remote show" does not show symbolic refs' ' |
275 | ||
276 | git clone one three && | |
277 | (cd three && | |
278 | git remote show origin > output && | |
279 | ! grep HEAD < output && | |
280 | ! grep -i stale < output) | |
281 | ||
282 | ' | |
283 | ||
24b6177e JF |
284 | test_expect_success 'reject adding remote with an invalid name' ' |
285 | ||
286 | ! git remote add some:url desired-name | |
287 | ||
288 | ' | |
289 | ||
683b5679 | 290 | test_done |