3 # Copyright (C) 2006 Martin Waitz <tali@admingilde.org>
6 test_description
='test clone --reference'
11 U
=$base_dir/UPLOAD_LOG
13 # create a commit in repo $1 with name $2
23 # check that there are $2 loose objects in repo $1
26 git
-C "$1" count-objects
>actual.raw
&&
27 cut
-d' ' -f1 <actual.raw
>actual
&&
28 test_cmp expect actual
31 test_expect_success
'preparing first repository' '
36 test_expect_success
'preparing second repository' '
39 git -C B repack -ad &&
43 test_expect_success
'cloning with reference (-l -s)' '
44 git clone -l -s --reference B A C
47 test_expect_success
'existence of info/alternates' '
48 test_line_count = 2 C/.git/objects/info/alternates
51 test_expect_success
'pulling from reference' '
52 git -C C pull ../B master
55 test_expect_success
'that reference gets used' '
59 test_expect_success
'cloning with reference (no -l -s)' '
60 GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D
63 test_expect_success
'fetched no objects' '
68 test_expect_success
'existence of info/alternates' '
69 test_line_count = 1 D/.git/objects/info/alternates
72 test_expect_success
'pulling from reference' '
73 git -C D pull ../B master
76 test_expect_success
'that reference gets used' '
80 test_expect_success
'updating origin' '
82 git -C A repack -ad &&
86 test_expect_success
'pulling changes from origin' '
90 # the 2 local objects are commit and tree from the merge
91 test_expect_success
'that alternate to origin gets used' '
95 test_expect_success
'pulling changes from origin' '
99 # the 5 local objects are expected; file3 blob, commit in A to add it
100 # and its tree, and 2 are our tree and the merge commit.
101 test_expect_success
'check objects expected to exist locally' '
105 test_expect_success
'preparing alternate repository #1' '
106 test_create_repo F &&
110 test_expect_success
'cloning alternate repo #2 and adding changes to repo #1' '
115 test_expect_success
'cloning alternate repo #1, using #2 as reference' '
116 git clone --reference G F H
119 test_expect_success
'cloning with reference being subset of source (-l -s)' '
120 git clone -l -s --reference A B E
123 test_expect_success
'cloning with multiple references drops duplicates' '
124 git clone -s --reference B --reference A --reference B A dups &&
125 test_line_count = 2 dups/.git/objects/info/alternates
128 test_expect_success
'clone with reference from a tagged repository' '
130 cd A && git tag -a -m tagged HEAD
132 git clone --reference=A A I
135 test_expect_success
'prepare branched repository' '
139 git checkout -b other master^ &&
140 echo other >otherfile &&
142 git commit -m other &&
147 test_expect_success
'fetch with incomplete alternates' '
149 echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates &&
152 git remote add J "file://$base_dir/J" &&
153 GIT_TRACE_PACKET=$U.K git fetch J
155 master_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&
157 ! grep " want $master_object" "$U.K" &&
158 tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
159 ! grep " want $tag_object" "$U.K"
162 test_expect_success
'clone using repo with gitfile as a reference' '
163 git clone --separate-git-dir=L A M &&
164 git clone --reference=M A N &&
165 echo "$base_dir/L/objects" >expected &&
166 test_cmp expected "$base_dir/N/.git/objects/info/alternates"
169 test_expect_success
'clone using repo pointed at by gitfile as reference' '
170 git clone --reference=M/.git A O &&
171 echo "$base_dir/L/objects" >expected &&
172 test_cmp expected "$base_dir/O/.git/objects/info/alternates"
175 test_expect_success
'clone and dissociate from reference' '
178 cd P && test_commit one
182 cd Q && test_commit two
184 git clone --no-local --reference=P Q R &&
185 git clone --no-local --reference=P --dissociate Q S &&
186 # removing the reference P would corrupt R but not S
188 test_must_fail git -C R fsck &&
191 test_expect_success
'clone, dissociate from partial reference and repack' '
201 git clone --bare P Q &&
204 git checkout -b second &&
208 git clone --bare --dissociate --reference=P Q R &&
209 ls R/objects/pack/*.pack >packs.txt &&
210 test_line_count = 1 packs.txt
213 test_expect_success
'clone, dissociate from alternates' '
215 test_create_repo A &&
217 git clone --reference=A A B &&
218 test_line_count = 1 B/.git/objects/info/alternates &&
219 git clone --local --dissociate B C &&
220 ! test -f C/.git/objects/info/alternates &&
224 test_expect_success
'setup repo with garbage in objects/*' '
231 >.some-hidden-file &&
233 mkdir .some-hidden-dir &&
234 >.some-hidden-dir/some-file &&
235 >.some-hidden-dir/.some-dot-file &&
237 >some-dir/some-file &&
238 >some-dir/.some-dot-file
242 test_expect_success
'clone a repo with garbage in objects/*' '
243 for option in --local --no-hardlinks --shared --dissociate
245 git clone $option S S$option || return 1 &&
246 git -C S$option fsck || return 1
248 find S-* -name "*some*" | sort >actual &&
249 cat >expected <<-EOF &&
250 S--dissociate/.git/objects/.some-hidden-dir
251 S--dissociate/.git/objects/.some-hidden-dir/.some-dot-file
252 S--dissociate/.git/objects/.some-hidden-dir/some-file
253 S--dissociate/.git/objects/.some-hidden-file
254 S--dissociate/.git/objects/some-dir
255 S--dissociate/.git/objects/some-dir/.some-dot-file
256 S--dissociate/.git/objects/some-dir/some-file
257 S--dissociate/.git/objects/some-file
258 S--local/.git/objects/.some-hidden-dir
259 S--local/.git/objects/.some-hidden-dir/.some-dot-file
260 S--local/.git/objects/.some-hidden-dir/some-file
261 S--local/.git/objects/.some-hidden-file
262 S--local/.git/objects/some-dir
263 S--local/.git/objects/some-dir/.some-dot-file
264 S--local/.git/objects/some-dir/some-file
265 S--local/.git/objects/some-file
266 S--no-hardlinks/.git/objects/.some-hidden-dir
267 S--no-hardlinks/.git/objects/.some-hidden-dir/.some-dot-file
268 S--no-hardlinks/.git/objects/.some-hidden-dir/some-file
269 S--no-hardlinks/.git/objects/.some-hidden-file
270 S--no-hardlinks/.git/objects/some-dir
271 S--no-hardlinks/.git/objects/some-dir/.some-dot-file
272 S--no-hardlinks/.git/objects/some-dir/some-file
273 S--no-hardlinks/.git/objects/some-file
275 test_cmp expected actual
278 test_expect_success SYMLINKS
'setup repo with manually symlinked or unknown files at objects/' '
282 git config gc.auto 0 &&
290 find ?? -type d >loose-dirs &&
291 last_loose=$(tail -n 1 loose-dirs) &&
292 mv $last_loose a-loose-dir &&
293 ln -s a-loose-dir $last_loose &&
294 first_loose=$(head -n 1 loose-dirs) &&
299 mv $obj ../an-object &&
300 ln -s ../an-object $obj &&
303 find . -type f | sort >../../../T.objects-files.raw &&
304 find . -type l | sort >../../../T.objects-symlinks.raw &&
305 echo unknown_content >unknown_file
308 git -C T rev-list --all --objects >T.objects
312 test_expect_success SYMLINKS
'clone repo with symlinked or unknown files at objects/' '
313 for option in --local --no-hardlinks --shared --dissociate
315 git clone $option T T$option || return 1 &&
316 git -C T$option fsck || return 1 &&
317 git -C T$option rev-list --all --objects >T$option.objects &&
318 test_cmp T.objects T$option.objects &&
320 cd T$option/.git/objects &&
321 find . -type f | sort >../../../T$option.objects-files.raw &&
322 find . -type l | sort >../../../T$option.objects-symlinks.raw
326 for raw in $(ls T*.raw)
328 sed -e "s!/../!/Y/!; s![0-9a-f]\{38,\}!Z!" -e "/commit-graph/d" \
329 -e "/multi-pack-index/d" <$raw >$raw.de-sha || return 1
332 cat >expected-files <<-EOF &&
346 for option in --local --no-hardlinks --dissociate
348 test_cmp expected-files T$option.objects-files.raw.de-sha || return 1 &&
349 test_must_be_empty T$option.objects-symlinks.raw.de-sha || return 1
352 echo ./info/alternates >expected-files &&
353 test_cmp expected-files T--shared.objects-files.raw &&
354 test_must_be_empty T--shared.objects-symlinks.raw