Junio C Hamano | 7be1d62 | 2006-09-23 03:40:17 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright (c) 2006, Junio C Hamano. |
| 3 | |
| 4 | test_description='Per branch config variables affects "git fetch". |
| 5 | |
| 6 | ' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | D=`pwd` |
| 11 | |
Junio C Hamano | 2e674a9 | 2009-08-07 20:12:13 -0700 | [diff] [blame] | 12 | test_bundle_object_count () { |
| 13 | git verify-pack -v "$1" >verify.out && |
| 14 | test "$2" = $(grep '^[0-9a-f]\{40\} ' verify.out | wc -l) |
| 15 | } |
| 16 | |
Junio C Hamano | 7be1d62 | 2006-09-23 03:40:17 -0700 | [diff] [blame] | 17 | test_expect_success setup ' |
| 18 | echo >file original && |
| 19 | git add file && |
| 20 | git commit -a -m original' |
| 21 | |
| 22 | test_expect_success "clone and setup child repos" ' |
| 23 | git clone . one && |
| 24 | cd one && |
| 25 | echo >file updated by one && |
| 26 | git commit -a -m "updated by one" && |
| 27 | cd .. && |
| 28 | git clone . two && |
| 29 | cd two && |
Tom Prince | e0d10e1 | 2007-01-28 16:16:53 -0800 | [diff] [blame] | 30 | git config branch.master.remote one && |
| 31 | git config remote.one.url ../one/.git/ && |
| 32 | git config remote.one.fetch refs/heads/master:refs/heads/one && |
Santi Béjar | 6cc7c36 | 2006-09-23 22:55:35 +0200 | [diff] [blame] | 33 | cd .. && |
| 34 | git clone . three && |
| 35 | cd three && |
Tom Prince | e0d10e1 | 2007-01-28 16:16:53 -0800 | [diff] [blame] | 36 | git config branch.master.remote two && |
| 37 | git config branch.master.merge refs/heads/one && |
Junio C Hamano | 75c384e | 2006-12-19 01:50:37 -0800 | [diff] [blame] | 38 | mkdir -p .git/remotes && |
Santi Béjar | 6cc7c36 | 2006-09-23 22:55:35 +0200 | [diff] [blame] | 39 | { |
| 40 | echo "URL: ../two/.git/" |
| 41 | echo "Pull: refs/heads/master:refs/heads/two" |
| 42 | echo "Pull: refs/heads/one:refs/heads/one" |
Johannes Schindelin | 2e0afaf | 2007-02-22 01:59:14 +0100 | [diff] [blame] | 43 | } >.git/remotes/two && |
| 44 | cd .. && |
Jeff King | 9a7bbd1 | 2008-06-16 12:15:02 -0400 | [diff] [blame] | 45 | git clone . bundle && |
| 46 | git clone . seven |
Junio C Hamano | 7be1d62 | 2006-09-23 03:40:17 -0700 | [diff] [blame] | 47 | ' |
| 48 | |
| 49 | test_expect_success "fetch test" ' |
| 50 | cd "$D" && |
| 51 | echo >file updated by origin && |
| 52 | git commit -a -m "updated by origin" && |
| 53 | cd two && |
| 54 | git fetch && |
| 55 | test -f .git/refs/heads/one && |
| 56 | mine=`git rev-parse refs/heads/one` && |
| 57 | his=`cd ../one && git rev-parse refs/heads/master` && |
| 58 | test "z$mine" = "z$his" |
| 59 | ' |
| 60 | |
Santi Béjar | 6cc7c36 | 2006-09-23 22:55:35 +0200 | [diff] [blame] | 61 | test_expect_success "fetch test for-merge" ' |
| 62 | cd "$D" && |
| 63 | cd three && |
| 64 | git fetch && |
| 65 | test -f .git/refs/heads/two && |
| 66 | test -f .git/refs/heads/one && |
| 67 | master_in_two=`cd ../two && git rev-parse master` && |
| 68 | one_in_two=`cd ../two && git rev-parse one` && |
| 69 | { |
| 70 | echo "$master_in_two not-for-merge" |
| 71 | echo "$one_in_two " |
| 72 | } >expected && |
| 73 | cut -f -2 .git/FETCH_HEAD >actual && |
| 74 | diff expected actual' |
| 75 | |
Väinö Järvelä | f539d0d | 2007-10-09 11:51:07 +0300 | [diff] [blame] | 76 | test_expect_success 'fetch tags when there is no tags' ' |
| 77 | |
| 78 | cd "$D" && |
| 79 | |
| 80 | mkdir notags && |
| 81 | cd notags && |
| 82 | git init && |
| 83 | |
| 84 | git fetch -t .. |
| 85 | |
| 86 | ' |
| 87 | |
Junio C Hamano | 6c96c0f | 2006-11-18 21:39:17 -0800 | [diff] [blame] | 88 | test_expect_success 'fetch following tags' ' |
| 89 | |
| 90 | cd "$D" && |
| 91 | git tag -a -m 'annotated' anno HEAD && |
| 92 | git tag light HEAD && |
| 93 | |
| 94 | mkdir four && |
| 95 | cd four && |
Nicolas Pitre | 5c94f87 | 2007-01-12 16:01:46 -0500 | [diff] [blame] | 96 | git init && |
Junio C Hamano | 6c96c0f | 2006-11-18 21:39:17 -0800 | [diff] [blame] | 97 | |
| 98 | git fetch .. :track && |
| 99 | git show-ref --verify refs/tags/anno && |
| 100 | git show-ref --verify refs/tags/light |
| 101 | |
| 102 | ' |
| 103 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 104 | test_expect_success 'fetch must not resolve short tag name' ' |
Steffen Prohaska | 605b497 | 2007-11-11 15:01:48 +0100 | [diff] [blame] | 105 | |
| 106 | cd "$D" && |
| 107 | |
| 108 | mkdir five && |
| 109 | cd five && |
| 110 | git init && |
| 111 | |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 112 | test_must_fail git fetch .. anno:five |
Steffen Prohaska | 605b497 | 2007-11-11 15:01:48 +0100 | [diff] [blame] | 113 | |
| 114 | ' |
| 115 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 116 | test_expect_success 'fetch must not resolve short remote name' ' |
Steffen Prohaska | 605b497 | 2007-11-11 15:01:48 +0100 | [diff] [blame] | 117 | |
| 118 | cd "$D" && |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 119 | git update-ref refs/remotes/six/HEAD HEAD |
Steffen Prohaska | 605b497 | 2007-11-11 15:01:48 +0100 | [diff] [blame] | 120 | |
| 121 | mkdir six && |
| 122 | cd six && |
| 123 | git init && |
| 124 | |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 125 | test_must_fail git fetch .. six:six |
Steffen Prohaska | 605b497 | 2007-11-11 15:01:48 +0100 | [diff] [blame] | 126 | |
| 127 | ' |
| 128 | |
Johannes Schindelin | 2e0afaf | 2007-02-22 01:59:14 +0100 | [diff] [blame] | 129 | test_expect_success 'create bundle 1' ' |
| 130 | cd "$D" && |
| 131 | echo >file updated again by origin && |
| 132 | git commit -a -m "tip" && |
| 133 | git bundle create bundle1 master^..master |
| 134 | ' |
| 135 | |
Johannes Schindelin | 8315588 | 2007-03-06 22:57:07 +0100 | [diff] [blame] | 136 | test_expect_success 'header of bundle looks right' ' |
| 137 | head -n 1 "$D"/bundle1 | grep "^#" && |
| 138 | head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " && |
| 139 | head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " && |
| 140 | head -n 4 "$D"/bundle1 | grep "^$" |
| 141 | ' |
| 142 | |
Johannes Schindelin | 2e0afaf | 2007-02-22 01:59:14 +0100 | [diff] [blame] | 143 | test_expect_success 'create bundle 2' ' |
| 144 | cd "$D" && |
| 145 | git bundle create bundle2 master~2..master |
| 146 | ' |
| 147 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 148 | test_expect_success 'unbundle 1' ' |
Johannes Schindelin | 2e0afaf | 2007-02-22 01:59:14 +0100 | [diff] [blame] | 149 | cd "$D/bundle" && |
| 150 | git checkout -b some-branch && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 151 | test_must_fail git fetch "$D/bundle1" master:master |
Johannes Schindelin | 2e0afaf | 2007-02-22 01:59:14 +0100 | [diff] [blame] | 152 | ' |
| 153 | |
Junio C Hamano | 2e674a9 | 2009-08-07 20:12:13 -0700 | [diff] [blame] | 154 | |
Johannes Schindelin | 8315588 | 2007-03-06 22:57:07 +0100 | [diff] [blame] | 155 | test_expect_success 'bundle 1 has only 3 files ' ' |
| 156 | cd "$D" && |
| 157 | ( |
| 158 | while read x && test -n "$x" |
| 159 | do |
| 160 | :; |
| 161 | done |
| 162 | cat |
| 163 | ) <bundle1 >bundle.pack && |
| 164 | git index-pack bundle.pack && |
Junio C Hamano | 2e674a9 | 2009-08-07 20:12:13 -0700 | [diff] [blame] | 165 | test_bundle_object_count bundle.pack 3 |
Johannes Schindelin | 8315588 | 2007-03-06 22:57:07 +0100 | [diff] [blame] | 166 | ' |
| 167 | |
Johannes Schindelin | 2e0afaf | 2007-02-22 01:59:14 +0100 | [diff] [blame] | 168 | test_expect_success 'unbundle 2' ' |
| 169 | cd "$D/bundle" && |
| 170 | git fetch ../bundle2 master:master && |
| 171 | test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)" |
| 172 | ' |
| 173 | |
Johannes Schindelin | 18449ab | 2007-03-08 00:43:05 +0100 | [diff] [blame] | 174 | test_expect_success 'bundle does not prerequisite objects' ' |
| 175 | cd "$D" && |
| 176 | touch file2 && |
| 177 | git add file2 && |
| 178 | git commit -m add.file2 file2 && |
| 179 | git bundle create bundle3 -1 HEAD && |
Shawn O. Pearce | 6016e35 | 2007-03-12 18:59:16 -0400 | [diff] [blame] | 180 | ( |
| 181 | while read x && test -n "$x" |
| 182 | do |
| 183 | :; |
| 184 | done |
| 185 | cat |
| 186 | ) <bundle3 >bundle.pack && |
Johannes Schindelin | 18449ab | 2007-03-08 00:43:05 +0100 | [diff] [blame] | 187 | git index-pack bundle.pack && |
Junio C Hamano | 2e674a9 | 2009-08-07 20:12:13 -0700 | [diff] [blame] | 188 | test_bundle_object_count bundle.pack 3 |
Johannes Schindelin | 18449ab | 2007-03-08 00:43:05 +0100 | [diff] [blame] | 189 | ' |
| 190 | |
Junio C Hamano | 7fa8254 | 2007-08-08 17:01:49 -0700 | [diff] [blame] | 191 | test_expect_success 'bundle should be able to create a full history' ' |
| 192 | |
| 193 | cd "$D" && |
| 194 | git tag -a -m '1.0' v1.0 master && |
| 195 | git bundle create bundle4 v1.0 |
| 196 | |
| 197 | ' |
| 198 | |
Johannes Schindelin | 7efaeba | 2009-03-09 19:44:55 +0100 | [diff] [blame] | 199 | ! rsync --help > /dev/null 2> /dev/null && |
| 200 | say 'Skipping rsync tests because rsync was not found' || { |
Johannes Schindelin | cd547b4 | 2007-10-01 00:59:39 +0100 | [diff] [blame] | 201 | test_expect_success 'fetch via rsync' ' |
| 202 | git pack-refs && |
| 203 | mkdir rsynced && |
Johannes Schindelin | 7efaeba | 2009-03-09 19:44:55 +0100 | [diff] [blame] | 204 | (cd rsynced && |
| 205 | git init --bare && |
| 206 | git fetch "rsync:$(pwd)/../.git" master:refs/heads/master && |
| 207 | git gc --prune && |
| 208 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && |
| 209 | git fsck --full) |
Johannes Schindelin | cd547b4 | 2007-10-01 00:59:39 +0100 | [diff] [blame] | 210 | ' |
| 211 | |
| 212 | test_expect_success 'push via rsync' ' |
Johannes Schindelin | 7efaeba | 2009-03-09 19:44:55 +0100 | [diff] [blame] | 213 | mkdir rsynced2 && |
| 214 | (cd rsynced2 && |
Johannes Schindelin | cd547b4 | 2007-10-01 00:59:39 +0100 | [diff] [blame] | 215 | git init) && |
Johannes Schindelin | 7efaeba | 2009-03-09 19:44:55 +0100 | [diff] [blame] | 216 | (cd rsynced && |
| 217 | git push "rsync:$(pwd)/../rsynced2/.git" master) && |
| 218 | (cd rsynced2 && |
| 219 | git gc --prune && |
| 220 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && |
| 221 | git fsck --full) |
Johannes Schindelin | cd547b4 | 2007-10-01 00:59:39 +0100 | [diff] [blame] | 222 | ' |
| 223 | |
| 224 | test_expect_success 'push via rsync' ' |
Johannes Schindelin | cd547b4 | 2007-10-01 00:59:39 +0100 | [diff] [blame] | 225 | mkdir rsynced3 && |
| 226 | (cd rsynced3 && |
| 227 | git init) && |
Johannes Schindelin | 7efaeba | 2009-03-09 19:44:55 +0100 | [diff] [blame] | 228 | git push --all "rsync:$(pwd)/rsynced3/.git" && |
| 229 | (cd rsynced3 && |
| 230 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && |
| 231 | git fsck --full) |
Johannes Schindelin | cd547b4 | 2007-10-01 00:59:39 +0100 | [diff] [blame] | 232 | ' |
| 233 | } |
| 234 | |
Johannes Schindelin | da0204d | 2007-10-11 01:47:55 +0100 | [diff] [blame] | 235 | test_expect_success 'fetch with a non-applying branch.<name>.merge' ' |
| 236 | git config branch.master.remote yeti && |
| 237 | git config branch.master.merge refs/heads/bigfoot && |
| 238 | git config remote.blub.url one && |
| 239 | git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" && |
| 240 | git fetch blub |
| 241 | ' |
| 242 | |
Johannes Sixt | c2015b3 | 2007-11-04 21:26:22 +0100 | [diff] [blame] | 243 | # the strange name is: a\!'b |
| 244 | test_expect_success 'quoting of a strangely named repo' ' |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 245 | test_must_fail git fetch "a\\!'\''b" > result 2>&1 && |
Johannes Sixt | c2015b3 | 2007-11-04 21:26:22 +0100 | [diff] [blame] | 246 | cat result && |
| 247 | grep "fatal: '\''a\\\\!'\''b'\''" result |
| 248 | ' |
| 249 | |
Johannes Schindelin | c5546e8 | 2007-11-22 12:24:59 +0000 | [diff] [blame] | 250 | test_expect_success 'bundle should record HEAD correctly' ' |
| 251 | |
| 252 | cd "$D" && |
| 253 | git bundle create bundle5 HEAD master && |
| 254 | git bundle list-heads bundle5 >actual && |
| 255 | for h in HEAD refs/heads/master |
| 256 | do |
| 257 | echo "$(git rev-parse --verify $h) $h" |
| 258 | done >expect && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 259 | test_cmp expect actual |
Johannes Schindelin | c5546e8 | 2007-11-22 12:24:59 +0000 | [diff] [blame] | 260 | |
| 261 | ' |
| 262 | |
Junio C Hamano | c701596 | 2007-12-04 21:58:42 -0800 | [diff] [blame] | 263 | test_expect_success 'explicit fetch should not update tracking' ' |
| 264 | |
| 265 | cd "$D" && |
| 266 | git branch -f side && |
| 267 | ( |
| 268 | cd three && |
| 269 | o=$(git rev-parse --verify refs/remotes/origin/master) && |
| 270 | git fetch origin master && |
| 271 | n=$(git rev-parse --verify refs/remotes/origin/master) && |
| 272 | test "$o" = "$n" && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 273 | test_must_fail git rev-parse --verify refs/remotes/origin/side |
Junio C Hamano | c701596 | 2007-12-04 21:58:42 -0800 | [diff] [blame] | 274 | ) |
| 275 | ' |
| 276 | |
| 277 | test_expect_success 'explicit pull should not update tracking' ' |
| 278 | |
| 279 | cd "$D" && |
| 280 | git branch -f side && |
| 281 | ( |
| 282 | cd three && |
| 283 | o=$(git rev-parse --verify refs/remotes/origin/master) && |
| 284 | git pull origin master && |
| 285 | n=$(git rev-parse --verify refs/remotes/origin/master) && |
| 286 | test "$o" = "$n" && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 287 | test_must_fail git rev-parse --verify refs/remotes/origin/side |
Junio C Hamano | c701596 | 2007-12-04 21:58:42 -0800 | [diff] [blame] | 288 | ) |
| 289 | ' |
| 290 | |
| 291 | test_expect_success 'configured fetch updates tracking' ' |
| 292 | |
| 293 | cd "$D" && |
| 294 | git branch -f side && |
| 295 | ( |
| 296 | cd three && |
| 297 | o=$(git rev-parse --verify refs/remotes/origin/master) && |
| 298 | git fetch origin && |
| 299 | n=$(git rev-parse --verify refs/remotes/origin/master) && |
| 300 | test "$o" != "$n" && |
| 301 | git rev-parse --verify refs/remotes/origin/side |
| 302 | ) |
| 303 | ' |
| 304 | |
Jeff King | 9a7bbd1 | 2008-06-16 12:15:02 -0400 | [diff] [blame] | 305 | test_expect_success 'pushing nonexistent branch by mistake should not segv' ' |
| 306 | |
| 307 | cd "$D" && |
| 308 | test_must_fail git push seven no:no |
| 309 | |
| 310 | ' |
| 311 | |
Junio C Hamano | 4942025 | 2008-09-21 23:50:01 -0700 | [diff] [blame] | 312 | test_expect_success 'auto tag following fetches minimum' ' |
| 313 | |
| 314 | cd "$D" && |
| 315 | git clone .git follow && |
| 316 | git checkout HEAD^0 && |
| 317 | ( |
| 318 | for i in 1 2 3 4 5 6 7 |
| 319 | do |
| 320 | echo $i >>file && |
| 321 | git commit -m $i -a && |
| 322 | git tag -a -m $i excess-$i || exit 1 |
| 323 | done |
| 324 | ) && |
| 325 | git checkout master && |
| 326 | ( |
| 327 | cd follow && |
| 328 | git fetch |
| 329 | ) |
| 330 | ' |
| 331 | |
Johannes Schindelin | 8ee5d73 | 2008-10-13 11:36:52 +0200 | [diff] [blame] | 332 | test_expect_success 'refuse to fetch into the current branch' ' |
| 333 | |
| 334 | test_must_fail git fetch . side:master |
| 335 | |
| 336 | ' |
| 337 | |
| 338 | test_expect_success 'fetch into the current branch with --update-head-ok' ' |
| 339 | |
| 340 | git fetch --update-head-ok . side:master |
| 341 | |
| 342 | ' |
| 343 | |
Junio C Hamano | 7be1d62 | 2006-09-23 03:40:17 -0700 | [diff] [blame] | 344 | test_done |