Git 2.45
[git/gitster.git] / t / t5331-pack-objects-stdin.sh
blob2dcf1eeceeb65c4c034cb769f4b1d5fae3b79423
1 #!/bin/sh
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
8 . ./test-lib.sh
10 packed_objects () {
11 git show-index <"$1" >tmp-object-list &&
12 cut -d' ' -f2 tmp-object-list | sort &&
13 rm tmp-object-list
16 test_expect_success 'setup for --stdin-packs tests' '
17 git init stdin-packs &&
19 cd stdin-packs &&
21 test_commit A &&
22 test_commit B &&
23 test_commit C &&
25 for id in A B C
27 git pack-objects .git/objects/pack/pack-$id \
28 --incremental --revs <<-EOF || exit 1
29 refs/tags/$id
30 EOF
31 done &&
33 ls -la .git/objects/pack
37 test_expect_success '--stdin-packs with excluded packs' '
39 cd stdin-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 &&
46 $PACK_A
47 ^$PACK_B
48 $PACK_C
49 EOF
52 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
53 git show-index <$(ls .git/objects/pack/pack-C-*.idx)
54 ) >expect.raw &&
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' '
65 cd stdin-packs &&
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' '
74 cd stdin-packs &&
75 test_must_fail git pack-objects --stdin-packs --revs out \
76 </dev/null 2>err &&
77 test_grep "cannot use internal rev list with --stdin-packs" err
81 test_expect_success '--stdin-packs with loose objects' '
83 cd stdin-packs &&
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 &&
92 $PACK_A
93 ^$PACK_B
94 $PACK_C
95 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
103 ) >expect.raw &&
104 ls -la . &&
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' '
115 cd stdin-packs &&
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 &&
130 $PACK_A
131 ^$PACK_B
132 $PACK_C
133 $PACK_D
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
142 ) >expect.raw &&
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" &&
154 git init repo &&
156 cd repo &&
157 test_commit "commit" &&
158 git repack -ad &&
161 basename .git/objects/pack/pack-*.pack &&
162 basename .git/objects/pack/pack-*.pack
163 } >packfiles &&
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" &&
175 git init repo &&
177 cd repo &&
178 test_commit "commit" &&
179 git repack -ad &&
182 basename .git/objects/pack/pack-*.pack &&
183 printf "^%s\n" "$(basename .git/objects/pack/pack-*.pack)"
184 } >packfiles &&
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.
196 git init shared &&
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.
213 git init shared &&
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
220 # databases.
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
228 } >packfiles &&
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
240 test_done