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/t5604-clone-reference.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 / t5604-clone-reference.sh` 411 lines ยท 11308 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (C) 2006 Martin Waitz 4 # 5 6 test_description='test clone --reference' 7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 9 10 . ./test-lib.sh 11 12 base_dir=$(pwd) 13 14 U=$base_dir/UPLOAD_LOG 15 16 # create a commit in repo $1 with name $2 17 commit_in () { 18 ( 19 cd "$1" && 20 echo "$2" >"$2" && 21 git add "$2" && 22 git commit -m "$2" 23 ) 24 } 25 26 # check that there are $2 loose objects in repo $1 27 test_objcount () { 28 echo "$2" >expect && 29 git -C "$1" count-objects >actual.raw && 30 cut -d' ' -f1 actual && 31 test_cmp expect actual 32 } 33 34 test_expect_success 'preparing first repository' ' 35 test_create_repo A && 36 commit_in A file1 37 ' 38 39 test_expect_success 'preparing second repository' ' 40 git clone A B && 41 commit_in B file2 && 42 git -C B repack -ad && 43 git -C B prune 44 ' 45 46 test_expect_success 'cloning with reference (-l -s)' ' 47 git clone -l -s --reference B A C 48 ' 49 50 test_expect_success 'existence of info/alternates' ' 51 test_line_count = 2 C/.git/objects/info/alternates 52 ' 53 54 test_expect_success 'pulling from reference' ' 55 git -C C pull ../B main 56 ' 57 58 test_expect_success 'that reference gets used' ' 59 test_objcount C 0 60 ' 61 62 test_expect_success 'cloning with reference (no -l -s)' ' 63 GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D 64 ' 65 66 test_expect_success 'fetched no objects' ' 67 test -s "$U.D" && 68 test_grep ! " want" "$U.D" 69 ' 70 71 test_expect_success 'existence of info/alternates' ' 72 test_line_count = 1 D/.git/objects/info/alternates 73 ' 74 75 test_expect_success 'pulling from reference' ' 76 git -C D pull ../B main 77 ' 78 79 test_expect_success 'that reference gets used' ' 80 test_objcount D 0 81 ' 82 83 test_expect_success 'updating origin' ' 84 commit_in A file3 && 85 git -C A repack -ad && 86 git -C A prune 87 ' 88 89 test_expect_success 'pulling changes from origin' ' 90 git -C C pull --no-rebase origin 91 ' 92 93 # the 2 local objects are commit and tree from the merge 94 test_expect_success 'that alternate to origin gets used' ' 95 test_objcount C 2 96 ' 97 98 test_expect_success 'pulling changes from origin' ' 99 git -C D pull --no-rebase origin 100 ' 101 102 # the 5 local objects are expected; file3 blob, commit in A to add it 103 # and its tree, and 2 are our tree and the merge commit. 104 test_expect_success 'check objects expected to exist locally' ' 105 test_objcount D 5 106 ' 107 108 test_expect_success 'preparing alternate repository #1' ' 109 test_create_repo F && 110 commit_in F file1 111 ' 112 113 test_expect_success 'cloning alternate repo #2 and adding changes to repo #1' ' 114 git clone F G && 115 commit_in F file2 116 ' 117 118 test_expect_success 'cloning alternate repo #1, using #2 as reference' ' 119 git clone --reference G F H 120 ' 121 122 test_expect_success 'cloning with reference being subset of source (-l -s)' ' 123 git clone -l -s --reference A B E 124 ' 125 126 test_expect_success 'cloning with multiple references drops duplicates' ' 127 git clone -s --reference B --reference A --reference B A dups && 128 test_line_count = 2 dups/.git/objects/info/alternates 129 ' 130 131 test_expect_success 'clone with reference from a tagged repository' ' 132 ( 133 cd A && git tag -a -m tagged foo 134 ) && 135 git clone --reference=A A I 136 ' 137 138 test_expect_success 'prepare branched repository' ' 139 git clone A J && 140 ( 141 cd J && 142 git checkout -b other main^ && 143 echo other >otherfile && 144 git add otherfile && 145 git commit -m other && 146 git checkout main 147 ) 148 ' 149 150 test_expect_success 'fetch with incomplete alternates' ' 151 git init K && 152 echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates && 153 ( 154 cd K && 155 git remote add J "file://$base_dir/J" && 156 GIT_TRACE_PACKET=$U.K git fetch J 157 ) && 158 main_object=$(git -C A rev-parse --verify refs/heads/main) && 159 test -s "$U.K" && 160 test_grep ! " want $main_object" "$U.K" && 161 tag_object=$(git -C A rev-parse --verify refs/tags/foo) && 162 test_grep ! " want $tag_object" "$U.K" 163 ' 164 165 test_expect_success 'clone using repo with gitfile as a reference' ' 166 git clone --separate-git-dir=L A M && 167 git clone --reference=M A N && 168 echo "$base_dir/L/objects" >expected && 169 test_cmp expected "$base_dir/N/.git/objects/info/alternates" 170 ' 171 172 test_expect_success 'clone using repo pointed at by gitfile as reference' ' 173 git clone --reference=M/.git A O && 174 echo "$base_dir/L/objects" >expected && 175 test_cmp expected "$base_dir/O/.git/objects/info/alternates" 176 ' 177 178 test_expect_success 'clone and dissociate from reference' ' 179 git init P && 180 ( 181 cd P && test_commit one 182 ) && 183 git clone P Q && 184 ( 185 cd Q && test_commit two 186 ) && 187 git clone --no-local --reference=P Q R && 188 git clone --no-local --reference=P --dissociate Q S && 189 # removing the reference P would corrupt R but not S 190 rm -fr P && 191 test_must_fail git -C R fsck && 192 git -C S fsck 193 ' 194 test_expect_success 'clone, dissociate from partial reference and repack' ' 195 rm -fr P Q R && 196 git init P && 197 ( 198 cd P && 199 test_commit one && 200 git repack && 201 test_commit two && 202 git repack 203 ) && 204 git clone --bare P Q && 205 ( 206 cd P && 207 git checkout -b second && 208 test_commit three && 209 git repack 210 ) && 211 git clone --bare --dissociate --reference=P Q R && 212 ls R/objects/pack/*.pack >packs.txt && 213 test_line_count = 1 packs.txt 214 ' 215 216 test_expect_success 'clone, dissociate from alternates' ' 217 rm -fr A B C && 218 test_create_repo A && 219 commit_in A file1 && 220 git clone --reference=A A B && 221 test_line_count = 1 B/.git/objects/info/alternates && 222 git clone --local --dissociate B C && 223 ! test -f C/.git/objects/info/alternates && 224 ( cd C && git fsck ) 225 ' 226 227 test_expect_success 'setup repo with garbage in objects/*' ' 228 git init S && 229 ( 230 cd S && 231 test_commit A && 232 233 cd .git/objects && 234 >.some-hidden-file && 235 >some-file && 236 mkdir .some-hidden-dir && 237 >.some-hidden-dir/some-file && 238 >.some-hidden-dir/.some-dot-file && 239 mkdir some-dir && 240 >some-dir/some-file && 241 >some-dir/.some-dot-file 242 ) 243 ' 244 245 test_expect_success 'clone a repo with garbage in objects/*' ' 246 for option in --local --no-hardlinks --shared --dissociate 247 do 248 git clone $option S S$option || return 1 && 249 git -C S$option fsck || return 1 250 done && 251 find S-* -name "*some*" | sort >actual && 252 cat >expected <<-EOF && 253 S--dissociate/.git/objects/.some-hidden-dir 254 S--dissociate/.git/objects/.some-hidden-dir/.some-dot-file 255 S--dissociate/.git/objects/.some-hidden-dir/some-file 256 S--dissociate/.git/objects/.some-hidden-file 257 S--dissociate/.git/objects/some-dir 258 S--dissociate/.git/objects/some-dir/.some-dot-file 259 S--dissociate/.git/objects/some-dir/some-file 260 S--dissociate/.git/objects/some-file 261 S--local/.git/objects/.some-hidden-dir 262 S--local/.git/objects/.some-hidden-dir/.some-dot-file 263 S--local/.git/objects/.some-hidden-dir/some-file 264 S--local/.git/objects/.some-hidden-file 265 S--local/.git/objects/some-dir 266 S--local/.git/objects/some-dir/.some-dot-file 267 S--local/.git/objects/some-dir/some-file 268 S--local/.git/objects/some-file 269 S--no-hardlinks/.git/objects/.some-hidden-dir 270 S--no-hardlinks/.git/objects/.some-hidden-dir/.some-dot-file 271 S--no-hardlinks/.git/objects/.some-hidden-dir/some-file 272 S--no-hardlinks/.git/objects/.some-hidden-file 273 S--no-hardlinks/.git/objects/some-dir 274 S--no-hardlinks/.git/objects/some-dir/.some-dot-file 275 S--no-hardlinks/.git/objects/some-dir/some-file 276 S--no-hardlinks/.git/objects/some-file 277 EOF 278 test_cmp expected actual 279 ' 280 281 test_expect_success SYMLINKS 'setup repo with manually symlinked or unknown files at objects/' ' 282 git init T && 283 ( 284 cd T && 285 git config gc.auto 0 && 286 test_commit A && 287 git gc && 288 test_commit B && 289 290 cd .git/objects && 291 mv pack packs && 292 ln -s packs pack && 293 find ?? -type d >loose-dirs && 294 last_loose=$(tail -n 1 loose-dirs) && 295 mv $last_loose a-loose-dir && 296 ln -s a-loose-dir $last_loose && 297 first_loose=$(head -n 1 loose-dirs) && 298 rm -f loose-dirs && 299 300 cd $first_loose && 301 obj=$(ls *) && 302 mv $obj ../an-object && 303 ln -s ../an-object $obj && 304 305 cd ../ && 306 echo unknown_content >unknown_file 307 ) && 308 git -C T fsck && 309 git -C T rev-list --all --objects >T.objects 310 ' 311 312 313 test_expect_success SYMLINKS 'clone repo with symlinked or unknown files at objects/' ' 314 # None of these options work when cloning locally, since T has 315 # symlinks in its `$GIT_DIR/objects` directory 316 for option in --local --no-hardlinks --dissociate 317 do 318 test_must_fail git clone $option T T$option 2>err || return 1 && 319 test_grep "symlink.*exists" err || return 1 320 done && 321 322 # But `--shared` clones should still work, even when specifying 323 # a local path *and* that repository has symlinks present in its 324 # `$GIT_DIR/objects` directory. 325 git clone --shared T T--shared && 326 git -C T--shared fsck && 327 git -C T--shared rev-list --all --objects >T--shared.objects && 328 test_cmp T.objects T--shared.objects && 329 ( 330 cd T--shared/.git/objects && 331 find . -type f | sort >../../../T--shared.objects-files.raw && 332 find . -type l | sort >../../../T--shared.objects-symlinks.raw 333 ) && 334 335 for raw in $(ls T*.raw) 336 do 337 sed -e "s!/../!/Y/!; s![0-9a-f]\{38,\}!Z!" -e "/commit-graph/d" \ 338 -e "/multi-pack-index/d" -e "/rev/d" <$raw >$raw.de-sha-1 && 339 sort $raw.de-sha-1 >$raw.de-sha || return 1 340 done && 341 342 echo ./info/alternates >expected-files && 343 test_cmp expected-files T--shared.objects-files.raw && 344 test_must_be_empty T--shared.objects-symlinks.raw 345 ' 346 347 test_expect_success SYMLINKS 'clone repo with symlinked objects directory' ' 348 test_when_finished "rm -fr sensitive malicious" && 349 350 mkdir -p sensitive && 351 echo "secret" >sensitive/file && 352 353 git init malicious && 354 rm -fr malicious/.git/objects && 355 ln -s "$(pwd)/sensitive" ./malicious/.git/objects && 356 357 test_must_fail git clone --local malicious clone 2>err && 358 359 test_path_is_missing clone && 360 test_grep "is a symlink, refusing to clone with --local" err 361 ' 362 363 test_expect_success 'dissociate from repo with commit graph' ' 364 git init orig && 365 # We are trying to make sure the dissociated repo can 366 # find the tree of the tip commit, so the test could still 367 # serve its purpose with an empty tree. But having actual 368 # content future-proofs us against any kind of internal 369 # empty-tree optimizations. 370 echo content >orig/file && 371 git -C orig add . && 372 git -C orig commit -m foo && 373 374 # We will use graph.git as our "local" source to dissociate 375 # from. 376 git clone --bare orig graph.git && 377 git -C graph.git commit-graph write --reachable && 378 379 # And then finally clone orig, using graph.git to get our objects. This 380 # must be non-bare so that we perform the checkout step, which will 381 # need to access the tree of HEAD, which we will have originally loaded 382 # via the commit graph. 383 git clone --no-local --reference graph.git --dissociate orig clone 384 ' 385 386 test_expect_success 'local clone from linked worktree carries over alternates' ' 387 rm -fr base derived derived-wt dst expect && 388 git init base && 389 test_commit -C base one && 390 git clone --shared base derived && 391 git -C derived worktree add ../derived-wt && 392 git clone derived-wt dst && 393 echo "$(pwd)/base/.git/objects" >expect && 394 test_cmp expect dst/.git/objects/info/alternates && 395 git -C dst fsck 396 ' 397 398 test_expect_success 'local clone from linked worktree resolves relative alternates' ' 399 rm -fr base derived derived-wt dst expect && 400 git init base && 401 test_commit -C base one && 402 git clone --shared base derived && 403 echo "../../../base/.git/objects" >derived/.git/objects/info/alternates && 404 git -C derived worktree add ../derived-wt && 405 git clone derived-wt dst && 406 echo "$(pwd)/base/.git/objects" >expect && 407 test_cmp expect dst/.git/objects/info/alternates && 408 git -C dst fsck 409 ' 410 411 test_done