3 test_description
='pack-objects --stdin'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
11 git show-index
<"$1" >tmp-object-list
&&
12 cut
-d' ' -f2 tmp-object-list |
sort &&
16 test_expect_success
'setup for --stdin-packs tests' '
17 git init stdin-packs &&
27 git pack-objects .git/objects/pack/pack-$id \
28 --incremental --revs <<-EOF || exit 1
33 ls -la .git/objects/pack
37 test_expect_success
'--stdin-packs with excluded packs' '
41 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
42 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
43 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
45 git pack-objects test --stdin-packs <<-EOF &&
52 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
53 git show-index <$(ls .git/objects/pack/pack-C-*.idx)
55 git show-index <$(ls test-*.idx) >actual.raw &&
57 cut -d" " -f2 <expect.raw | sort >expect &&
58 cut -d" " -f2 <actual.raw | sort >actual &&
59 test_cmp expect actual
63 test_expect_success
'--stdin-packs is incompatible with --filter' '
66 test_must_fail git pack-objects --stdin-packs --stdout \
67 --filter=blob:none </dev/null 2>err &&
68 test_grep "cannot use --filter with --stdin-packs" err
72 test_expect_success
'--stdin-packs is incompatible with --revs' '
75 test_must_fail git pack-objects --stdin-packs --revs out \
77 test_grep "cannot use internal rev list with --stdin-packs" err
81 test_expect_success
'--stdin-packs with loose objects' '
85 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
86 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
87 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
89 test_commit D && # loose
91 git pack-objects test2 --stdin-packs --unpacked <<-EOF &&
98 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
99 git show-index <$(ls .git/objects/pack/pack-C-*.idx) &&
100 git rev-list --objects --no-object-names \
101 refs/tags/C..refs/tags/D
105 git show-index <$(ls test2-*.idx) >actual.raw &&
107 cut -d" " -f2 <expect.raw | sort >expect &&
108 cut -d" " -f2 <actual.raw | sort >actual &&
109 test_cmp expect actual
113 test_expect_success
'--stdin-packs with broken links' '
117 # make an unreachable object with a bogus parent
118 git cat-file -p HEAD >commit &&
119 sed "s/$(git rev-parse HEAD^)/$(test_oid zero)/" <commit |
120 git hash-object -w -t commit --stdin >in &&
122 git pack-objects .git/objects/pack/pack-D <in &&
124 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
125 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
126 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
127 PACK_D="$(basename .git/objects/pack/pack-D-*.pack)" &&
129 git pack-objects test3 --stdin-packs --unpacked <<-EOF &&
137 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
138 git show-index <$(ls .git/objects/pack/pack-C-*.idx) &&
139 git show-index <$(ls .git/objects/pack/pack-D-*.idx) &&
140 git rev-list --objects --no-object-names \
141 refs/tags/C..refs/tags/D
143 git show-index <$(ls test3-*.idx) >actual.raw &&
145 cut -d" " -f2 <expect.raw | sort >expect &&
146 cut -d" " -f2 <actual.raw | sort >actual &&
147 test_cmp expect actual
151 test_expect_success
'pack-objects --stdin with duplicate packfile' '
152 test_when_finished "rm -fr repo" &&
157 test_commit "commit" &&
161 basename .git/objects/pack/pack-*.pack &&
162 basename .git/objects/pack/pack-*.pack
165 git pack-objects --stdin-packs generated-pack <packfiles &&
166 packed_objects .git/objects/pack/pack-*.idx >expect &&
167 packed_objects generated-pack-*.idx >actual &&
168 test_cmp expect actual
172 test_expect_success
'pack-objects --stdin with same packfile excluded and included' '
173 test_when_finished "rm -fr repo" &&
178 test_commit "commit" &&
182 basename .git/objects/pack/pack-*.pack &&
183 printf "^%s\n" "$(basename .git/objects/pack/pack-*.pack)"
186 git pack-objects --stdin-packs generated-pack <packfiles &&
187 packed_objects generated-pack-*.idx >packed-objects &&
188 test_must_be_empty packed-objects
192 test_expect_success
'pack-objects --stdin with packfiles from alternate object database' '
193 test_when_finished "rm -fr shared member" &&
195 # Set up a shared repository with a single packfile.
197 test_commit -C shared "shared-objects" &&
198 git -C shared repack -ad &&
199 basename shared/.git/objects/pack/pack-*.pack >packfile &&
201 # Set up a repository that is connected to the shared repository. This
202 # repository has no objects on its own, but we still expect to be able
203 # to pack objects from its alternate.
204 git clone --shared shared member &&
205 git -C member pack-objects --stdin-packs generated-pack <packfile &&
206 test_cmp shared/.git/objects/pack/pack-*.pack member/generated-pack-*.pack
209 test_expect_success
'pack-objects --stdin with packfiles from main and alternate object database' '
210 test_when_finished "rm -fr shared member" &&
212 # Set up a shared repository with a single packfile.
214 test_commit -C shared "shared-commit" &&
215 git -C shared repack -ad &&
217 # Set up a repository that is connected to the shared repository. This
218 # repository has a second packfile so that we can verify that it is
219 # possible to write packs that include packfiles from different object
221 git clone --shared shared member &&
222 test_commit -C member "local-commit" &&
223 git -C member repack -dl &&
226 basename shared/.git/objects/pack/pack-*.pack &&
227 basename member/.git/objects/pack/pack-*.pack
231 packed_objects shared/.git/objects/pack/pack-*.idx &&
232 packed_objects member/.git/objects/pack/pack-*.idx
233 } | sort >expected-objects &&
235 git -C member pack-objects --stdin-packs generated-pack <packfiles &&
236 packed_objects member/generated-pack-*.idx >actual-objects &&
237 test_cmp expected-objects actual-objects