]>
Commit | Line | Data |
---|---|---|
b7b8f048 PS |
1 | #!/bin/sh |
2 | ||
3 | test_description='pack-objects --stdin' | |
4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
6 | ||
7 | TEST_PASSES_SANITIZE_LEAK=true | |
8 | . ./test-lib.sh | |
9 | ||
732194b5 PS |
10 | packed_objects () { |
11 | git show-index <"$1" >tmp-object-list && | |
12 | cut -d' ' -f2 tmp-object-list | sort && | |
13 | rm tmp-object-list | |
14 | } | |
15 | ||
b7b8f048 PS |
16 | test_expect_success 'setup for --stdin-packs tests' ' |
17 | git init stdin-packs && | |
18 | ( | |
19 | cd stdin-packs && | |
20 | ||
21 | test_commit A && | |
22 | test_commit B && | |
23 | test_commit C && | |
24 | ||
25 | for id in A B C | |
26 | do | |
27 | git pack-objects .git/objects/pack/pack-$id \ | |
28 | --incremental --revs <<-EOF || exit 1 | |
29 | refs/tags/$id | |
30 | EOF | |
31 | done && | |
32 | ||
33 | ls -la .git/objects/pack | |
34 | ) | |
35 | ' | |
36 | ||
37 | test_expect_success '--stdin-packs with excluded packs' ' | |
38 | ( | |
39 | cd stdin-packs && | |
40 | ||
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)" && | |
44 | ||
45 | git pack-objects test --stdin-packs <<-EOF && | |
46 | $PACK_A | |
47 | ^$PACK_B | |
48 | $PACK_C | |
49 | EOF | |
50 | ||
51 | ( | |
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 && | |
56 | ||
57 | cut -d" " -f2 <expect.raw | sort >expect && | |
58 | cut -d" " -f2 <actual.raw | sort >actual && | |
59 | test_cmp expect actual | |
60 | ) | |
61 | ' | |
62 | ||
63 | test_expect_success '--stdin-packs is incompatible with --filter' ' | |
64 | ( | |
65 | cd stdin-packs && | |
66 | test_must_fail git pack-objects --stdin-packs --stdout \ | |
67 | --filter=blob:none </dev/null 2>err && | |
6789275d | 68 | test_grep "cannot use --filter with --stdin-packs" err |
b7b8f048 PS |
69 | ) |
70 | ' | |
71 | ||
72 | test_expect_success '--stdin-packs is incompatible with --revs' ' | |
73 | ( | |
74 | cd stdin-packs && | |
75 | test_must_fail git pack-objects --stdin-packs --revs out \ | |
76 | </dev/null 2>err && | |
6789275d | 77 | test_grep "cannot use internal rev list with --stdin-packs" err |
b7b8f048 PS |
78 | ) |
79 | ' | |
80 | ||
81 | test_expect_success '--stdin-packs with loose objects' ' | |
82 | ( | |
83 | cd stdin-packs && | |
84 | ||
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)" && | |
88 | ||
89 | test_commit D && # loose | |
90 | ||
91 | git pack-objects test2 --stdin-packs --unpacked <<-EOF && | |
92 | $PACK_A | |
93 | ^$PACK_B | |
94 | $PACK_C | |
95 | EOF | |
96 | ||
97 | ( | |
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 | |
102 | ||
103 | ) >expect.raw && | |
104 | ls -la . && | |
105 | git show-index <$(ls test2-*.idx) >actual.raw && | |
106 | ||
107 | cut -d" " -f2 <expect.raw | sort >expect && | |
108 | cut -d" " -f2 <actual.raw | sort >actual && | |
109 | test_cmp expect actual | |
110 | ) | |
111 | ' | |
112 | ||
113 | test_expect_success '--stdin-packs with broken links' ' | |
114 | ( | |
115 | cd stdin-packs && | |
116 | ||
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 && | |
121 | ||
122 | git pack-objects .git/objects/pack/pack-D <in && | |
123 | ||
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)" && | |
128 | ||
129 | git pack-objects test3 --stdin-packs --unpacked <<-EOF && | |
130 | $PACK_A | |
131 | ^$PACK_B | |
132 | $PACK_C | |
133 | $PACK_D | |
134 | EOF | |
135 | ||
136 | ( | |
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 && | |
144 | ||
145 | cut -d" " -f2 <expect.raw | sort >expect && | |
146 | cut -d" " -f2 <actual.raw | sort >actual && | |
147 | test_cmp expect actual | |
148 | ) | |
149 | ' | |
150 | ||
732194b5 PS |
151 | test_expect_success 'pack-objects --stdin with duplicate packfile' ' |
152 | test_when_finished "rm -fr repo" && | |
153 | ||
154 | git init repo && | |
155 | ( | |
156 | cd repo && | |
157 | test_commit "commit" && | |
158 | git repack -ad && | |
159 | ||
160 | { | |
161 | basename .git/objects/pack/pack-*.pack && | |
162 | basename .git/objects/pack/pack-*.pack | |
163 | } >packfiles && | |
164 | ||
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 | |
169 | ) | |
170 | ' | |
171 | ||
752b465c PS |
172 | test_expect_success 'pack-objects --stdin with same packfile excluded and included' ' |
173 | test_when_finished "rm -fr repo" && | |
174 | ||
175 | git init repo && | |
176 | ( | |
177 | cd repo && | |
178 | test_commit "commit" && | |
179 | git repack -ad && | |
180 | ||
181 | { | |
182 | basename .git/objects/pack/pack-*.pack && | |
183 | printf "^%s\n" "$(basename .git/objects/pack/pack-*.pack)" | |
184 | } >packfiles && | |
185 | ||
186 | git pack-objects --stdin-packs generated-pack <packfiles && | |
187 | packed_objects generated-pack-*.idx >packed-objects && | |
188 | test_must_be_empty packed-objects | |
189 | ) | |
190 | ' | |
191 | ||
f3028418 PS |
192 | test_expect_success 'pack-objects --stdin with packfiles from alternate object database' ' |
193 | test_when_finished "rm -fr shared member" && | |
194 | ||
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 && | |
200 | ||
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 | |
207 | ' | |
208 | ||
209 | test_expect_success 'pack-objects --stdin with packfiles from main and alternate object database' ' | |
210 | test_when_finished "rm -fr shared member" && | |
211 | ||
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 && | |
216 | ||
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 && | |
224 | ||
225 | { | |
226 | basename shared/.git/objects/pack/pack-*.pack && | |
227 | basename member/.git/objects/pack/pack-*.pack | |
228 | } >packfiles && | |
229 | ||
230 | { | |
231 | packed_objects shared/.git/objects/pack/pack-*.idx && | |
232 | packed_objects member/.git/objects/pack/pack-*.idx | |
233 | } | sort >expected-objects && | |
234 | ||
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 | |
238 | ' | |
239 | ||
b7b8f048 | 240 | test_done |