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