Skip to content

Commit 0315616

Browse files
avargitster
authored andcommitted
clone: test for our behavior on odd objects/* content
Add tests for what happens when we perform a local clone on a repo containing odd files at .git/object directory, such as symlinks to other dirs, or unknown files. I'm bending over backwards here to avoid a SHA-1 dependency. See [1] for an earlier and simpler version that hardcoded SHA-1s. This behavior has been the same for a *long* time, but hasn't been tested for. There's a good post-hoc argument to be made for copying over unknown things, e.g. I'd like a git version that doesn't know about the commit-graph to copy it under "clone --local" so a newer git version can make use of it. In follow-up commits we'll look at changing some of this behavior, but for now, let's just assert it as-is so we'll notice what we'll change later. 1. https://public-inbox.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> [matheus.bernardino: improved and split tests in more than one patch] Helped-by: Matheus Tavares <[email protected]> Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0e78f7 commit 0315616

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

t/t5604-clone-reference.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,115 @@ test_expect_success 'clone, dissociate from alternates' '
221221
( cd C && git fsck )
222222
'
223223

224+
test_expect_success 'setup repo with garbage in objects/*' '
225+
git init S &&
226+
(
227+
cd S &&
228+
test_commit A &&
229+
230+
cd .git/objects &&
231+
>.some-hidden-file &&
232+
>some-file &&
233+
mkdir .some-hidden-dir &&
234+
>.some-hidden-dir/some-file &&
235+
>.some-hidden-dir/.some-dot-file &&
236+
mkdir some-dir &&
237+
>some-dir/some-file &&
238+
>some-dir/.some-dot-file
239+
)
240+
'
241+
242+
test_expect_success 'clone a repo with garbage in objects/*' '
243+
for option in --local --no-hardlinks --shared --dissociate
244+
do
245+
git clone $option S S$option || return 1 &&
246+
git -C S$option fsck || return 1
247+
done &&
248+
find S-* -name "*some*" | sort >actual &&
249+
cat >expected <<-EOF &&
250+
S--dissociate/.git/objects/.some-hidden-file
251+
S--dissociate/.git/objects/some-dir
252+
S--dissociate/.git/objects/some-dir/.some-dot-file
253+
S--dissociate/.git/objects/some-dir/some-file
254+
S--dissociate/.git/objects/some-file
255+
S--local/.git/objects/.some-hidden-file
256+
S--local/.git/objects/some-dir
257+
S--local/.git/objects/some-dir/.some-dot-file
258+
S--local/.git/objects/some-dir/some-file
259+
S--local/.git/objects/some-file
260+
S--no-hardlinks/.git/objects/.some-hidden-file
261+
S--no-hardlinks/.git/objects/some-dir
262+
S--no-hardlinks/.git/objects/some-dir/.some-dot-file
263+
S--no-hardlinks/.git/objects/some-dir/some-file
264+
S--no-hardlinks/.git/objects/some-file
265+
EOF
266+
test_cmp expected actual
267+
'
268+
269+
test_expect_success SYMLINKS 'setup repo with manually symlinked dirs and unknown files at objects/' '
270+
git init T &&
271+
(
272+
cd T &&
273+
git config gc.auto 0 &&
274+
test_commit A &&
275+
git gc &&
276+
test_commit B &&
277+
278+
cd .git/objects &&
279+
mv pack packs &&
280+
ln -s packs pack &&
281+
find ?? -type d >loose-dirs &&
282+
last_loose=$(tail -n 1 loose-dirs) &&
283+
rm -f loose-dirs &&
284+
mv $last_loose a-loose-dir &&
285+
ln -s a-loose-dir $last_loose &&
286+
find . -type f | sort >../../../T.objects-files.raw &&
287+
echo unknown_content >unknown_file
288+
) &&
289+
git -C T fsck &&
290+
git -C T rev-list --all --objects >T.objects
291+
'
292+
293+
294+
test_expect_success SYMLINKS 'clone repo with symlinked dirs and unknown files at objects/' '
295+
for option in --local --no-hardlinks --shared --dissociate
296+
do
297+
git clone $option T T$option || return 1 &&
298+
git -C T$option fsck || return 1 &&
299+
git -C T$option rev-list --all --objects >T$option.objects &&
300+
test_cmp T.objects T$option.objects &&
301+
(
302+
cd T$option/.git/objects &&
303+
find . -type f | sort >../../../T$option.objects-files.raw
304+
)
305+
done &&
306+
307+
for raw in $(ls T*.raw)
308+
do
309+
sed -e "s!/../!/Y/!; s![0-9a-f]\{38,\}!Z!" -e "/commit-graph/d" \
310+
-e "/multi-pack-index/d" <$raw >$raw.de-sha || return 1
311+
done &&
312+
313+
cat >expected-files <<-EOF &&
314+
./Y/Z
315+
./Y/Z
316+
./a-loose-dir/Z
317+
./Y/Z
318+
./info/packs
319+
./pack/pack-Z.idx
320+
./pack/pack-Z.pack
321+
./packs/pack-Z.idx
322+
./packs/pack-Z.pack
323+
./unknown_file
324+
EOF
325+
326+
for option in --local --dissociate --no-hardlinks
327+
do
328+
test_cmp expected-files T$option.objects-files.raw.de-sha || return 1
329+
done &&
330+
331+
echo ./info/alternates >expected-files &&
332+
test_cmp expected-files T--shared.objects-files.raw
333+
'
334+
224335
test_done

0 commit comments

Comments
 (0)