3 test_description='git repack works correctly'
8 test_commit "$@" 1>&2 &&
9 SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
10 echo pack-${SHA1}.pack
13 test_no_missing_in_packs () {
14 myidx=$(ls -1 .git/objects/pack/*.idx) &&
15 test_path_is_file "$myidx" &&
16 git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
17 sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig &&
18 git verify-pack -v $myidx >dest.raw &&
19 cut -d" " -f1 dest.raw | sort >dest &&
20 comm -23 orig dest >missing &&
21 test_must_be_empty missing
24 # we expect $packsha1 and $objsha1 to be defined
25 test_has_duplicate_object () {
26 want_duplicate_object="$1"
27 found_duplicate_object=false
28 for p in .git/objects/pack/*.idx
31 test "pack-$packsha1.idx" = "$idx" && continue
32 git verify-pack -v $p >packlist || return $?
33 if grep "^$objsha1" packlist
35 found_duplicate_object=true
36 echo "DUPLICATE OBJECT FOUND"
40 test "$want_duplicate_object" = "$found_duplicate_object"
43 test_expect_success 'objects in packs marked .keep are not repacked' '
44 echo content1 >file1 &&
45 echo content2 >file2 &&
48 git commit -m initial_commit &&
50 # The first pack will contain all of the objects except one
51 git rev-list --objects --all | grep -v file2 |
52 git pack-objects pack &&
53 # The second pack will contain the excluded object
54 packsha1=$(git rev-list --objects --all | grep file2 |
55 git pack-objects pack) &&
56 >pack-$packsha1.keep &&
57 objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
58 sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
59 mv pack-* .git/objects/pack/ &&
60 git repack -A -d -l &&
62 test_has_duplicate_object false
65 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
66 # build on $objsha1, $packsha1, and .keep state from previous
68 test_has_duplicate_object true
71 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
72 # build on $objsha1, $packsha1, and .keep state from previous
73 git -c repack.writebitmaps=true repack -Adl &&
74 test_has_duplicate_object true
77 test_expect_success 'loose objects in alternate ODB are not repacked' '
79 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
80 echo content3 >file3 &&
81 objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
84 git commit -m commit_file3 &&
85 git repack -a -d -l &&
87 test_has_duplicate_object false
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 test_no_missing_in_packs
97 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
98 rm -f .git/objects/pack/* &&
99 echo new_content >>file1 &&
102 git commit -m more_content &&
105 test_no_missing_in_packs
108 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
109 # swap the .keep so the commit object is in the pack with .keep
110 for p in alt_objects/pack/*.pack
112 base_name=$(basename $p .pack) &&
113 if test_path_is_file alt_objects/pack/$base_name.keep
115 rm alt_objects/pack/$base_name.keep
117 touch alt_objects/pack/$base_name.keep
121 test_no_missing_in_packs
124 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
125 rm -f alt_objects/pack/*.keep &&
126 mv .git/objects/pack/* alt_objects/pack/ &&
127 csha1=$(git rev-parse HEAD^{commit}) &&
128 git reset --hard HEAD^ &&
130 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
131 # The pack-objects call on the next line is equivalent to
132 # git repack -A -d without the call to prune-packed
133 git pack-objects --honor-pack-keep --non-empty --all --reflog \
134 --unpack-unreachable </dev/null pack &&
135 rm -f .git/objects/pack/* &&
136 mv pack-* .git/objects/pack/ &&
137 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
138 grep "^$csha1 " | sort | uniq | wc -l) &&
139 echo >.git/objects/info/alternates &&
140 test_must_fail git show $csha1
143 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
144 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
145 echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
146 rm -f .git/objects/pack/* &&
147 mv pack-* .git/objects/pack/ &&
148 # The pack-objects call on the next line is equivalent to
149 # git repack -A -d without the call to prune-packed
150 git pack-objects --honor-pack-keep --non-empty --all --reflog \
151 --unpack-unreachable </dev/null pack &&
152 rm -f .git/objects/pack/* &&
153 mv pack-* .git/objects/pack/ &&
154 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
155 grep "^$csha1 " | sort | uniq | wc -l) &&
156 echo >.git/objects/info/alternates &&
157 test_must_fail git show $csha1
160 test_expect_success 'objects made unreachable by grafts only are kept' '
162 git commit --allow-empty -m "commit 4" &&
163 H0=$(git rev-parse HEAD) &&
164 H1=$(git rev-parse HEAD^) &&
165 H2=$(git rev-parse HEAD^^) &&
166 echo "$H0 $H2" >.git/info/grafts &&
167 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
172 test_expect_success 'repack --keep-pack' '
173 test_create_repo keep-pack &&
176 P1=$(commit_and_pack 1) &&
177 P2=$(commit_and_pack 2) &&
178 P3=$(commit_and_pack 3) &&
179 P4=$(commit_and_pack 4) &&
180 ls .git/objects/pack/*.pack >old-counts &&
181 test_line_count = 4 old-counts &&
182 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
183 ls .git/objects/pack/*.pack >new-counts &&
184 grep -q $P1 new-counts &&
185 grep -q $P4 new-counts &&
186 test_line_count = 3 new-counts &&
191 test_expect_success 'bitmaps are created by default in bare repos' '
192 git clone --bare .git bare.git &&
193 git -C bare.git repack -ad &&
194 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
195 test_path_is_file "$bitmap"
198 test_expect_success 'incremental repack does not complain' '
199 git -C bare.git repack -q 2>repack.err &&
200 test_must_be_empty repack.err
203 test_expect_success 'bitmaps can be disabled on bare repos' '
204 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
205 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
209 test_expect_success 'no bitmaps created if .keep files present' '
210 pack=$(ls bare.git/objects/pack/*.pack) &&
211 test_path_is_file "$pack" &&
212 keep=${pack%.pack}.keep &&
213 test_when_finished "rm -f \"\$keep\"" &&
215 git -C bare.git repack -ad 2>stderr &&
216 test_must_be_empty stderr &&
217 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
218 test_must_be_empty actual
221 test_expect_success 'auto-bitmaps do not complain if unavailable' '
222 test_config -C bare.git pack.packSizeLimit 1M &&
223 blob=$(test-tool genrandom big $((1024*1024)) |
224 git -C bare.git hash-object -w --stdin) &&
225 git -C bare.git update-ref refs/tags/big $blob &&
226 git -C bare.git repack -ad 2>stderr &&
227 test_must_be_empty stderr &&
228 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
229 test_must_be_empty actual