| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test `test-tool find-pack`' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup' ' |
| 8 | test_commit one && |
| 9 | test_commit two && |
| 10 | test_commit three && |
| 11 | test_commit four && |
| 12 | test_commit five |
| 13 | ' |
| 14 | |
| 15 | test_expect_success 'repack everything into a single packfile' ' |
| 16 | git repack -a -d --no-write-bitmap-index && |
| 17 | |
| 18 | head_commit_pack=$(test-tool find-pack HEAD) && |
| 19 | head_tree_pack=$(test-tool find-pack HEAD^{tree}) && |
| 20 | one_pack=$(test-tool find-pack HEAD:one.t) && |
| 21 | three_pack=$(test-tool find-pack HEAD:three.t) && |
| 22 | old_commit_pack=$(test-tool find-pack HEAD~4) && |
| 23 | |
| 24 | test-tool find-pack --check-count 1 HEAD && |
| 25 | test-tool find-pack --check-count=1 HEAD^{tree} && |
| 26 | ! test-tool find-pack --check-count=0 HEAD:one.t && |
| 27 | ! test-tool find-pack -c 2 HEAD:one.t && |
| 28 | test-tool find-pack -c 1 HEAD:three.t && |
| 29 | |
| 30 | # Packfile exists at the right path |
| 31 | case "$head_commit_pack" in |
| 32 | ".git/objects/pack/pack-"*".pack") true ;; |
| 33 | *) false ;; |
| 34 | esac && |
| 35 | test -f "$head_commit_pack" && |
| 36 | |
| 37 | # Everything is in the same pack |
| 38 | test "$head_commit_pack" = "$head_tree_pack" && |
| 39 | test "$head_commit_pack" = "$one_pack" && |
| 40 | test "$head_commit_pack" = "$three_pack" && |
| 41 | test "$head_commit_pack" = "$old_commit_pack" |
| 42 | ' |
| 43 | |
| 44 | test_expect_success 'add more packfiles' ' |
| 45 | git rev-parse HEAD^{tree} HEAD:two.t HEAD:four.t >objects && |
| 46 | git pack-objects .git/objects/pack/mypackname1 >packhash1 <objects && |
| 47 | |
| 48 | git rev-parse HEAD~ HEAD~^{tree} HEAD:five.t >objects && |
| 49 | git pack-objects .git/objects/pack/mypackname2 >packhash2 <objects && |
| 50 | |
| 51 | head_commit_pack=$(test-tool find-pack HEAD) && |
| 52 | |
| 53 | # HEAD^{tree} is in 2 packfiles |
| 54 | test-tool find-pack HEAD^{tree} >head_tree_packs && |
| 55 | test_grep "$head_commit_pack" head_tree_packs && |
| 56 | test_grep mypackname1 head_tree_packs && |
| 57 | test_grep ! mypackname2 head_tree_packs && |
| 58 | test-tool find-pack --check-count 2 HEAD^{tree} && |
| 59 | ! test-tool find-pack --check-count 1 HEAD^{tree} && |
| 60 | |
| 61 | # HEAD:five.t is also in 2 packfiles |
| 62 | test-tool find-pack HEAD:five.t >five_packs && |
| 63 | test_grep "$head_commit_pack" five_packs && |
| 64 | test_grep ! mypackname1 five_packs && |
| 65 | test_grep mypackname2 five_packs && |
| 66 | test-tool find-pack -c 2 HEAD:five.t && |
| 67 | ! test-tool find-pack --check-count=0 HEAD:five.t |
| 68 | ' |
| 69 | |
| 70 | test_expect_success 'add more commits (as loose objects)' ' |
| 71 | test_config maintenance.auto false && |
| 72 | test_commit six && |
| 73 | test_commit seven && |
| 74 | |
| 75 | test -z "$(test-tool find-pack HEAD)" && |
| 76 | test -z "$(test-tool find-pack HEAD:six.t)" && |
| 77 | test-tool find-pack --check-count 0 HEAD && |
| 78 | test-tool find-pack -c 0 HEAD:six.t && |
| 79 | ! test-tool find-pack -c 1 HEAD:seven.t |
| 80 | ' |
| 81 | |
| 82 | test_done |