]>
Commit | Line | Data |
---|---|---|
a2b26acd JH |
1 | #!/bin/sh |
2 | ||
3 | test_description=clone | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success setup ' | |
8 | ||
9 | rm -fr .git && | |
10 | test_create_repo src && | |
11 | ( | |
12 | cd src | |
13 | >file | |
14 | git add file | |
15 | git commit -m initial | |
16 | ) | |
17 | ||
18 | ' | |
19 | ||
1db4a75c | 20 | test_expect_success 'clone with excess parameters (1)' ' |
a2b26acd | 21 | |
1db4a75c SP |
22 | rm -fr dst && |
23 | test_must_fail git clone -n src dst junk | |
24 | ||
25 | ' | |
26 | ||
27 | test_expect_success 'clone with excess parameters (2)' ' | |
28 | ||
29 | rm -fr dst && | |
a2b26acd JH |
30 | test_must_fail git clone -n "file://$(pwd)/src" dst junk |
31 | ||
32 | ' | |
33 | ||
2c3766f0 AM |
34 | test_expect_success 'output from clone' ' |
35 | rm -fr dst && | |
36 | git clone -n "file://$(pwd)/src" dst >output && | |
28ba96ab | 37 | test $(grep Clon output | wc -l) = 1 |
2c3766f0 AM |
38 | ' |
39 | ||
1db4a75c SP |
40 | test_expect_success 'clone does not keep pack' ' |
41 | ||
42 | rm -fr dst && | |
43 | git clone -n "file://$(pwd)/src" dst && | |
44 | ! test -f dst/file && | |
45 | ! (echo dst/.git/objects/pack/pack-* | grep "\.keep") | |
46 | ||
47 | ' | |
48 | ||
a73bc127 JS |
49 | test_expect_success 'clone checks out files' ' |
50 | ||
1db4a75c | 51 | rm -fr dst && |
a73bc127 JS |
52 | git clone src dst && |
53 | test -f dst/file | |
54 | ||
55 | ' | |
56 | ||
2beebd22 JK |
57 | test_expect_success 'clone respects GIT_WORK_TREE' ' |
58 | ||
59 | GIT_WORK_TREE=worktree git clone src bare && | |
60 | test -f bare/config && | |
61 | test -f worktree/file | |
62 | ||
63 | ' | |
64 | ||
65 | test_expect_success 'clone creates intermediate directories' ' | |
66 | ||
67 | git clone src long/path/to/dst && | |
68 | test -f long/path/to/dst/file | |
69 | ||
70 | ' | |
71 | ||
72 | test_expect_success 'clone creates intermediate directories for bare repo' ' | |
73 | ||
74 | git clone --bare src long/path/to/bare/dst && | |
75 | test -f long/path/to/bare/dst/config | |
76 | ||
77 | ' | |
78 | ||
bc699afc JS |
79 | test_expect_success 'clone --mirror' ' |
80 | ||
81 | git clone --mirror src mirror && | |
82 | test -f mirror/HEAD && | |
83 | test ! -f mirror/file && | |
84 | FETCH="$(cd mirror && git config remote.origin.fetch)" && | |
85 | test "+refs/*:refs/*" = "$FETCH" && | |
86 | MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" && | |
87 | test "$MIRROR" = true | |
88 | ||
89 | ' | |
90 | ||
6612f877 JS |
91 | test_expect_success 'clone --bare names the local repository <name>.git' ' |
92 | ||
93 | git clone --bare src && | |
94 | test -d src.git | |
95 | ||
96 | ' | |
97 | ||
468386a9 JS |
98 | test_expect_success 'clone --mirror does not repeat tags' ' |
99 | ||
100 | (cd src && | |
101 | git tag some-tag HEAD) && | |
102 | git clone --mirror src mirror2 && | |
103 | (cd mirror2 && | |
104 | git show-ref 2> clone.err > clone.out) && | |
105 | test_must_fail grep Duplicate mirror2/clone.err && | |
106 | grep some-tag mirror2/clone.out | |
107 | ||
108 | ' | |
109 | ||
44a68fd5 CB |
110 | test_expect_success 'clone to destination with trailing /' ' |
111 | ||
112 | git clone src target-1/ && | |
113 | T=$( cd target-1 && git rev-parse HEAD ) && | |
114 | S=$( cd src && git rev-parse HEAD ) && | |
115 | test "$T" = "$S" | |
116 | ||
117 | ' | |
118 | ||
119 | test_expect_success 'clone to destination with extra trailing /' ' | |
120 | ||
121 | git clone src target-2/// && | |
122 | T=$( cd target-2 && git rev-parse HEAD ) && | |
123 | S=$( cd src && git rev-parse HEAD ) && | |
124 | test "$T" = "$S" | |
125 | ||
126 | ' | |
127 | ||
55892d23 AP |
128 | test_expect_success 'clone to an existing empty directory' ' |
129 | mkdir target-3 && | |
130 | git clone src target-3 && | |
131 | T=$( cd target-3 && git rev-parse HEAD ) && | |
132 | S=$( cd src && git rev-parse HEAD ) && | |
133 | test "$T" = "$S" | |
134 | ' | |
135 | ||
136 | test_expect_success 'clone to an existing non-empty directory' ' | |
137 | mkdir target-4 && | |
138 | >target-4/Fakefile && | |
139 | test_must_fail git clone src target-4 | |
140 | ' | |
141 | ||
142 | test_expect_success 'clone to an existing path' ' | |
143 | >target-5 && | |
144 | test_must_fail git clone src target-5 | |
145 | ' | |
146 | ||
5cd12b85 JH |
147 | test_expect_success 'clone a void' ' |
148 | mkdir src-0 && | |
149 | ( | |
150 | cd src-0 && git init | |
151 | ) && | |
12d49966 JK |
152 | git clone "file://$(pwd)/src-0" target-6 2>err-6 && |
153 | ! grep "fatal:" err-6 && | |
5cd12b85 JH |
154 | ( |
155 | cd src-0 && test_commit A | |
156 | ) && | |
12d49966 JK |
157 | git clone "file://$(pwd)/src-0" target-7 2>err-7 && |
158 | ! grep "fatal:" err-7 && | |
5cd12b85 JH |
159 | # There is no reason to insist they are bit-for-bit |
160 | # identical, but this test should suffice for now. | |
161 | test_cmp target-6/.git/config target-7/.git/config | |
162 | ' | |
163 | ||
a9f2c136 JH |
164 | test_expect_success 'clone respects global branch.autosetuprebase' ' |
165 | ( | |
a9f2c136 JH |
166 | test_config="$HOME/.gitconfig" && |
167 | unset GIT_CONFIG_NOGLOBAL && | |
168 | git config -f "$test_config" branch.autosetuprebase remote && | |
169 | rm -fr dst && | |
170 | git clone src dst && | |
171 | cd dst && | |
172 | actual="z$(git config branch.master.rebase)" && | |
173 | test ztrue = $actual | |
174 | ) | |
175 | ' | |
176 | ||
9d2e9420 JK |
177 | test_expect_success 'respect url-encoding of file://' ' |
178 | git init x+y && | |
730220de TR |
179 | git clone "file://$PWD/x+y" xy-url-1 && |
180 | git clone "file://$PWD/x%2By" xy-url-2 | |
181 | ' | |
182 | ||
183 | test_expect_success 'do not query-string-decode + in URLs' ' | |
184 | rm -rf x+y && | |
185 | git init "x y" && | |
186 | test_must_fail git clone "file://$PWD/x+y" xy-no-plus | |
9d2e9420 JK |
187 | ' |
188 | ||
189 | test_expect_success 'do not respect url-encoding of non-url path' ' | |
190 | git init x+y && | |
191 | test_must_fail git clone x%2By xy-regular && | |
192 | git clone x+y xy-regular | |
193 | ' | |
194 | ||
a2b26acd | 195 | test_done |