3 # Copyright (C) 2006 Martin Waitz <tali@admingilde.org>
6 test_description
='test clone --reference'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 U
=$base_dir/UPLOAD_LOG
16 # create a commit in repo $1 with name $2
26 # check that there are $2 loose objects in repo $1
29 git
-C "$1" count-objects
>actual.raw
&&
30 cut
-d' ' -f1 <actual.raw
>actual
&&
31 test_cmp expect actual
34 test_expect_success
'preparing first repository' '
39 test_expect_success
'preparing second repository' '
42 git -C B repack -ad &&
46 test_expect_success
'cloning with reference (-l -s)' '
47 git clone -l -s --reference B A C
50 test_expect_success
'existence of info/alternates' '
51 test_line_count = 2 C/.git/objects/info/alternates
54 test_expect_success
'pulling from reference' '
55 git -C C pull ../B main
58 test_expect_success
'that reference gets used' '
62 test_expect_success
'cloning with reference (no -l -s)' '
63 GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D
66 test_expect_success
'fetched no objects' '
71 test_expect_success
'existence of info/alternates' '
72 test_line_count = 1 D/.git/objects/info/alternates
75 test_expect_success
'pulling from reference' '
76 git -C D pull ../B main
79 test_expect_success
'that reference gets used' '
83 test_expect_success
'updating origin' '
85 git -C A repack -ad &&
89 test_expect_success
'pulling changes from origin' '
93 # the 2 local objects are commit and tree from the merge
94 test_expect_success
'that alternate to origin gets used' '
98 test_expect_success
'pulling changes from origin' '
102 # the 5 local objects are expected; file3 blob, commit in A to add it
103 # and its tree, and 2 are our tree and the merge commit.
104 test_expect_success
'check objects expected to exist locally' '
108 test_expect_success
'preparing alternate repository #1' '
109 test_create_repo F &&
113 test_expect_success
'cloning alternate repo #2 and adding changes to repo #1' '
118 test_expect_success
'cloning alternate repo #1, using #2 as reference' '
119 git clone --reference G F H
122 test_expect_success
'cloning with reference being subset of source (-l -s)' '
123 git clone -l -s --reference A B E
126 test_expect_success
'cloning with multiple references drops duplicates' '
127 git clone -s --reference B --reference A --reference B A dups &&
128 test_line_count = 2 dups/.git/objects/info/alternates
131 test_expect_success
'clone with reference from a tagged repository' '
133 cd A && git tag -a -m tagged HEAD
135 git clone --reference=A A I
138 test_expect_success
'prepare branched repository' '
142 git checkout -b other main^ &&
143 echo other >otherfile &&
145 git commit -m other &&
150 test_expect_success
'fetch with incomplete alternates' '
152 echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates &&
155 git remote add J "file://$base_dir/J" &&
156 GIT_TRACE_PACKET=$U.K git fetch J
158 main_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/main) &&
160 ! grep " want $main_object" "$U.K" &&
161 tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
162 ! grep " want $tag_object" "$U.K"
165 test_expect_success
'clone using repo with gitfile as a reference' '
166 git clone --separate-git-dir=L A M &&
167 git clone --reference=M A N &&
168 echo "$base_dir/L/objects" >expected &&
169 test_cmp expected "$base_dir/N/.git/objects/info/alternates"
172 test_expect_success
'clone using repo pointed at by gitfile as reference' '
173 git clone --reference=M/.git A O &&
174 echo "$base_dir/L/objects" >expected &&
175 test_cmp expected "$base_dir/O/.git/objects/info/alternates"
178 test_expect_success
'clone and dissociate from reference' '
181 cd P && test_commit one
185 cd Q && test_commit two
187 git clone --no-local --reference=P Q R &&
188 git clone --no-local --reference=P --dissociate Q S &&
189 # removing the reference P would corrupt R but not S
191 test_must_fail git -C R fsck &&
194 test_expect_success
'clone, dissociate from partial reference and repack' '
204 git clone --bare P Q &&
207 git checkout -b second &&
211 git clone --bare --dissociate --reference=P Q R &&
212 ls R/objects/pack/*.pack >packs.txt &&
213 test_line_count = 1 packs.txt
216 test_expect_success
'clone, dissociate from alternates' '
218 test_create_repo A &&
220 git clone --reference=A A B &&
221 test_line_count = 1 B/.git/objects/info/alternates &&
222 git clone --local --dissociate B C &&
223 ! test -f C/.git/objects/info/alternates &&
227 test_expect_success
'setup repo with garbage in objects/*' '
234 >.some-hidden-file &&
236 mkdir .some-hidden-dir &&
237 >.some-hidden-dir/some-file &&
238 >.some-hidden-dir/.some-dot-file &&
240 >some-dir/some-file &&
241 >some-dir/.some-dot-file
245 test_expect_success
'clone a repo with garbage in objects/*' '
246 for option in --local --no-hardlinks --shared --dissociate
248 git clone $option S S$option || return 1 &&
249 git -C S$option fsck || return 1
251 find S-* -name "*some*" | sort >actual &&
252 cat >expected <<-EOF &&
253 S--dissociate/.git/objects/.some-hidden-dir
254 S--dissociate/.git/objects/.some-hidden-dir/.some-dot-file
255 S--dissociate/.git/objects/.some-hidden-dir/some-file
256 S--dissociate/.git/objects/.some-hidden-file
257 S--dissociate/.git/objects/some-dir
258 S--dissociate/.git/objects/some-dir/.some-dot-file
259 S--dissociate/.git/objects/some-dir/some-file
260 S--dissociate/.git/objects/some-file
261 S--local/.git/objects/.some-hidden-dir
262 S--local/.git/objects/.some-hidden-dir/.some-dot-file
263 S--local/.git/objects/.some-hidden-dir/some-file
264 S--local/.git/objects/.some-hidden-file
265 S--local/.git/objects/some-dir
266 S--local/.git/objects/some-dir/.some-dot-file
267 S--local/.git/objects/some-dir/some-file
268 S--local/.git/objects/some-file
269 S--no-hardlinks/.git/objects/.some-hidden-dir
270 S--no-hardlinks/.git/objects/.some-hidden-dir/.some-dot-file
271 S--no-hardlinks/.git/objects/.some-hidden-dir/some-file
272 S--no-hardlinks/.git/objects/.some-hidden-file
273 S--no-hardlinks/.git/objects/some-dir
274 S--no-hardlinks/.git/objects/some-dir/.some-dot-file
275 S--no-hardlinks/.git/objects/some-dir/some-file
276 S--no-hardlinks/.git/objects/some-file
278 test_cmp expected actual
281 test_expect_success SYMLINKS
'setup repo with manually symlinked or unknown files at objects/' '
285 git config gc.auto 0 &&
293 find ?? -type d >loose-dirs &&
294 last_loose=$(tail -n 1 loose-dirs) &&
295 mv $last_loose a-loose-dir &&
296 ln -s a-loose-dir $last_loose &&
297 first_loose=$(head -n 1 loose-dirs) &&
302 mv $obj ../an-object &&
303 ln -s ../an-object $obj &&
306 find . -type f | sort >../../../T.objects-files.raw &&
307 find . -type l | sort >../../../T.objects-symlinks.raw &&
308 echo unknown_content >unknown_file
311 git -C T rev-list --all --objects >T.objects
315 test_expect_success SYMLINKS
'clone repo with symlinked or unknown files at objects/' '
316 for option in --local --no-hardlinks --shared --dissociate
318 git clone $option T T$option || return 1 &&
319 git -C T$option fsck || return 1 &&
320 git -C T$option rev-list --all --objects >T$option.objects &&
321 test_cmp T.objects T$option.objects &&
323 cd T$option/.git/objects &&
324 find . -type f | sort >../../../T$option.objects-files.raw &&
325 find . -type l | sort >../../../T$option.objects-symlinks.raw
329 for raw in $(ls T*.raw)
331 sed -e "s!/../!/Y/!; s![0-9a-f]\{38,\}!Z!" -e "/commit-graph/d" \
332 -e "/multi-pack-index/d" -e "/rev/d" <$raw >$raw.de-sha-1 &&
333 sort $raw.de-sha-1 >$raw.de-sha || return 1
336 cat >expected-files <<-EOF &&
350 for option in --local --no-hardlinks --dissociate
352 test_cmp expected-files T$option.objects-files.raw.de-sha || return 1 &&
353 test_must_be_empty T$option.objects-symlinks.raw.de-sha || return 1
356 echo ./info/alternates >expected-files &&
357 test_cmp expected-files T--shared.objects-files.raw &&
358 test_must_be_empty T--shared.objects-symlinks.raw