Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5537-fetch-shallow.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5537-fetch-shallow.sh` 330 lines ยท 9985 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='fetch/clone from a shallow clone' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./test-lib.sh 9 10 commit() { 11 echo "$1" >tracked && 12 git add tracked && 13 git commit -m "$1" 14 } 15 16 test_expect_success 'setup' ' 17 commit 1 && 18 commit 2 && 19 commit 3 && 20 commit 4 && 21 git config --global transfer.fsckObjects true && 22 test_oid_cache <<-\EOF 23 perl sha1:s/0034shallow %s/0036unshallow %s/ 24 perl sha256:s/004cshallow %s/004eunshallow %s/ 25 EOF 26 ' 27 28 test_expect_success 'setup shallow clone' ' 29 git clone --no-local --depth=2 .git shallow && 30 git --git-dir=shallow/.git log --format=%s >actual && 31 test_write_lines 4 3 >expect && 32 test_cmp expect actual 33 ' 34 35 test_expect_success 'clone from shallow clone' ' 36 git clone --no-local shallow shallow2 && 37 ( 38 cd shallow2 && 39 git fsck && 40 git log --format=%s >actual && 41 test_write_lines 4 3 >expect && 42 test_cmp expect actual 43 ) 44 ' 45 46 test_expect_success 'fetch from shallow clone' ' 47 ( 48 cd shallow && 49 commit 5 50 ) && 51 ( 52 cd shallow2 && 53 git fetch && 54 git fsck && 55 git log --format=%s origin/main >actual && 56 test_write_lines 5 4 3 >expect && 57 test_cmp expect actual 58 ) 59 ' 60 61 test_expect_success 'fetch --depth from shallow clone' ' 62 ( 63 cd shallow && 64 commit 6 65 ) && 66 ( 67 cd shallow2 && 68 git fetch --depth=2 && 69 git fsck && 70 git log --format=%s origin/main >actual && 71 test_write_lines 6 5 >expect && 72 test_cmp expect actual 73 ) 74 ' 75 76 test_expect_success 'fetch --unshallow from shallow clone' ' 77 ( 78 cd shallow2 && 79 git fetch --unshallow && 80 git fsck && 81 git log --format=%s origin/main >actual && 82 test_write_lines 6 5 4 3 >expect && 83 test_cmp expect actual 84 ) 85 ' 86 87 test_expect_success 'fetch --unshallow from a full clone' ' 88 git clone --no-local --depth=2 .git shallow3 && 89 ( 90 cd shallow3 && 91 git log --format=%s >actual && 92 test_write_lines 4 3 >expect && 93 test_cmp expect actual && 94 git -c fetch.writeCommitGraph fetch --unshallow && 95 git log origin/main --format=%s >actual && 96 test_write_lines 4 3 2 1 >expect && 97 test_cmp expect actual 98 ) 99 ' 100 101 test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' ' 102 # the blob "1" is available in .git but hidden by the 103 # shallow2/.git/shallow and it should be resent 104 ! git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null && 105 echo 1 >1.t && 106 git add 1.t && 107 git commit -m add-1-back && 108 ( 109 cd shallow2 && 110 git fetch ../.git +refs/heads/main:refs/remotes/top/main && 111 git fsck && 112 git log --format=%s top/main >actual && 113 test_write_lines add-1-back 4 3 >expect && 114 test_cmp expect actual 115 ) && 116 git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null 117 ' 118 119 test_expect_success 'fetch that requires changes in .git/shallow is filtered' ' 120 ( 121 cd shallow && 122 git checkout --orphan no-shallow && 123 commit no-shallow 124 ) && 125 git init notshallow && 126 ( 127 cd notshallow && 128 git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/* && 129 git for-each-ref --format="%(refname)" >actual.refs && 130 echo refs/remotes/shallow/no-shallow >expect.refs && 131 test_cmp expect.refs actual.refs && 132 git log --format=%s shallow/no-shallow >actual && 133 echo no-shallow >expect && 134 test_cmp expect actual 135 ) 136 ' 137 138 test_expect_success 'fetch.writeCommitGraph skips refs that require changes in .git/shallow' ' 139 git clone --no-local --depth=2 .git shallow-graph && 140 git -C shallow-graph checkout --orphan no-shallow && 141 test_commit -C shallow-graph --no-tag no-shallow && 142 git init notshallow-graph && 143 git -C notshallow-graph -c fetch.writeCommitGraph=true \ 144 fetch ../shallow-graph/.git "refs/heads/*:refs/remotes/shallow/*" && 145 test_commit -C shallow-graph --no-tag no-shallow-2 && 146 rejected=$(git -C shallow-graph rev-parse main) && 147 ( 148 cd notshallow-graph && 149 git -c fetch.writeCommitGraph=true \ 150 fetch ../shallow-graph/.git "refs/heads/*:refs/remotes/shallow/*" && 151 git for-each-ref --format="%(refname)" >actual.refs && 152 echo refs/remotes/shallow/no-shallow >expect.refs && 153 test_cmp expect.refs actual.refs && 154 test-tool read-graph commit-info shallow/no-shallow && 155 test_expect_code 1 \ 156 test-tool read-graph commit-info $rejected 2>/dev/null 157 ) 158 ' 159 160 test_expect_success 'fetch --update-shallow' ' 161 ( 162 cd shallow && 163 git checkout main && 164 commit 7 && 165 git tag -m foo heavy-tag HEAD^ && 166 git tag light-tag HEAD^:tracked 167 ) && 168 ( 169 cd notshallow && 170 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* && 171 git fsck && 172 git for-each-ref --sort=refname --format="%(refname)" >actual.refs && 173 cat <<-\EOF >expect.refs && 174 refs/remotes/shallow/main 175 refs/remotes/shallow/no-shallow 176 refs/tags/heavy-tag 177 refs/tags/light-tag 178 EOF 179 test_cmp expect.refs actual.refs && 180 git log --format=%s shallow/main >actual && 181 test_write_lines 7 6 5 4 3 >expect && 182 test_cmp expect actual 183 ) 184 ' 185 186 test_expect_success 'fetch --update-shallow into a repo with submodules' ' 187 test_config_global protocol.file.allow always && 188 189 git init a-submodule && 190 test_commit -C a-submodule foo && 191 192 test_when_finished "rm -rf repo-with-sub" && 193 git init repo-with-sub && 194 git -C repo-with-sub submodule add ../a-submodule a-submodule && 195 git -C repo-with-sub commit -m "added submodule" && 196 git -C repo-with-sub fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* 197 ' 198 199 test_expect_success 'fetch --update-shallow a commit that is also a shallow point into a repo with submodules' ' 200 test_when_finished "rm -rf repo-with-sub" && 201 git init repo-with-sub && 202 git -c protocol.file.allow=always -C repo-with-sub \ 203 submodule add ../a-submodule a-submodule && 204 git -C repo-with-sub commit -m "added submodule" && 205 206 SHALLOW=$(cat shallow/.git/shallow) && 207 git -C repo-with-sub fetch --update-shallow ../shallow/.git "$SHALLOW":refs/heads/a-shallow 208 ' 209 210 test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' ' 211 ( 212 cd shallow && 213 git checkout main && 214 commit 8 && 215 git tag -m foo heavy-tag-for-graph HEAD^ && 216 git tag light-tag-for-graph HEAD^:tracked 217 ) && 218 test_config -C notshallow fetch.writeCommitGraph true && 219 ( 220 cd notshallow && 221 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* && 222 git fsck && 223 git for-each-ref --sort=refname --format="%(refname)" >actual.refs && 224 cat <<-EOF >expect.refs && 225 refs/remotes/shallow/main 226 refs/remotes/shallow/no-shallow 227 refs/tags/heavy-tag 228 refs/tags/heavy-tag-for-graph 229 refs/tags/light-tag 230 refs/tags/light-tag-for-graph 231 EOF 232 test_cmp expect.refs actual.refs && 233 git log --format=%s shallow/main >actual && 234 test_write_lines 8 7 6 5 4 3 >expect && 235 test_cmp expect actual 236 ) 237 ' 238 239 test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' ' 240 cp -R .git read-only.git && 241 test_when_finished "find read-only.git -type d -print | xargs chmod +w" && 242 find read-only.git -print | xargs chmod -w && 243 git clone --no-local --depth=2 read-only.git from-read-only && 244 git --git-dir=from-read-only/.git log --format=%s >actual && 245 test_write_lines add-1-back 4 >expect && 246 test_cmp expect actual 247 ' 248 249 test_expect_success '.git/shallow is edited by repack' ' 250 git init shallow-server && 251 test_commit -C shallow-server A && 252 test_commit -C shallow-server B && 253 git -C shallow-server checkout -b branch && 254 test_commit -C shallow-server C && 255 test_commit -C shallow-server E && 256 test_commit -C shallow-server D && 257 d="$(git -C shallow-server rev-parse --verify D^0)" && 258 git -C shallow-server checkout main && 259 260 git clone --depth=1 --no-tags --no-single-branch \ 261 "file://$PWD/shallow-server" shallow-client && 262 263 : now remove the branch and fetch with prune && 264 git -C shallow-server branch -D branch && 265 git -C shallow-client fetch --prune --depth=1 \ 266 origin "+refs/heads/*:refs/remotes/origin/*" && 267 git -C shallow-client repack -adfl && 268 test_must_fail git -C shallow-client rev-parse --verify $d^0 && 269 test_grep ! $d shallow-client/.git/shallow && 270 271 git -C shallow-server branch branch-orig $d && 272 git -C shallow-client fetch --prune --depth=2 \ 273 origin "+refs/heads/*:refs/remotes/origin/*" 274 ' 275 276 test_expect_success 'fetch --deepen does not truncate' ' 277 git clone --no-local .git full-clone && 278 git -C full-clone rev-parse --is-shallow-repository >expect && 279 git -C full-clone log --oneline >>expect && 280 git -C full-clone fetch --deepen=1 && 281 git -C full-clone rev-parse --is-shallow-repository >actual && 282 git -C full-clone log --oneline >>actual && 283 test_cmp expect actual 284 ' 285 286 . "$TEST_DIRECTORY"/lib-httpd.sh 287 start_httpd 288 289 REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo" 290 291 test_expect_success 'shallow fetches check connectivity before writing shallow file' ' 292 rm -rf "$REPO" client && 293 294 git init "$REPO" && 295 test_commit -C "$REPO" one && 296 test_commit -C "$REPO" two && 297 test_commit -C "$REPO" three && 298 299 git init client && 300 301 # Use protocol v2 to ensure that shallow information is sent exactly 302 # once by the server, since we are planning to manipulate it. 303 git -C "$REPO" config protocol.version 2 && 304 git -C client config protocol.version 2 && 305 306 git -C client fetch --depth=2 "$HTTPD_URL/one_time_script/repo" main:a_branch && 307 308 # Craft a situation in which the server sends back an unshallow request 309 # with an empty packfile. This is done by refetching with a shorter 310 # depth (to ensure that the packfile is empty), and overwriting the 311 # shallow line in the response with the unshallow line we want. 312 write_script "$HTTPD_ROOT_PATH/one-time-script" <<-EOF && 313 sed "$(printf "$(test_oid perl)" "$(git -C "$REPO" rev-parse HEAD)" "$(git -C "$REPO" rev-parse HEAD^)")" "\$1" 314 EOF 315 test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \ 316 fetch --depth=1 "$HTTPD_URL/one_time_script/repo" \ 317 main:a_branch && 318 319 # Ensure that the one-time-script script was used. 320 ! test -e "$HTTPD_ROOT_PATH/one-time-script" && 321 322 # Ensure that the resulting repo is consistent, despite our failure to 323 # fetch. 324 git -C client fsck 325 ' 326 327 # DO NOT add non-httpd-specific tests here, because the last part of this 328 # test script is only executed when httpd is available and enabled. 329 330 test_done