Git fork
1#!/bin/sh
2
3test_description='check output directory names used by git-clone'
4
5. ./test-lib.sh
6
7# we use a fake ssh wrapper that ignores the arguments
8# entirely; we really only care that we get _some_ repo,
9# as the real test is what clone does on the local side
10test_expect_success 'setup ssh wrapper' '
11 write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
12 git upload-pack "$TRASH_DIRECTORY"
13 EOF
14 GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
15 GIT_SSH_VARIANT=ssh &&
16 export GIT_SSH &&
17 export GIT_SSH_VARIANT &&
18 export TRASH_DIRECTORY
19'
20
21# make sure that cloning $1 results in local directory $2
22test_clone_dir () {
23 url=$1; shift
24 dir=$1; shift
25 expect=success
26 bare=non-bare
27 clone_opts=
28 for i in "$@"
29 do
30 case "$i" in
31 fail)
32 expect=failure
33 ;;
34 bare)
35 bare=bare
36 clone_opts=--bare
37 ;;
38 esac
39 done
40 test_expect_$expect "clone of $url goes to $dir ($bare)" "
41 rm -rf $dir &&
42 git clone $clone_opts $url &&
43 test_path_is_dir $dir
44 "
45}
46
47# basic syntax with bare and non-bare variants
48test_clone_dir host:foo foo
49test_clone_dir host:foo foo.git bare
50test_clone_dir host:foo.git foo
51test_clone_dir host:foo.git foo.git bare
52test_clone_dir host:foo/.git foo
53test_clone_dir host:foo/.git foo.git bare
54
55# similar, but using ssh URL rather than host:path syntax
56test_clone_dir ssh://host/foo foo
57test_clone_dir ssh://host/foo foo.git bare
58test_clone_dir ssh://host/foo.git foo
59test_clone_dir ssh://host/foo.git foo.git bare
60test_clone_dir ssh://host/foo/.git foo
61test_clone_dir ssh://host/foo/.git foo.git bare
62
63# we should remove trailing slashes and .git suffixes
64test_clone_dir ssh://host/foo/ foo
65test_clone_dir ssh://host/foo/// foo
66test_clone_dir ssh://host/foo/.git/ foo
67test_clone_dir ssh://host/foo.git/ foo
68test_clone_dir ssh://host/foo.git/// foo
69test_clone_dir ssh://host/foo///.git/ foo
70test_clone_dir ssh://host/foo/.git/// foo
71
72test_clone_dir host:foo/ foo
73test_clone_dir host:foo/// foo
74test_clone_dir host:foo.git/ foo
75test_clone_dir host:foo/.git/ foo
76test_clone_dir host:foo.git/// foo
77test_clone_dir host:foo///.git/ foo
78test_clone_dir host:foo/.git/// foo
79
80# omitting the path should default to the hostname
81test_clone_dir ssh://host/ host
82test_clone_dir ssh://host:1234/ host
83test_clone_dir ssh://user@host/ host
84test_clone_dir host:/ host
85
86# auth materials should be redacted
87test_clone_dir ssh://user:password@host/ host
88test_clone_dir ssh://user:password@host:1234/ host
89test_clone_dir ssh://user:passw@rd@host:1234/ host
90test_clone_dir user@host:/ host
91test_clone_dir user:password@host:/ host
92test_clone_dir user:passw@rd@host:/ host
93
94# auth-like material should not be dropped
95test_clone_dir ssh://host/foo@bar foo@bar
96test_clone_dir ssh://host/foo@bar.git foo@bar
97test_clone_dir ssh://user:password@host/foo@bar foo@bar
98test_clone_dir ssh://user:passw@rd@host/foo@bar.git foo@bar
99
100test_clone_dir host:/foo@bar foo@bar
101test_clone_dir host:/foo@bar.git foo@bar
102test_clone_dir user:password@host:/foo@bar foo@bar
103test_clone_dir user:passw@rd@host:/foo@bar.git foo@bar
104
105# trailing port-like numbers should not be stripped for paths
106test_clone_dir ssh://user:password@host/test:1234 1234
107test_clone_dir ssh://user:password@host/test:1234.git 1234
108
109test_done