3 test_description
='git repack works correctly'
7 test_expect_success
'objects in packs marked .keep are not repacked' '
8 echo content1 > file1 &&
9 echo content2 > file2 &&
12 git commit -m initial_commit &&
14 # The first pack will contain all of the objects except one
15 git rev-list --objects --all | grep -v file2 |
16 git pack-objects pack > /dev/null &&
17 # The second pack will contain the excluded object
18 packsha1=$(git rev-list --objects --all | grep file2 |
19 git pack-objects pack) &&
20 touch -r pack-$packsha1.pack pack-$packsha1.keep &&
21 objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
22 sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
23 mv pack-* .git/objects/pack/ &&
24 git repack --no-pack-kept-objects -A -d -l &&
26 for p in .git/objects/pack/*.idx; do
28 test "pack-$packsha1.idx" = "$idx" && continue
29 if git verify-pack -v $p | egrep "^$objsha1"; then
30 found_duplicate_object=1
31 echo "DUPLICATE OBJECT FOUND"
35 test -z "$found_duplicate_object"
38 test_expect_success
'writing bitmaps via command-line can duplicate .keep objects' '
39 # build on $objsha1, $packsha1, and .keep state from previous
41 test_when_finished "found_duplicate_object=" &&
42 for p in .git/objects/pack/*.idx; do
44 test "pack-$packsha1.idx" = "$idx" && continue
45 if git verify-pack -v $p | egrep "^$objsha1"; then
46 found_duplicate_object=1
47 echo "DUPLICATE OBJECT FOUND"
51 test "$found_duplicate_object" = 1
54 test_expect_success
'writing bitmaps via config can duplicate .keep objects' '
55 # build on $objsha1, $packsha1, and .keep state from previous
56 git -c repack.writebitmaps=true repack -Adl &&
57 test_when_finished "found_duplicate_object=" &&
58 for p in .git/objects/pack/*.idx; do
60 test "pack-$packsha1.idx" = "$idx" && continue
61 if git verify-pack -v $p | egrep "^$objsha1"; then
62 found_duplicate_object=1
63 echo "DUPLICATE OBJECT FOUND"
67 test "$found_duplicate_object" = 1
70 test_expect_success
'loose objects in alternate ODB are not repacked' '
72 echo `pwd`/alt_objects > .git/objects/info/alternates &&
73 echo content3 > file3 &&
74 objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
77 git commit -m commit_file3 &&
78 git repack -a -d -l &&
80 for p in .git/objects/pack/*.idx; do
81 if git verify-pack -v $p | egrep "^$objsha1"; then
82 found_duplicate_object=1
83 echo "DUPLICATE OBJECT FOUND"
87 test -z "$found_duplicate_object"
90 test_expect_success
'packed obs in alt ODB are repacked even when local repo is packless' '
91 mkdir alt_objects/pack &&
92 mv .git/objects/pack/* alt_objects/pack &&
94 myidx=$(ls -1 .git/objects/pack/*.idx) &&
96 for p in alt_objects/pack/*.idx; do
97 git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
98 done | while read sha1 rest; do
99 if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
100 echo "Missing object in local pack: $sha1"
106 test_expect_success
'packed obs in alt ODB are repacked when local repo has packs' '
107 rm -f .git/objects/pack/* &&
108 echo new_content >> file1 &&
111 git commit -m more_content &&
114 myidx=$(ls -1 .git/objects/pack/*.idx) &&
116 for p in alt_objects/pack/*.idx; do
117 git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
118 done | while read sha1 rest; do
119 if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
120 echo "Missing object in local pack: $sha1"
126 test_expect_success
'packed obs in alternate ODB kept pack are repacked' '
127 # swap the .keep so the commit object is in the pack with .keep
128 for p in alt_objects/pack/*.pack
130 base_name=$(basename $p .pack) &&
131 if test -f alt_objects/pack/$base_name.keep
133 rm alt_objects/pack/$base_name.keep
135 touch alt_objects/pack/$base_name.keep
139 myidx=$(ls -1 .git/objects/pack/*.idx) &&
141 for p in alt_objects/pack/*.idx; do
142 git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
143 done | while read sha1 rest; do
144 if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
145 echo "Missing object in local pack: $sha1"
151 test_expect_success
'packed unreachable obs in alternate ODB are not loosened' '
152 rm -f alt_objects/pack/*.keep &&
153 mv .git/objects/pack/* alt_objects/pack/ &&
154 csha1=$(git rev-parse HEAD^{commit}) &&
155 git reset --hard HEAD^ &&
157 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
158 # The pack-objects call on the next line is equivalent to
159 # git repack -A -d without the call to prune-packed
160 git pack-objects --honor-pack-keep --non-empty --all --reflog \
161 --unpack-unreachable </dev/null pack &&
162 rm -f .git/objects/pack/* &&
163 mv pack-* .git/objects/pack/ &&
164 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
165 egrep "^$csha1 " | sort | uniq | wc -l) &&
166 echo > .git/objects/info/alternates &&
167 test_must_fail git show $csha1
170 test_expect_success
'local packed unreachable obs that exist in alternate ODB are not loosened' '
171 echo `pwd`/alt_objects > .git/objects/info/alternates &&
172 echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
173 rm -f .git/objects/pack/* &&
174 mv pack-* .git/objects/pack/ &&
175 # The pack-objects call on the next line is equivalent to
176 # git repack -A -d without the call to prune-packed
177 git pack-objects --honor-pack-keep --non-empty --all --reflog \
178 --unpack-unreachable </dev/null pack &&
179 rm -f .git/objects/pack/* &&
180 mv pack-* .git/objects/pack/ &&
181 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
182 egrep "^$csha1 " | sort | uniq | wc -l) &&
183 echo > .git/objects/info/alternates &&
184 test_must_fail git show $csha1
187 test_expect_success
'objects made unreachable by grafts only are kept' '
189 git commit --allow-empty -m "commit 4" &&
190 H0=$(git rev-parse HEAD) &&
191 H1=$(git rev-parse HEAD^) &&
192 H2=$(git rev-parse HEAD^^) &&
193 echo "$H0 $H2" > .git/info/grafts &&
194 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&