]>
Commit | Line | Data |
---|---|---|
a2b26acd JH |
1 | #!/bin/sh |
2 | ||
3 | test_description=clone | |
4 | ||
95cf2c01 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
a2b26acd JH |
8 | . ./test-lib.sh |
9 | ||
3064d5a3 JS |
10 | X= |
11 | test_have_prereq !MINGW || X=.exe | |
12 | ||
a2b26acd JH |
13 | test_expect_success setup ' |
14 | ||
15 | rm -fr .git && | |
16 | test_create_repo src && | |
17 | ( | |
bafe7631 NTND |
18 | cd src && |
19 | >file && | |
20 | git add file && | |
7f08c685 NTND |
21 | git commit -m initial && |
22 | echo 1 >file && | |
23 | git add file && | |
24 | git commit -m updated | |
a2b26acd JH |
25 | ) |
26 | ||
27 | ' | |
28 | ||
1db4a75c | 29 | test_expect_success 'clone with excess parameters (1)' ' |
a2b26acd | 30 | |
1db4a75c SP |
31 | rm -fr dst && |
32 | test_must_fail git clone -n src dst junk | |
33 | ||
34 | ' | |
35 | ||
36 | test_expect_success 'clone with excess parameters (2)' ' | |
37 | ||
38 | rm -fr dst && | |
a2b26acd JH |
39 | test_must_fail git clone -n "file://$(pwd)/src" dst junk |
40 | ||
41 | ' | |
42 | ||
a926c4b9 | 43 | test_expect_success 'output from clone' ' |
2c3766f0 | 44 | rm -fr dst && |
68b939b2 | 45 | git clone -n "file://$(pwd)/src" dst >output 2>&1 && |
28ba96ab | 46 | test $(grep Clon output | wc -l) = 1 |
2c3766f0 AM |
47 | ' |
48 | ||
1db4a75c SP |
49 | test_expect_success 'clone does not keep pack' ' |
50 | ||
51 | rm -fr dst && | |
52 | git clone -n "file://$(pwd)/src" dst && | |
53 | ! test -f dst/file && | |
54 | ! (echo dst/.git/objects/pack/pack-* | grep "\.keep") | |
55 | ||
56 | ' | |
57 | ||
a73bc127 JS |
58 | test_expect_success 'clone checks out files' ' |
59 | ||
1db4a75c | 60 | rm -fr dst && |
a73bc127 JS |
61 | git clone src dst && |
62 | test -f dst/file | |
63 | ||
64 | ' | |
65 | ||
2beebd22 JK |
66 | test_expect_success 'clone respects GIT_WORK_TREE' ' |
67 | ||
68 | GIT_WORK_TREE=worktree git clone src bare && | |
69 | test -f bare/config && | |
70 | test -f worktree/file | |
71 | ||
72 | ' | |
73 | ||
86d26f24 NTND |
74 | test_expect_success 'clone from hooks' ' |
75 | ||
76 | test_create_repo r0 && | |
77 | cd r0 && | |
78 | test_commit initial && | |
79 | cd .. && | |
80 | git init r1 && | |
81 | cd r1 && | |
60a8a6bf | 82 | test_hook pre-commit <<-\EOF && |
86d26f24 NTND |
83 | git clone ../r0 ../r2 |
84 | exit 1 | |
85 | EOF | |
86d26f24 NTND |
86 | : >file && |
87 | git add file && | |
88 | test_must_fail git commit -m invoke-hook && | |
89 | cd .. && | |
90 | test_cmp r0/.git/HEAD r2/.git/HEAD && | |
91 | test_cmp r0/initial.t r2/initial.t | |
92 | ||
93 | ' | |
94 | ||
2beebd22 JK |
95 | test_expect_success 'clone creates intermediate directories' ' |
96 | ||
97 | git clone src long/path/to/dst && | |
98 | test -f long/path/to/dst/file | |
99 | ||
100 | ' | |
101 | ||
102 | test_expect_success 'clone creates intermediate directories for bare repo' ' | |
103 | ||
104 | git clone --bare src long/path/to/bare/dst && | |
105 | test -f long/path/to/bare/dst/config | |
106 | ||
107 | ' | |
108 | ||
bc699afc JS |
109 | test_expect_success 'clone --mirror' ' |
110 | ||
111 | git clone --mirror src mirror && | |
112 | test -f mirror/HEAD && | |
113 | test ! -f mirror/file && | |
114 | FETCH="$(cd mirror && git config remote.origin.fetch)" && | |
115 | test "+refs/*:refs/*" = "$FETCH" && | |
116 | MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" && | |
117 | test "$MIRROR" = true | |
118 | ||
119 | ' | |
120 | ||
7f08c685 NTND |
121 | test_expect_success 'clone --mirror with detached HEAD' ' |
122 | ||
123 | ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) && | |
124 | git clone --mirror src mirror.detached && | |
125 | ( cd src && git checkout - ) && | |
126 | GIT_DIR=mirror.detached git rev-parse HEAD >actual && | |
127 | test_cmp expected actual | |
128 | ||
129 | ' | |
130 | ||
131 | test_expect_success 'clone --bare with detached HEAD' ' | |
132 | ||
133 | ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) && | |
134 | git clone --bare src bare.detached && | |
135 | ( cd src && git checkout - ) && | |
136 | GIT_DIR=bare.detached git rev-parse HEAD >actual && | |
137 | test_cmp expected actual | |
138 | ||
139 | ' | |
140 | ||
6612f877 JS |
141 | test_expect_success 'clone --bare names the local repository <name>.git' ' |
142 | ||
143 | git clone --bare src && | |
144 | test -d src.git | |
145 | ||
146 | ' | |
147 | ||
468386a9 JS |
148 | test_expect_success 'clone --mirror does not repeat tags' ' |
149 | ||
150 | (cd src && | |
151 | git tag some-tag HEAD) && | |
152 | git clone --mirror src mirror2 && | |
153 | (cd mirror2 && | |
154 | git show-ref 2> clone.err > clone.out) && | |
c7cf9566 | 155 | ! grep Duplicate mirror2/clone.err && |
468386a9 JS |
156 | grep some-tag mirror2/clone.out |
157 | ||
158 | ' | |
159 | ||
44a68fd5 CB |
160 | test_expect_success 'clone to destination with trailing /' ' |
161 | ||
162 | git clone src target-1/ && | |
163 | T=$( cd target-1 && git rev-parse HEAD ) && | |
164 | S=$( cd src && git rev-parse HEAD ) && | |
165 | test "$T" = "$S" | |
166 | ||
167 | ' | |
168 | ||
169 | test_expect_success 'clone to destination with extra trailing /' ' | |
170 | ||
171 | git clone src target-2/// && | |
172 | T=$( cd target-2 && git rev-parse HEAD ) && | |
173 | S=$( cd src && git rev-parse HEAD ) && | |
174 | test "$T" = "$S" | |
175 | ||
176 | ' | |
177 | ||
55892d23 AP |
178 | test_expect_success 'clone to an existing empty directory' ' |
179 | mkdir target-3 && | |
180 | git clone src target-3 && | |
181 | T=$( cd target-3 && git rev-parse HEAD ) && | |
182 | S=$( cd src && git rev-parse HEAD ) && | |
183 | test "$T" = "$S" | |
184 | ' | |
185 | ||
186 | test_expect_success 'clone to an existing non-empty directory' ' | |
187 | mkdir target-4 && | |
188 | >target-4/Fakefile && | |
189 | test_must_fail git clone src target-4 | |
190 | ' | |
191 | ||
192 | test_expect_success 'clone to an existing path' ' | |
193 | >target-5 && | |
194 | test_must_fail git clone src target-5 | |
195 | ' | |
196 | ||
5cd12b85 JH |
197 | test_expect_success 'clone a void' ' |
198 | mkdir src-0 && | |
199 | ( | |
200 | cd src-0 && git init | |
201 | ) && | |
12d49966 JK |
202 | git clone "file://$(pwd)/src-0" target-6 2>err-6 && |
203 | ! grep "fatal:" err-6 && | |
5cd12b85 JH |
204 | ( |
205 | cd src-0 && test_commit A | |
206 | ) && | |
12d49966 JK |
207 | git clone "file://$(pwd)/src-0" target-7 2>err-7 && |
208 | ! grep "fatal:" err-7 && | |
5cd12b85 JH |
209 | # There is no reason to insist they are bit-for-bit |
210 | # identical, but this test should suffice for now. | |
211 | test_cmp target-6/.git/config target-7/.git/config | |
212 | ' | |
213 | ||
a9f2c136 JH |
214 | test_expect_success 'clone respects global branch.autosetuprebase' ' |
215 | ( | |
a9f2c136 | 216 | test_config="$HOME/.gitconfig" && |
a9f2c136 JH |
217 | git config -f "$test_config" branch.autosetuprebase remote && |
218 | rm -fr dst && | |
219 | git clone src dst && | |
220 | cd dst && | |
95cf2c01 | 221 | actual="z$(git config branch.main.rebase)" && |
a9f2c136 JH |
222 | test ztrue = $actual |
223 | ) | |
224 | ' | |
225 | ||
9d2e9420 JK |
226 | test_expect_success 'respect url-encoding of file://' ' |
227 | git init x+y && | |
730220de TR |
228 | git clone "file://$PWD/x+y" xy-url-1 && |
229 | git clone "file://$PWD/x%2By" xy-url-2 | |
230 | ' | |
231 | ||
232 | test_expect_success 'do not query-string-decode + in URLs' ' | |
233 | rm -rf x+y && | |
234 | git init "x y" && | |
235 | test_must_fail git clone "file://$PWD/x+y" xy-no-plus | |
9d2e9420 JK |
236 | ' |
237 | ||
238 | test_expect_success 'do not respect url-encoding of non-url path' ' | |
239 | git init x+y && | |
240 | test_must_fail git clone x%2By xy-regular && | |
241 | git clone x+y xy-regular | |
242 | ' | |
243 | ||
b57fb80a NTND |
244 | test_expect_success 'clone separate gitdir' ' |
245 | rm -rf dst && | |
246 | git clone --separate-git-dir realgitdir src dst && | |
b57fb80a NTND |
247 | test -d realgitdir/refs |
248 | ' | |
249 | ||
33d56fa0 | 250 | test_expect_success 'clone separate gitdir: output' ' |
c723e50d | 251 | echo "gitdir: $(pwd)/realgitdir" >expected && |
2c050e01 ÆAB |
252 | test_cmp expected dst/.git |
253 | ' | |
254 | ||
9b0ebc72 NTND |
255 | test_expect_success 'clone from .git file' ' |
256 | git clone dst/.git dst2 | |
257 | ' | |
258 | ||
0c80fdb3 PH |
259 | test_expect_success 'fetch from .git gitfile' ' |
260 | ( | |
261 | cd dst2 && | |
262 | git fetch ../dst/.git | |
263 | ) | |
264 | ' | |
265 | ||
266 | test_expect_success 'fetch from gitfile parent' ' | |
267 | ( | |
268 | cd dst2 && | |
269 | git fetch ../dst | |
270 | ) | |
271 | ' | |
272 | ||
b57fb80a NTND |
273 | test_expect_success 'clone separate gitdir where target already exists' ' |
274 | rm -rf dst && | |
dfaa209a BW |
275 | echo foo=bar >>realgitdir/config && |
276 | test_must_fail git clone --separate-git-dir realgitdir src dst && | |
277 | grep foo=bar realgitdir/config | |
b57fb80a NTND |
278 | ' |
279 | ||
e6baf4a1 | 280 | test_expect_success 'clone --reference from original' ' |
dbc92b07 JH |
281 | git clone --shared --bare src src-1 && |
282 | git clone --bare src src-2 && | |
283 | git clone --reference=src-2 --bare src-1 target-8 && | |
284 | grep /src-2/ target-8/objects/info/alternates | |
285 | ' | |
286 | ||
287 | test_expect_success 'clone with more than one --reference' ' | |
288 | git clone --bare src src-3 && | |
289 | git clone --bare src src-4 && | |
290 | git clone --reference=src-3 --reference=src-4 src target-9 && | |
291 | grep /src-3/ target-9/.git/objects/info/alternates && | |
292 | grep /src-4/ target-9/.git/objects/info/alternates | |
293 | ' | |
294 | ||
e6baf4a1 JH |
295 | test_expect_success 'clone from original with relative alternate' ' |
296 | mkdir nest && | |
297 | git clone --bare src nest/src-5 && | |
298 | echo ../../../src/.git/objects >nest/src-5/objects/info/alternates && | |
299 | git clone --bare nest/src-5 target-10 && | |
300 | grep /src/\\.git/objects target-10/objects/info/alternates | |
301 | ' | |
302 | ||
5a7d5b68 NTND |
303 | test_expect_success 'clone checking out a tag' ' |
304 | git clone --branch=some-tag src dst.tag && | |
305 | GIT_DIR=src/.git git rev-parse some-tag >expected && | |
dd8468ef HWN |
306 | GIT_DIR=dst.tag/.git git rev-parse HEAD >actual && |
307 | test_cmp expected actual && | |
5a7d5b68 NTND |
308 | GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual && |
309 | echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected && | |
310 | test_cmp fetch.expected fetch.actual | |
311 | ' | |
312 | ||
8339805b JN |
313 | test_expect_success 'set up ssh wrapper' ' |
314 | cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" \ | |
315 | "$TRASH_DIRECTORY/ssh$X" && | |
316 | GIT_SSH="$TRASH_DIRECTORY/ssh$X" && | |
317 | export GIT_SSH && | |
318 | export TRASH_DIRECTORY && | |
319 | >"$TRASH_DIRECTORY"/ssh-output | |
320 | ' | |
8d3d28f5 | 321 | |
baaf2337 | 322 | copy_ssh_wrapper_as () { |
cff48ccf | 323 | rm -f "${1%$X}$X" && |
94b8ae5a | 324 | cp "$TRASH_DIRECTORY/ssh$X" "${1%$X}$X" && |
8339805b | 325 | test_when_finished "rm $(git rev-parse --sq-quote "${1%$X}$X")" && |
3064d5a3 | 326 | GIT_SSH="${1%$X}$X" && |
8339805b | 327 | test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" |
baaf2337 | 328 | } |
329 | ||
8d3d28f5 | 330 | expect_ssh () { |
710eb3e2 TB |
331 | test_when_finished ' |
332 | (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output) | |
333 | ' && | |
8d3d28f5 | 334 | { |
9f697652 TB |
335 | case "$#" in |
336 | 1) | |
8d3d28f5 | 337 | ;; |
9f697652 | 338 | 2) |
8d3d28f5 | 339 | echo "ssh: $1 git-upload-pack '$2'" |
9f697652 TB |
340 | ;; |
341 | 3) | |
342 | echo "ssh: $1 $2 git-upload-pack '$3'" | |
343 | ;; | |
344 | *) | |
345 | echo "ssh: $1 $2 git-upload-pack '$3' $4" | |
8d3d28f5 NTND |
346 | esac |
347 | } >"$TRASH_DIRECTORY/ssh-expect" && | |
348 | (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output) | |
349 | } | |
350 | ||
2171f3d2 | 351 | test_expect_success 'clone myhost:src uses ssh' ' |
3a5728dc | 352 | GIT_TEST_PROTOCOL_VERSION=0 git clone myhost:src ssh-clone && |
8d3d28f5 NTND |
353 | expect_ssh myhost src |
354 | ' | |
355 | ||
f57a8715 | 356 | test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' ' |
60003340 | 357 | cp -R src "foo:bar" && |
710eb3e2 | 358 | git clone "foo:bar" foobar && |
8d3d28f5 NTND |
359 | expect_ssh none |
360 | ' | |
361 | ||
362 | test_expect_success 'bracketed hostnames are still ssh' ' | |
3a5728dc | 363 | GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone && |
d1018c24 | 364 | expect_ssh "-p 123" myhost src |
60003340 NTND |
365 | ' |
366 | ||
94b8ae5a | 367 | test_expect_success 'OpenSSH variant passes -4' ' |
3a5728dc | 368 | GIT_TEST_PROTOCOL_VERSION=0 git clone -4 "[myhost:123]:src" ssh-ipv4-clone && |
94b8ae5a BW |
369 | expect_ssh "-4 -p 123" myhost src |
370 | ' | |
371 | ||
a3f5b66f JN |
372 | test_expect_success 'variant can be overridden' ' |
373 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/putty" && | |
374 | git -c ssh.variant=putty clone -4 "[myhost:123]:src" ssh-putty-clone && | |
375 | expect_ssh "-4 -P 123" myhost src | |
94b8ae5a BW |
376 | ' |
377 | ||
0da0e49b JN |
378 | test_expect_success 'variant=auto picks based on basename' ' |
379 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && | |
380 | git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone && | |
381 | expect_ssh "-4 -P 123" myhost src | |
382 | ' | |
383 | ||
a3f5b66f | 384 | test_expect_success 'simple does not support -4/-6' ' |
94b8ae5a | 385 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" && |
3fa5e0d0 JN |
386 | test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple |
387 | ' | |
388 | ||
389 | test_expect_success 'simple does not support port' ' | |
390 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" && | |
391 | test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple | |
94b8ae5a BW |
392 | ' |
393 | ||
394 | test_expect_success 'uplink is treated as simple' ' | |
baaf2337 | 395 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" && |
3fa5e0d0 JN |
396 | test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink && |
397 | git clone "myhost:src" ssh-clone-uplink && | |
94b8ae5a | 398 | expect_ssh myhost src |
baaf2337 | 399 | ' |
400 | ||
0da0e49b JN |
401 | test_expect_success 'OpenSSH-like uplink is treated as ssh' ' |
402 | write_script "$TRASH_DIRECTORY/uplink" <<-EOF && | |
403 | if test "\$1" = "-G" | |
404 | then | |
405 | exit 0 | |
406 | fi && | |
407 | exec "\$TRASH_DIRECTORY/ssh$X" "\$@" | |
408 | EOF | |
409 | test_when_finished "rm -f \"\$TRASH_DIRECTORY/uplink\"" && | |
410 | GIT_SSH="$TRASH_DIRECTORY/uplink" && | |
411 | test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" && | |
3a5728dc | 412 | GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink && |
0da0e49b JN |
413 | expect_ssh "-p 123" myhost src |
414 | ' | |
415 | ||
baaf2337 | 416 | test_expect_success 'plink is treated specially (as putty)' ' |
417 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && | |
418 | git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 && | |
419 | expect_ssh "-P 123" myhost src | |
60003340 NTND |
420 | ' |
421 | ||
baaf2337 | 422 | test_expect_success 'plink.exe is treated specially (as putty)' ' |
423 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" && | |
424 | git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 && | |
425 | expect_ssh "-P 123" myhost src | |
426 | ' | |
427 | ||
428 | test_expect_success 'tortoiseplink is like putty, with extra arguments' ' | |
429 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" && | |
430 | git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 && | |
431 | expect_ssh "-batch -P 123" myhost src | |
432 | ' | |
433 | ||
e9d9a8a4 SF |
434 | test_expect_success 'double quoted plink.exe in GIT_SSH_COMMAND' ' |
435 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" && | |
436 | GIT_SSH_COMMAND="\"$TRASH_DIRECTORY/plink.exe\" -v" \ | |
437 | git clone "[myhost:123]:src" ssh-bracket-clone-plink-3 && | |
438 | expect_ssh "-v -P 123" myhost src | |
439 | ' | |
440 | ||
e9d9a8a4 SF |
441 | test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' ' |
442 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" && | |
443 | GIT_SSH_COMMAND="$SQ$TRASH_DIRECTORY/plink.exe$SQ -v" \ | |
444 | git clone "[myhost:123]:src" ssh-bracket-clone-plink-4 && | |
445 | expect_ssh "-v -P 123" myhost src | |
446 | ' | |
447 | ||
dd33e077 SF |
448 | test_expect_success 'GIT_SSH_VARIANT overrides plink detection' ' |
449 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && | |
3a5728dc JT |
450 | GIT_TEST_PROTOCOL_VERSION=0 GIT_SSH_VARIANT=ssh \ |
451 | git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 && | |
dd33e077 SF |
452 | expect_ssh "-p 123" myhost src |
453 | ' | |
454 | ||
455 | test_expect_success 'ssh.variant overrides plink detection' ' | |
456 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && | |
3a5728dc | 457 | GIT_TEST_PROTOCOL_VERSION=0 git -c ssh.variant=ssh \ |
dd33e077 SF |
458 | clone "[myhost:123]:src" ssh-bracket-clone-variant-2 && |
459 | expect_ssh "-p 123" myhost src | |
460 | ' | |
461 | ||
462 | test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' ' | |
8339805b | 463 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && |
dd33e077 SF |
464 | GIT_SSH_VARIANT=plink \ |
465 | git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 && | |
466 | expect_ssh "-P 123" myhost src | |
467 | ' | |
468 | ||
469 | test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' ' | |
8339805b | 470 | copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && |
dd33e077 SF |
471 | GIT_SSH_VARIANT=tortoiseplink \ |
472 | git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 && | |
473 | expect_ssh "-batch -P 123" myhost src | |
474 | ' | |
475 | ||
22e5ae5c JK |
476 | test_expect_success 'clean failure on broken quoting' ' |
477 | test_must_fail \ | |
478 | env GIT_SSH_COMMAND="${SQ}plink.exe -v" \ | |
479 | git clone "[myhost:123]:src" sq-failure | |
480 | ' | |
481 | ||
2171f3d2 TB |
482 | counter=0 |
483 | # $1 url | |
484 | # $2 none|host | |
485 | # $3 path | |
486 | test_clone_url () { | |
487 | counter=$(($counter + 1)) | |
3a5728dc | 488 | test_might_fail env GIT_TEST_PROTOCOL_VERSION=0 git clone "$1" tmp$counter && |
9f697652 TB |
489 | shift && |
490 | expect_ssh "$@" | |
2171f3d2 TB |
491 | } |
492 | ||
1cadad6f | 493 | test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' ' |
2171f3d2 TB |
494 | test_clone_url c:temp c temp |
495 | ' | |
496 | ||
497 | test_expect_success MINGW 'clone c:temp is dos drive' ' | |
498 | test_clone_url c:temp none | |
499 | ' | |
500 | ||
501 | #ip v4 | |
6a599748 | 502 | for repo in rep rep/home/project 123 |
2171f3d2 TB |
503 | do |
504 | test_expect_success "clone host:$repo" ' | |
505 | test_clone_url host:$repo host $repo | |
506 | ' | |
507 | done | |
508 | ||
509 | #ipv6 | |
2171f3d2 TB |
510 | for repo in rep rep/home/project 123 |
511 | do | |
512 | test_expect_success "clone [::1]:$repo" ' | |
9f697652 | 513 | test_clone_url [::1]:$repo ::1 "$repo" |
2171f3d2 TB |
514 | ' |
515 | done | |
c59ab2e5 TB |
516 | #home directory |
517 | test_expect_success "clone host:/~repo" ' | |
518 | test_clone_url host:/~repo host "~repo" | |
519 | ' | |
520 | ||
521 | test_expect_success "clone [::1]:/~repo" ' | |
522 | test_clone_url [::1]:/~repo ::1 "~repo" | |
523 | ' | |
2171f3d2 TB |
524 | |
525 | # Corner cases | |
83b05875 | 526 | for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz |
2171f3d2 TB |
527 | do |
528 | test_expect_success "clone $url is not ssh" ' | |
529 | test_clone_url $url none | |
530 | ' | |
531 | done | |
532 | ||
533 | #with ssh:// scheme | |
6b6c5f7a TB |
534 | #ignore trailing colon |
535 | for tcol in "" : | |
536 | do | |
537 | test_expect_success "clone ssh://host.xz$tcol/home/user/repo" ' | |
538 | test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo | |
539 | ' | |
540 | # from home directory | |
541 | test_expect_success "clone ssh://host.xz$tcol/~repo" ' | |
542 | test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo" | |
2171f3d2 | 543 | ' |
6b6c5f7a | 544 | done |
2171f3d2 TB |
545 | |
546 | # with port number | |
547 | test_expect_success 'clone ssh://host.xz:22/home/user/repo' ' | |
548 | test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo" | |
549 | ' | |
550 | ||
551 | # from home directory with port number | |
552 | test_expect_success 'clone ssh://host.xz:22/~repo' ' | |
553 | test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo" | |
554 | ' | |
555 | ||
556 | #IPv6 | |
6b6c5f7a | 557 | for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]: |
9f697652 | 558 | do |
a75a3081 | 559 | ehost=$(echo $tuah | sed -e "s/1]:/1]/" | tr -d "[]") |
9f697652 TB |
560 | test_expect_success "clone ssh://$tuah/home/user/repo" " |
561 | test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo | |
562 | " | |
563 | done | |
2171f3d2 TB |
564 | |
565 | #IPv6 from home directory | |
9f697652 TB |
566 | for tuah in ::1 [::1] user@::1 user@[::1] [user@::1] |
567 | do | |
568 | euah=$(echo $tuah | tr -d "[]") | |
569 | test_expect_success "clone ssh://$tuah/~repo" " | |
570 | test_clone_url ssh://$tuah/~repo $euah '~repo' | |
571 | " | |
572 | done | |
2171f3d2 TB |
573 | |
574 | #IPv6 with port number | |
9f697652 TB |
575 | for tuah in [::1] user@[::1] [user@::1] |
576 | do | |
577 | euah=$(echo $tuah | tr -d "[]") | |
578 | test_expect_success "clone ssh://$tuah:22/home/user/repo" " | |
579 | test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo | |
580 | " | |
581 | done | |
2171f3d2 TB |
582 | |
583 | #IPv6 from home directory with port number | |
9f697652 TB |
584 | for tuah in [::1] user@[::1] [user@::1] |
585 | do | |
586 | euah=$(echo $tuah | tr -d "[]") | |
587 | test_expect_success "clone ssh://$tuah:22/~repo" " | |
588 | test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo' | |
589 | " | |
590 | done | |
2171f3d2 | 591 | |
8b277222 JH |
592 | test_expect_success 'clone from a repository with two identical branches' ' |
593 | ||
594 | ( | |
595 | cd src && | |
95cf2c01 | 596 | git checkout -b another main |
8b277222 JH |
597 | ) && |
598 | git clone src target-11 && | |
599 | test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another | |
600 | ||
601 | ' | |
602 | ||
0d7d285f NTND |
603 | test_expect_success 'shallow clone locally' ' |
604 | git clone --depth=1 --no-local src ssrrcc && | |
605 | git clone ssrrcc ddsstt && | |
606 | test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow && | |
607 | ( cd ddsstt && git fsck ) | |
608 | ' | |
609 | ||
32359838 JK |
610 | test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' ' |
611 | rm -rf dst.git && | |
612 | GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git && | |
613 | git init --bare replay.git && | |
614 | git -C replay.git index-pack -v --stdin <tmp.pack | |
615 | ' | |
616 | ||
b6947af2 ES |
617 | test_expect_success 'clone on case-insensitive fs' ' |
618 | git init icasefs && | |
619 | ( | |
51b85471 | 620 | cd icasefs && |
b6947af2 ES |
621 | o=$(git hash-object -w --stdin </dev/null | hex2oct) && |
622 | t=$(printf "100644 X\0${o}100644 x\0${o}" | | |
623 | git hash-object -w -t tree --stdin) && | |
624 | c=$(git commit-tree -m bogus $t) && | |
625 | git update-ref refs/heads/bogus $c && | |
b878579a | 626 | git clone -b bogus . bogus 2>warning |
b6947af2 ES |
627 | ) |
628 | ' | |
629 | ||
a7f609ec | 630 | test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' ' |
b878579a NTND |
631 | grep X icasefs/warning && |
632 | grep x icasefs/warning && | |
633 | test_i18ngrep "the following paths have collided" icasefs/warning | |
634 | ' | |
635 | ||
47ac9703 | 636 | test_expect_success 'clone with GIT_DEFAULT_HASH' ' |
637 | ( | |
638 | sane_unset GIT_DEFAULT_HASH && | |
639 | git init --object-format=sha1 test-sha1 && | |
640 | git init --object-format=sha256 test-sha256 | |
641 | ) && | |
642 | test_commit -C test-sha1 foo && | |
643 | test_commit -C test-sha256 foo && | |
644 | GIT_DEFAULT_HASH=sha1 git clone test-sha256 test-clone-sha256 && | |
645 | GIT_DEFAULT_HASH=sha256 git clone test-sha1 test-clone-sha1 && | |
646 | git -C test-clone-sha1 status && | |
647 | git -C test-clone-sha256 status | |
648 | ' | |
649 | ||
1c4a9f91 | 650 | partial_clone_server () { |
548719fb | 651 | SERVER="$1" && |
548719fb JT |
652 | |
653 | rm -rf "$SERVER" client && | |
654 | test_create_repo "$SERVER" && | |
655 | test_commit -C "$SERVER" one && | |
44b6c05b | 656 | HASH1=$(git -C "$SERVER" hash-object one.t) && |
548719fb JT |
657 | git -C "$SERVER" revert HEAD && |
658 | test_commit -C "$SERVER" two && | |
44b6c05b | 659 | HASH2=$(git -C "$SERVER" hash-object two.t) && |
548719fb | 660 | test_config -C "$SERVER" uploadpack.allowfilter 1 && |
1c4a9f91 XL |
661 | test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 |
662 | } | |
548719fb | 663 | |
1c4a9f91 XL |
664 | partial_clone () { |
665 | SERVER="$1" && | |
666 | URL="$2" && | |
667 | ||
668 | partial_clone_server "${SERVER}" && | |
548719fb JT |
669 | git clone --filter=blob:limit=0 "$URL" client && |
670 | ||
671 | git -C client fsck && | |
672 | ||
673 | # Ensure that unneeded blobs are not inadvertently fetched. | |
b14ed5ad | 674 | test_config -C client remote.origin.promisor "false" && |
fa3d1b63 | 675 | git -C client config --unset remote.origin.partialclonefilter && |
548719fb JT |
676 | test_must_fail git -C client cat-file -e "$HASH1" && |
677 | ||
678 | # But this blob was fetched, because clone performs an initial checkout | |
679 | git -C client cat-file -e "$HASH2" | |
680 | } | |
681 | ||
682 | test_expect_success 'partial clone' ' | |
683 | partial_clone server "file://$(pwd)/server" | |
684 | ' | |
685 | ||
1c4a9f91 XL |
686 | test_expect_success 'partial clone with -o' ' |
687 | partial_clone_server server && | |
23547c40 JT |
688 | git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client && |
689 | test_cmp_config -C client "blob:limit=0" --get-all remote.blah.partialclonefilter | |
1c4a9f91 XL |
690 | ' |
691 | ||
548719fb JT |
692 | test_expect_success 'partial clone: warn if server does not support object filtering' ' |
693 | rm -rf server client && | |
694 | test_create_repo server && | |
695 | test_commit -C server one && | |
696 | ||
697 | git clone --filter=blob:limit=0 "file://$(pwd)/server" client 2> err && | |
698 | ||
699 | test_i18ngrep "filtering not recognized by server" err | |
700 | ' | |
701 | ||
c0c578b3 JT |
702 | test_expect_success 'batch missing blob request during checkout' ' |
703 | rm -rf server client && | |
704 | ||
705 | test_create_repo server && | |
706 | echo a >server/a && | |
707 | echo b >server/b && | |
708 | git -C server add a b && | |
709 | ||
710 | git -C server commit -m x && | |
711 | echo aa >server/a && | |
712 | echo bb >server/b && | |
713 | git -C server add a b && | |
714 | git -C server commit -m x && | |
715 | ||
716 | test_config -C server uploadpack.allowfilter 1 && | |
717 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
718 | ||
719 | git clone --filter=blob:limit=0 "file://$(pwd)/server" client && | |
720 | ||
721 | # Ensure that there is only one negotiation by checking that there is | |
722 | # only "done" line sent. ("done" marks the end of negotiation.) | |
723 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client checkout HEAD^ && | |
7ca3c0ac | 724 | grep "fetch> done" trace >done_lines && |
c0c578b3 JT |
725 | test_line_count = 1 done_lines |
726 | ' | |
727 | ||
728 | test_expect_success 'batch missing blob request does not inadvertently try to fetch gitlinks' ' | |
729 | rm -rf server client && | |
730 | ||
731 | test_create_repo repo_for_submodule && | |
732 | test_commit -C repo_for_submodule x && | |
733 | ||
734 | test_create_repo server && | |
735 | echo a >server/a && | |
736 | echo b >server/b && | |
737 | git -C server add a b && | |
738 | git -C server commit -m x && | |
739 | ||
740 | echo aa >server/a && | |
741 | echo bb >server/b && | |
742 | # Also add a gitlink pointing to an arbitrary repository | |
743 | git -C server submodule add "$(pwd)/repo_for_submodule" c && | |
744 | git -C server add a b c && | |
745 | git -C server commit -m x && | |
746 | ||
747 | test_config -C server uploadpack.allowfilter 1 && | |
748 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
749 | ||
750 | # Make sure that it succeeds | |
751 | git clone --filter=blob:limit=0 "file://$(pwd)/server" client | |
752 | ' | |
753 | ||
548719fb JT |
754 | . "$TEST_DIRECTORY"/lib-httpd.sh |
755 | start_httpd | |
756 | ||
757 | test_expect_success 'partial clone using HTTP' ' | |
758 | partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server" | |
759 | ' | |
760 | ||
4fe788b1 LL |
761 | test_expect_success 'reject cloning shallow repository using HTTP' ' |
762 | test_when_finished "rm -rf repo" && | |
763 | git clone --bare --no-local --depth=1 src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && | |
b89c7312 | 764 | test_must_fail git -c protocol.version=2 clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err && |
4fe788b1 LL |
765 | test_i18ngrep -e "source repository is shallow, reject to clone." err && |
766 | ||
767 | git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo | |
768 | ' | |
769 | ||
decfe05b SG |
770 | # DO NOT add non-httpd-specific tests here, because the last part of this |
771 | # test script is only executed when httpd is available and enabled. | |
772 | ||
a2b26acd | 773 | test_done |