Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git remote porcelain-ish' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 7 | setup_repository () { |
| 8 | mkdir "$1" && ( |
| 9 | cd "$1" && |
| 10 | git init && |
| 11 | >file && |
| 12 | git add file && |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 13 | test_tick && |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 14 | git commit -m "Initial" && |
| 15 | git checkout -b side && |
| 16 | >elif && |
| 17 | git add elif && |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 18 | test_tick && |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 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 && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 27 | test_cmp expect actual |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 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 && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 76 | test_cmp expect actual |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 77 | ) |
| 78 | ' |
| 79 | |
Jeff King | 1ce89cc | 2008-04-22 07:11:13 -0400 | [diff] [blame] | 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 | |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 90 | test_expect_success 'remove remote' ' |
| 91 | ( |
| 92 | cd test && |
Johannes Schindelin | 3b9dcff | 2008-03-08 23:40:42 +0100 | [diff] [blame] | 93 | git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master && |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 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 && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 106 | test_cmp expect actual |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 107 | ) |
| 108 | ' |
| 109 | |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 110 | cat > test/expect << EOF |
| 111 | * remote origin |
Johan Herland | 86521ac | 2008-09-01 21:07:33 +0200 | [diff] [blame] | 112 | URL: $(pwd)/one |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 113 | Remote branch merged with 'git pull' while on branch master |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 114 | master |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 115 | New remote branch (next fetch will store in remotes/origin) |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 116 | master |
| 117 | Tracked remote branches |
| 118 | side master |
Johannes Sixt | ec31b0c | 2008-03-18 21:52:00 +0100 | [diff] [blame] | 119 | Local branches pushed with 'git push' |
| 120 | master:upstream +refs/tags/lastbackup |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 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 && |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 131 | test_tick && |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 132 | git commit -m update file) && |
Johannes Sixt | ec31b0c | 2008-03-18 21:52:00 +0100 | [diff] [blame] | 133 | git config remote.origin.push \ |
| 134 | refs/heads/master:refs/heads/upstream && |
| 135 | git config --add remote.origin.push \ |
| 136 | +refs/tags/lastbackup && |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 137 | git remote show origin > output && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 138 | test_cmp expect output) |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 139 | ' |
| 140 | |
Olivier Marin | 0ecfcb3 | 2008-06-10 16:51:08 +0200 | [diff] [blame] | 141 | cat > test/expect << EOF |
| 142 | * remote origin |
Johan Herland | 86521ac | 2008-09-01 21:07:33 +0200 | [diff] [blame] | 143 | URL: $(pwd)/one |
Olivier Marin | 0ecfcb3 | 2008-06-10 16:51:08 +0200 | [diff] [blame] | 144 | Remote branch merged with 'git pull' while on branch master |
| 145 | master |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 146 | Tracked remote branches |
| 147 | master side |
Olivier Marin | 0ecfcb3 | 2008-06-10 16:51:08 +0200 | [diff] [blame] | 148 | Local branches pushed with 'git push' |
| 149 | master:upstream +refs/tags/lastbackup |
| 150 | EOF |
| 151 | |
| 152 | test_expect_success 'show -n' ' |
| 153 | (mv one one.unreachable && |
| 154 | cd test && |
| 155 | git remote show -n origin > output && |
| 156 | mv ../one.unreachable ../one && |
| 157 | test_cmp expect output) |
| 158 | ' |
| 159 | |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 160 | test_expect_success 'prune' ' |
| 161 | (cd one && |
| 162 | git branch -m side side2) && |
| 163 | (cd test && |
| 164 | git fetch origin && |
| 165 | git remote prune origin && |
| 166 | git rev-parse refs/remotes/origin/side2 && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 167 | test_must_fail git rev-parse refs/remotes/origin/side) |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 168 | ' |
| 169 | |
Olivier Marin | 8d76792 | 2008-06-10 16:51:35 +0200 | [diff] [blame] | 170 | cat > test/expect << EOF |
| 171 | Pruning origin |
Johan Herland | 86521ac | 2008-09-01 21:07:33 +0200 | [diff] [blame] | 172 | URL: $(pwd)/one |
Olivier Marin | 8d76792 | 2008-06-10 16:51:35 +0200 | [diff] [blame] | 173 | * [would prune] origin/side2 |
| 174 | EOF |
| 175 | |
| 176 | test_expect_success 'prune --dry-run' ' |
| 177 | (cd one && |
| 178 | git branch -m side2 side) && |
| 179 | (cd test && |
| 180 | git remote prune --dry-run origin > output && |
| 181 | git rev-parse refs/remotes/origin/side2 && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 182 | test_must_fail git rev-parse refs/remotes/origin/side && |
Olivier Marin | 8d76792 | 2008-06-10 16:51:35 +0200 | [diff] [blame] | 183 | (cd ../one && |
| 184 | git branch -m side side2) && |
| 185 | test_cmp expect output) |
| 186 | ' |
| 187 | |
Johannes Schindelin | 4ebc914 | 2008-02-29 01:46:07 +0000 | [diff] [blame] | 188 | test_expect_success 'add --mirror && prune' ' |
| 189 | (mkdir mirror && |
| 190 | cd mirror && |
| 191 | git init && |
| 192 | git remote add --mirror -f origin ../one) && |
| 193 | (cd one && |
| 194 | git branch -m side2 side) && |
| 195 | (cd mirror && |
| 196 | git rev-parse --verify refs/heads/side2 && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 197 | test_must_fail git rev-parse --verify refs/heads/side && |
Johannes Schindelin | 4ebc914 | 2008-02-29 01:46:07 +0000 | [diff] [blame] | 198 | git fetch origin && |
| 199 | git remote prune origin && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 200 | test_must_fail git rev-parse --verify refs/heads/side2 && |
Johannes Schindelin | 4ebc914 | 2008-02-29 01:46:07 +0000 | [diff] [blame] | 201 | git rev-parse --verify refs/heads/side) |
| 202 | ' |
| 203 | |
Shawn O. Pearce | c175a7a | 2008-05-31 23:58:05 -0400 | [diff] [blame] | 204 | test_expect_success 'add alt && prune' ' |
| 205 | (mkdir alttst && |
| 206 | cd alttst && |
| 207 | git init && |
| 208 | git remote add -f origin ../one && |
| 209 | git config remote.alt.url ../one && |
| 210 | git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") && |
| 211 | (cd one && |
| 212 | git branch -m side side2) && |
| 213 | (cd alttst && |
| 214 | git rev-parse --verify refs/remotes/origin/side && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 215 | test_must_fail git rev-parse --verify refs/remotes/origin/side2 && |
Shawn O. Pearce | c175a7a | 2008-05-31 23:58:05 -0400 | [diff] [blame] | 216 | git fetch alt && |
| 217 | git remote prune alt && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 218 | test_must_fail git rev-parse --verify refs/remotes/origin/side && |
Shawn O. Pearce | c175a7a | 2008-05-31 23:58:05 -0400 | [diff] [blame] | 219 | git rev-parse --verify refs/remotes/origin/side2) |
| 220 | ' |
| 221 | |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 222 | cat > one/expect << EOF |
| 223 | apis/master |
| 224 | apis/side |
| 225 | drosophila/another |
| 226 | drosophila/master |
| 227 | drosophila/side |
| 228 | EOF |
| 229 | |
| 230 | test_expect_success 'update' ' |
| 231 | |
| 232 | (cd one && |
| 233 | git remote add drosophila ../two && |
| 234 | git remote add apis ../mirror && |
| 235 | git remote update && |
| 236 | git branch -r > output && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 237 | test_cmp expect output) |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 238 | |
| 239 | ' |
| 240 | |
| 241 | cat > one/expect << EOF |
| 242 | drosophila/another |
| 243 | drosophila/master |
| 244 | drosophila/side |
| 245 | manduca/master |
| 246 | manduca/side |
| 247 | megaloprepus/master |
| 248 | megaloprepus/side |
| 249 | EOF |
| 250 | |
| 251 | test_expect_success 'update with arguments' ' |
| 252 | |
| 253 | (cd one && |
| 254 | for b in $(git branch -r) |
| 255 | do |
| 256 | git branch -r -d $b || break |
| 257 | done && |
| 258 | git remote add manduca ../mirror && |
| 259 | git remote add megaloprepus ../mirror && |
| 260 | git config remotes.phobaeticus "drosophila megaloprepus" && |
| 261 | git config remotes.titanus manduca && |
| 262 | git remote update phobaeticus titanus && |
| 263 | git branch -r > output && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 264 | test_cmp expect output) |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 265 | |
| 266 | ' |
| 267 | |
| 268 | cat > one/expect << EOF |
| 269 | apis/master |
| 270 | apis/side |
| 271 | manduca/master |
| 272 | manduca/side |
| 273 | megaloprepus/master |
| 274 | megaloprepus/side |
| 275 | EOF |
| 276 | |
| 277 | test_expect_success 'update default' ' |
| 278 | |
| 279 | (cd one && |
| 280 | for b in $(git branch -r) |
| 281 | do |
| 282 | git branch -r -d $b || break |
| 283 | done && |
| 284 | git config remote.drosophila.skipDefaultUpdate true && |
| 285 | git remote update default && |
| 286 | git branch -r > output && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 287 | test_cmp expect output) |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 288 | |
| 289 | ' |
| 290 | |
| 291 | cat > one/expect << EOF |
| 292 | drosophila/another |
| 293 | drosophila/master |
| 294 | drosophila/side |
| 295 | EOF |
| 296 | |
| 297 | test_expect_success 'update default (overridden, with funny whitespace)' ' |
| 298 | |
| 299 | (cd one && |
| 300 | for b in $(git branch -r) |
| 301 | do |
| 302 | git branch -r -d $b || break |
| 303 | done && |
| 304 | git config remotes.default "$(printf "\t drosophila \n")" && |
| 305 | git remote update default && |
| 306 | git branch -r > output && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 307 | test_cmp expect output) |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 308 | |
| 309 | ' |
| 310 | |
Johannes Schindelin | 740fdd2 | 2008-03-19 00:27:42 +0000 | [diff] [blame] | 311 | test_expect_success '"remote show" does not show symbolic refs' ' |
| 312 | |
| 313 | git clone one three && |
| 314 | (cd three && |
| 315 | git remote show origin > output && |
| 316 | ! grep HEAD < output && |
| 317 | ! grep -i stale < output) |
| 318 | |
| 319 | ' |
| 320 | |
Jonas Fonseca | 24b6177 | 2008-04-13 11:56:54 +0200 | [diff] [blame] | 321 | test_expect_success 'reject adding remote with an invalid name' ' |
| 322 | |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 323 | test_must_fail git remote add some:url desired-name |
Jonas Fonseca | 24b6177 | 2008-04-13 11:56:54 +0200 | [diff] [blame] | 324 | |
| 325 | ' |
| 326 | |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 327 | test_done |