Junio C Hamano | b9849a1 | 2007-04-16 00:42:29 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test quickfetch from local' |
| 4 | |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Junio C Hamano | b9849a1 | 2007-04-16 00:42:29 -0700 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success setup ' |
| 11 | |
| 12 | test_tick && |
| 13 | echo ichi >file && |
| 14 | git add file && |
| 15 | git commit -m initial && |
| 16 | |
| 17 | cnt=$( ( |
| 18 | git count-objects | sed -e "s/ *objects,.*//" |
| 19 | ) ) && |
| 20 | test $cnt -eq 3 |
| 21 | ' |
| 22 | |
| 23 | test_expect_success 'clone without alternate' ' |
| 24 | |
| 25 | ( |
| 26 | mkdir cloned && |
| 27 | cd cloned && |
| 28 | git init-db && |
| 29 | git remote add -f origin .. |
| 30 | ) && |
| 31 | cnt=$( ( |
| 32 | cd cloned && |
| 33 | git count-objects | sed -e "s/ *objects,.*//" |
| 34 | ) ) && |
| 35 | test $cnt -eq 3 |
| 36 | ' |
| 37 | |
| 38 | test_expect_success 'further commits in the original' ' |
| 39 | |
| 40 | test_tick && |
| 41 | echo ni >file && |
| 42 | git commit -a -m second && |
| 43 | |
| 44 | cnt=$( ( |
| 45 | git count-objects | sed -e "s/ *objects,.*//" |
| 46 | ) ) && |
| 47 | test $cnt -eq 6 |
| 48 | ' |
| 49 | |
| 50 | test_expect_success 'copy commit and tree but not blob by hand' ' |
| 51 | |
| 52 | git rev-list --objects HEAD | |
| 53 | git pack-objects --stdout | |
| 54 | ( |
| 55 | cd cloned && |
| 56 | git unpack-objects |
| 57 | ) && |
| 58 | |
| 59 | cnt=$( ( |
| 60 | cd cloned && |
| 61 | git count-objects | sed -e "s/ *objects,.*//" |
| 62 | ) ) && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 63 | test $cnt -eq 6 && |
Junio C Hamano | b9849a1 | 2007-04-16 00:42:29 -0700 | [diff] [blame] | 64 | |
| 65 | blob=$(git rev-parse HEAD:file | sed -e "s|..|&/|") && |
| 66 | test -f "cloned/.git/objects/$blob" && |
| 67 | rm -f "cloned/.git/objects/$blob" && |
| 68 | |
| 69 | cnt=$( ( |
| 70 | cd cloned && |
| 71 | git count-objects | sed -e "s/ *objects,.*//" |
| 72 | ) ) && |
| 73 | test $cnt -eq 5 |
| 74 | |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'quickfetch should not leave a corrupted repository' ' |
| 78 | |
| 79 | ( |
| 80 | cd cloned && |
| 81 | git fetch |
| 82 | ) && |
| 83 | |
| 84 | cnt=$( ( |
| 85 | cd cloned && |
| 86 | git count-objects | sed -e "s/ *objects,.*//" |
| 87 | ) ) && |
| 88 | test $cnt -eq 6 |
| 89 | |
| 90 | ' |
| 91 | |
Shawn O. Pearce | 4191c35 | 2007-11-11 02:29:47 -0500 | [diff] [blame] | 92 | test_expect_success 'quickfetch should not copy from alternate' ' |
| 93 | |
| 94 | ( |
| 95 | mkdir quickclone && |
| 96 | cd quickclone && |
| 97 | git init-db && |
| 98 | (cd ../.git/objects && pwd) >.git/objects/info/alternates && |
| 99 | git remote add origin .. && |
| 100 | git fetch -k -k |
| 101 | ) && |
| 102 | obj_cnt=$( ( |
| 103 | cd quickclone && |
| 104 | git count-objects | sed -e "s/ *objects,.*//" |
| 105 | ) ) && |
| 106 | pck_cnt=$( ( |
| 107 | cd quickclone && |
| 108 | git count-objects -v | sed -n -e "/packs:/{ |
| 109 | s/packs:// |
| 110 | p |
| 111 | q |
| 112 | }" |
| 113 | ) ) && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 114 | origin_main=$( ( |
Shawn O. Pearce | 4191c35 | 2007-11-11 02:29:47 -0500 | [diff] [blame] | 115 | cd quickclone && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 116 | git rev-parse origin/main |
Shawn O. Pearce | 4191c35 | 2007-11-11 02:29:47 -0500 | [diff] [blame] | 117 | ) ) && |
| 118 | echo "loose objects: $obj_cnt, packfiles: $pck_cnt" && |
| 119 | test $obj_cnt -eq 0 && |
| 120 | test $pck_cnt -eq 0 && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 121 | test z$origin_main = z$(git rev-parse main) |
Shawn O. Pearce | 4191c35 | 2007-11-11 02:29:47 -0500 | [diff] [blame] | 122 | |
| 123 | ' |
| 124 | |
Johan Herland | d9eb020 | 2009-07-10 01:52:30 +0200 | [diff] [blame] | 125 | test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' ' |
| 126 | |
| 127 | git gc && |
| 128 | head=$(git rev-parse HEAD) && |
| 129 | branchprefix="$head refs/heads/branch" && |
| 130 | for i in 0 1 2 3 4 5 6 7 8 9; do |
| 131 | for j in 0 1 2 3 4 5 6 7 8 9; do |
| 132 | for k in 0 1 2 3 4 5 6 7 8 9; do |
| 133 | echo "$branchprefix$i$j$k" >> .git/packed-refs |
| 134 | done |
| 135 | done |
| 136 | done && |
| 137 | ( |
| 138 | cd cloned && |
| 139 | git fetch && |
| 140 | git fetch |
| 141 | ) |
| 142 | |
| 143 | ' |
| 144 | |
Junio C Hamano | b9849a1 | 2007-04-16 00:42:29 -0700 | [diff] [blame] | 145 | test_done |