| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Google Inc. |
| 4 | # |
| 5 | |
| 6 | test_description='git-pack-object with missing base |
| 7 | |
| 8 | ' |
| 9 | |
| 10 | . ./test-lib.sh |
| 11 | |
| 12 | # Create A-B chain |
| 13 | # |
| 14 | test_expect_success 'setup base' ' |
| 15 | test_write_lines a b c d e f g h i >text && |
| 16 | echo side >side && |
| 17 | git update-index --add text side && |
| 18 | A=$(echo A | git commit-tree $(git write-tree)) && |
| 19 | |
| 20 | echo m >>text && |
| 21 | git update-index text && |
| 22 | B=$(echo B | git commit-tree $(git write-tree) -p $A) && |
| 23 | git update-ref HEAD $B |
| 24 | ' |
| 25 | |
| 26 | # Create repository with C whose parent is B. |
| 27 | # Repository contains C, C^{tree}, C:text, B, B^{tree}. |
| 28 | # Repository is missing B:text (best delta base for C:text). |
| 29 | # Repository is missing A (parent of B). |
| 30 | # Repository is missing A:side. |
| 31 | # |
| 32 | test_expect_success 'setup patch_clone' ' |
| 33 | base_objects=$(pwd)/.git/objects && |
| 34 | (mkdir patch_clone && |
| 35 | cd patch_clone && |
| 36 | git init && |
| 37 | echo "$base_objects" >.git/objects/info/alternates && |
| 38 | echo q >>text && |
| 39 | git read-tree $B && |
| 40 | git update-index text && |
| 41 | git update-ref HEAD $(echo C | git commit-tree $(git write-tree) -p $B) && |
| 42 | rm .git/objects/info/alternates && |
| 43 | |
| 44 | git --git-dir=../.git cat-file commit $B | |
| 45 | git hash-object -t commit -w --stdin && |
| 46 | |
| 47 | git --git-dir=../.git cat-file tree "$B^{tree}" | |
| 48 | git hash-object -t tree -w --stdin |
| 49 | ) && |
| 50 | C=$(git --git-dir=patch_clone/.git rev-parse HEAD) |
| 51 | ' |
| 52 | |
| 53 | # Clone patch_clone indirectly by cloning base and fetching. |
| 54 | # |
| 55 | test_expect_success 'indirectly clone patch_clone' ' |
| 56 | (mkdir user_clone && |
| 57 | cd user_clone && |
| 58 | git init && |
| 59 | git pull ../.git && |
| 60 | test $(git rev-parse HEAD) = $B && |
| 61 | |
| 62 | # The --path-walk feature of "git pack-objects" is not |
| 63 | # compatible with this kind of fetch from an incomplete repo. |
| 64 | GIT_TEST_PACK_PATH_WALK=0 && |
| 65 | export GIT_TEST_PACK_PATH_WALK && |
| 66 | |
| 67 | git pull ../patch_clone/.git && |
| 68 | test $(git rev-parse HEAD) = $C |
| 69 | ) |
| 70 | ' |
| 71 | |
| 72 | # Cloning the patch_clone directly should fail. |
| 73 | # |
| 74 | test_expect_success 'clone of patch_clone is incomplete' ' |
| 75 | (mkdir user_direct && |
| 76 | cd user_direct && |
| 77 | git init && |
| 78 | test_must_fail git fetch ../patch_clone/.git |
| 79 | ) |
| 80 | ' |
| 81 | |
| 82 | test_done |