t7700-repack: add two new tests demonstrating repacking flaws
[git/vmiklos.git] / t / t7700-repack.sh
blobfa4772101fda56116698f2063572ebfef8d4d46a
1 #!/bin/sh
3 test_description='git repack works correctly'
5 . ./test-lib.sh
7 test_expect_success 'objects in packs marked .keep are not repacked' '
8 echo content1 > file1 &&
9 echo content2 > file2 &&
10 git add . &&
11 git commit -m initial_commit &&
12 # Create two packs
13 # The first pack will contain all of the objects except one
14 git rev-list --objects --all | grep -v file2 |
15 git pack-objects pack > /dev/null &&
16 # The second pack will contain the excluded object
17 packsha1=$(git rev-list --objects --all | grep file2 |
18 git pack-objects pack) &&
19 touch -r pack-$packsha1.pack pack-$packsha1.keep &&
20 objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
21 sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
22 mv pack-* .git/objects/pack/ &&
23 git repack -A -d -l &&
24 git prune-packed &&
25 for p in .git/objects/pack/*.idx; do
26 idx=$(basename $p)
27 test "pack-$packsha1.idx" = "$idx" && continue
28 if git verify-pack -v $p | egrep "^$objsha1"; then
29 found_duplicate_object=1
30 echo "DUPLICATE OBJECT FOUND"
31 break
33 done &&
34 test -z "$found_duplicate_object"
37 test_expect_success 'loose objects in alternate ODB are not repacked' '
38 mkdir alt_objects &&
39 echo `pwd`/alt_objects > .git/objects/info/alternates &&
40 echo content3 > file3 &&
41 objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
42 git add file3 &&
43 git commit -m commit_file3 &&
44 git repack -a -d -l &&
45 git prune-packed &&
46 for p in .git/objects/pack/*.idx; do
47 if git verify-pack -v $p | egrep "^$objsha1"; then
48 found_duplicate_object=1
49 echo "DUPLICATE OBJECT FOUND"
50 break
52 done &&
53 test -z "$found_duplicate_object"
56 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
57 mkdir alt_objects/pack
58 mv .git/objects/pack/* alt_objects/pack &&
59 git repack -a &&
60 myidx=$(ls -1 .git/objects/pack/*.idx) &&
61 test -f "$myidx" &&
62 for p in alt_objects/pack/*.idx; do
63 git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
64 done | while read sha1 rest; do
65 if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
66 echo "Missing object in local pack: $sha1"
67 return 1
69 done
72 test_expect_failure 'packed obs in alternate ODB kept pack are repacked' '
73 # swap the .keep so the commit object is in the pack with .keep
74 for p in alt_objects/pack/*.pack
76 base_name=$(basename $p .pack)
77 if test -f alt_objects/pack/$base_name.keep
78 then
79 rm alt_objects/pack/$base_name.keep
80 else
81 touch alt_objects/pack/$base_name.keep
83 done
84 git repack -a -d &&
85 myidx=$(ls -1 .git/objects/pack/*.idx) &&
86 test -f "$myidx" &&
87 for p in alt_objects/pack/*.idx; do
88 git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
89 done | while read sha1 rest; do
90 if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
91 echo "Missing object in local pack: $sha1"
92 return 1
94 done
97 test_expect_failure 'packed unreachable obs in alternate ODB are not loosened' '
98 rm -f alt_objects/pack/*.keep &&
99 mv .git/objects/pack/* alt_objects/pack/ &&
100 csha1=$(git rev-parse HEAD^{commit}) &&
101 git reset --hard HEAD^ &&
102 sleep 1 &&
103 git reflog expire --expire=now --expire-unreachable=now --all &&
104 # The pack-objects call on the next line is equivalent to
105 # git repack -A -d without the call to prune-packed
106 git pack-objects --honor-pack-keep --non-empty --all --reflog \
107 --unpack-unreachable </dev/null pack &&
108 rm -f .git/objects/pack/* &&
109 mv pack-* .git/objects/pack/ &&
110 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
111 egrep "^$csha1 " | sort | uniq | wc -l) &&
112 echo > .git/objects/info/alternates &&
113 test_must_fail git show $csha1
116 test_done