]>
Commit | Line | Data |
---|---|---|
6adcca3f JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git init' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | check_config () { | |
8 | if test -d "$1" && test -f "$1/config" && test -d "$1/refs" | |
9 | then | |
10 | : happy | |
11 | else | |
12 | echo "expected a directory $1, a file $1/config and $1/refs" | |
13 | return 1 | |
14 | fi | |
15 | bare=$(GIT_CONFIG="$1/config" git config --bool core.bare) | |
16 | worktree=$(GIT_CONFIG="$1/config" git config core.worktree) || | |
17 | worktree=unset | |
18 | ||
19 | test "$bare" = "$2" && test "$worktree" = "$3" || { | |
20 | echo "expected bare=$2 worktree=$3" | |
21 | echo " got bare=$bare worktree=$worktree" | |
22 | return 1 | |
23 | } | |
24 | } | |
25 | ||
26 | test_expect_success 'plain' ' | |
27 | ( | |
6adcca3f JH |
28 | mkdir plain && |
29 | cd plain && | |
30 | git init | |
31 | ) && | |
32 | check_config plain/.git false unset | |
33 | ' | |
34 | ||
4ad8332e JN |
35 | test_expect_success 'plain nested in bare' ' |
36 | ( | |
4ad8332e JN |
37 | git init --bare bare-ancestor.git && |
38 | cd bare-ancestor.git && | |
39 | mkdir plain-nested && | |
40 | cd plain-nested && | |
41 | git init | |
42 | ) && | |
43 | check_config bare-ancestor.git/plain-nested/.git false unset | |
44 | ' | |
45 | ||
46 | test_expect_success 'plain through aliased command, outside any git repo' ' | |
47 | ( | |
4ad8332e JN |
48 | HOME=$(pwd)/alias-config && |
49 | export HOME && | |
50 | mkdir alias-config && | |
51 | echo "[alias] aliasedinit = init" >alias-config/.gitconfig && | |
52 | ||
53 | GIT_CEILING_DIRECTORIES=$(pwd) && | |
54 | export GIT_CEILING_DIRECTORIES && | |
55 | ||
56 | mkdir plain-aliased && | |
57 | cd plain-aliased && | |
58 | git aliasedinit | |
59 | ) && | |
60 | check_config plain-aliased/.git false unset | |
61 | ' | |
62 | ||
63 | test_expect_failure 'plain nested through aliased command' ' | |
64 | ( | |
4ad8332e JN |
65 | git init plain-ancestor-aliased && |
66 | cd plain-ancestor-aliased && | |
67 | echo "[alias] aliasedinit = init" >>.git/config && | |
68 | mkdir plain-nested && | |
69 | cd plain-nested && | |
70 | git aliasedinit | |
71 | ) && | |
72 | check_config plain-ancestor-aliased/plain-nested/.git false unset | |
73 | ' | |
74 | ||
75 | test_expect_failure 'plain nested in bare through aliased command' ' | |
76 | ( | |
4ad8332e JN |
77 | git init --bare bare-ancestor-aliased.git && |
78 | cd bare-ancestor-aliased.git && | |
79 | echo "[alias] aliasedinit = init" >>config && | |
80 | mkdir plain-nested && | |
81 | cd plain-nested && | |
82 | git aliasedinit | |
83 | ) && | |
84 | check_config bare-ancestor-aliased.git/plain-nested/.git false unset | |
6adcca3f JH |
85 | ' |
86 | ||
87 | test_expect_success 'plain with GIT_WORK_TREE' ' | |
88 | if ( | |
6adcca3f JH |
89 | mkdir plain-wt && |
90 | cd plain-wt && | |
91 | GIT_WORK_TREE=$(pwd) git init | |
92 | ) | |
93 | then | |
94 | echo Should have failed -- GIT_WORK_TREE should not be used | |
95 | false | |
96 | fi | |
97 | ' | |
98 | ||
99 | test_expect_success 'plain bare' ' | |
100 | ( | |
6adcca3f JH |
101 | mkdir plain-bare-1 && |
102 | cd plain-bare-1 && | |
103 | git --bare init | |
104 | ) && | |
105 | check_config plain-bare-1 true unset | |
106 | ' | |
107 | ||
108 | test_expect_success 'plain bare with GIT_WORK_TREE' ' | |
109 | if ( | |
6adcca3f JH |
110 | mkdir plain-bare-2 && |
111 | cd plain-bare-2 && | |
112 | GIT_WORK_TREE=$(pwd) git --bare init | |
113 | ) | |
114 | then | |
115 | echo Should have failed -- GIT_WORK_TREE should not be used | |
116 | false | |
117 | fi | |
118 | ' | |
119 | ||
120 | test_expect_success 'GIT_DIR bare' ' | |
121 | ||
122 | ( | |
6adcca3f JH |
123 | mkdir git-dir-bare.git && |
124 | GIT_DIR=git-dir-bare.git git init | |
125 | ) && | |
126 | check_config git-dir-bare.git true unset | |
127 | ' | |
128 | ||
74d3b23f LR |
129 | test_expect_success 'init --bare' ' |
130 | ||
131 | ( | |
b6138273 MV |
132 | mkdir init-bare.git && |
133 | cd init-bare.git && | |
74d3b23f LR |
134 | git init --bare |
135 | ) && | |
b6138273 | 136 | check_config init-bare.git true unset |
74d3b23f LR |
137 | ' |
138 | ||
6adcca3f JH |
139 | test_expect_success 'GIT_DIR non-bare' ' |
140 | ||
141 | ( | |
6adcca3f JH |
142 | mkdir non-bare && |
143 | cd non-bare && | |
144 | GIT_DIR=.git git init | |
145 | ) && | |
146 | check_config non-bare/.git false unset | |
147 | ' | |
148 | ||
149 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' | |
150 | ||
151 | ( | |
6adcca3f JH |
152 | mkdir git-dir-wt-1.git && |
153 | GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init | |
154 | ) && | |
155 | check_config git-dir-wt-1.git false "$(pwd)" | |
156 | ' | |
157 | ||
158 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' | |
159 | ||
160 | if ( | |
6adcca3f JH |
161 | mkdir git-dir-wt-2.git && |
162 | GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init | |
163 | ) | |
164 | then | |
165 | echo Should have failed -- --bare should not be used | |
166 | false | |
167 | fi | |
168 | ' | |
169 | ||
127df8c6 | 170 | test_expect_success 'reinit' ' |
5cc8f372 JS |
171 | |
172 | ( | |
5cc8f372 JS |
173 | mkdir again && |
174 | cd again && | |
175 | git init >out1 2>err1 && | |
176 | git init >out2 2>err2 | |
177 | ) && | |
127df8c6 JH |
178 | test_i18ngrep "Initialized empty" again/out1 && |
179 | test_i18ngrep "Reinitialized existing" again/out2 && | |
5cc8f372 | 180 | >again/empty && |
127df8c6 JH |
181 | test_i18ncmp again/empty again/err1 && |
182 | test_i18ncmp again/empty again/err2 | |
5cc8f372 JS |
183 | ' |
184 | ||
172035f0 JK |
185 | test_expect_success 'init with --template' ' |
186 | mkdir template-source && | |
187 | echo content >template-source/file && | |
188 | ( | |
189 | mkdir template-custom && | |
190 | cd template-custom && | |
191 | git init --template=../template-source | |
192 | ) && | |
193 | test_cmp template-source/file template-custom/.git/file | |
194 | ' | |
195 | ||
196 | test_expect_success 'init with --template (blank)' ' | |
197 | ( | |
198 | mkdir template-plain && | |
199 | cd template-plain && | |
200 | git init | |
201 | ) && | |
202 | test -f template-plain/.git/info/exclude && | |
203 | ( | |
204 | mkdir template-blank && | |
205 | cd template-blank && | |
206 | git init --template= | |
207 | ) && | |
208 | ! test -f template-blank/.git/info/exclude | |
209 | ' | |
210 | ||
a94d305b SD |
211 | test_expect_success 'init with init.templatedir set' ' |
212 | mkdir templatedir-source && | |
213 | echo Content >templatedir-source/file && | |
214 | ( | |
a94d305b SD |
215 | test_config="${HOME}/.gitconfig" && |
216 | git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" && | |
217 | mkdir templatedir-set && | |
218 | cd templatedir-set && | |
00648ba0 | 219 | sane_unset GIT_TEMPLATE_DIR && |
a94d305b SD |
220 | NO_SET_GIT_TEMPLATE_DIR=t && |
221 | export NO_SET_GIT_TEMPLATE_DIR && | |
222 | git init | |
223 | ) && | |
224 | test_cmp templatedir-source/file templatedir-set/.git/file | |
225 | ' | |
226 | ||
0a2c7eea DM |
227 | test_expect_success 'init --bare/--shared overrides system/global config' ' |
228 | ( | |
0a2c7eea | 229 | test_config="$HOME"/.gitconfig && |
0a2c7eea DM |
230 | git config -f "$test_config" core.bare false && |
231 | git config -f "$test_config" core.sharedRepository 0640 && | |
232 | mkdir init-bare-shared-override && | |
233 | cd init-bare-shared-override && | |
234 | git init --bare --shared=0666 | |
235 | ) && | |
236 | check_config init-bare-shared-override true unset && | |
237 | test x0666 = \ | |
238 | x`git config -f init-bare-shared-override/config core.sharedRepository` | |
239 | ' | |
240 | ||
241 | test_expect_success 'init honors global core.sharedRepository' ' | |
242 | ( | |
0a2c7eea | 243 | test_config="$HOME"/.gitconfig && |
0a2c7eea DM |
244 | git config -f "$test_config" core.sharedRepository 0666 && |
245 | mkdir shared-honor-global && | |
246 | cd shared-honor-global && | |
247 | git init | |
248 | ) && | |
249 | test x0666 = \ | |
250 | x`git config -f shared-honor-global/.git/config core.sharedRepository` | |
251 | ' | |
252 | ||
32d1776b FL |
253 | test_expect_success 'init rejects insanely long --template' ' |
254 | ( | |
255 | insane=$(printf "x%09999dx" 1) && | |
256 | mkdir test && | |
257 | cd test && | |
258 | test_must_fail git init --template=$insane | |
259 | ) | |
260 | ' | |
261 | ||
53d48885 NS |
262 | test_expect_success 'init creates a new directory' ' |
263 | rm -fr newdir && | |
264 | ( | |
265 | git init newdir && | |
266 | test -d newdir/.git/refs | |
267 | ) | |
268 | ' | |
269 | ||
270 | test_expect_success 'init creates a new bare directory' ' | |
271 | rm -fr newdir && | |
272 | ( | |
273 | git init --bare newdir && | |
274 | test -d newdir/refs | |
275 | ) | |
276 | ' | |
277 | ||
278 | test_expect_success 'init recreates a directory' ' | |
279 | rm -fr newdir && | |
280 | ( | |
281 | mkdir newdir && | |
282 | git init newdir && | |
283 | test -d newdir/.git/refs | |
284 | ) | |
285 | ' | |
286 | ||
287 | test_expect_success 'init recreates a new bare directory' ' | |
288 | rm -fr newdir && | |
289 | ( | |
290 | mkdir newdir && | |
291 | git init --bare newdir && | |
292 | test -d newdir/refs | |
293 | ) | |
294 | ' | |
295 | ||
296 | test_expect_success 'init creates a new deep directory' ' | |
d82e75e8 JS |
297 | rm -fr newdir && |
298 | git init newdir/a/b/c && | |
299 | test -d newdir/a/b/c/.git/refs | |
300 | ' | |
301 | ||
302 | test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' ' | |
53d48885 NS |
303 | rm -fr newdir && |
304 | ( | |
305 | # Leading directories should honor umask while | |
306 | # the repository itself should follow "shared" | |
307 | umask 002 && | |
308 | git init --bare --shared=0660 newdir/a/b/c && | |
309 | test -d newdir/a/b/c/refs && | |
310 | ls -ld newdir/a newdir/a/b > lsab.out && | |
7d53a07a | 311 | ! grep -v "^drwxrw[sx]r-x" lsab.out && |
53d48885 NS |
312 | ls -ld newdir/a/b/c > lsc.out && |
313 | ! grep -v "^drwxrw[sx]---" lsc.out | |
314 | ) | |
315 | ' | |
316 | ||
317 | test_expect_success 'init notices EEXIST (1)' ' | |
318 | rm -fr newdir && | |
319 | ( | |
320 | >newdir && | |
321 | test_must_fail git init newdir && | |
322 | test -f newdir | |
323 | ) | |
324 | ' | |
325 | ||
326 | test_expect_success 'init notices EEXIST (2)' ' | |
327 | rm -fr newdir && | |
328 | ( | |
329 | mkdir newdir && | |
330 | >newdir/a | |
331 | test_must_fail git init newdir/a/b && | |
332 | test -f newdir/a | |
333 | ) | |
334 | ' | |
335 | ||
c91cfd19 | 336 | test_expect_success POSIXPERM,SANITY 'init notices EPERM' ' |
53d48885 NS |
337 | rm -fr newdir && |
338 | ( | |
339 | mkdir newdir && | |
340 | chmod -w newdir && | |
341 | test_must_fail git init newdir/a/b | |
342 | ) | |
343 | ' | |
344 | ||
87a074df JK |
345 | test_expect_success 'init creates a new bare directory with global --bare' ' |
346 | rm -rf newdir && | |
347 | git --bare init newdir && | |
348 | test -d newdir/refs | |
349 | ' | |
350 | ||
351 | test_expect_success 'init prefers command line to GIT_DIR' ' | |
352 | rm -rf newdir && | |
353 | mkdir otherdir && | |
354 | GIT_DIR=otherdir git --bare init newdir && | |
355 | test -d newdir/refs && | |
356 | ! test -d otherdir/refs | |
357 | ' | |
358 | ||
b57fb80a NTND |
359 | test_expect_success 'init with separate gitdir' ' |
360 | rm -rf newdir && | |
361 | git init --separate-git-dir realgitdir newdir && | |
362 | echo "gitdir: `pwd`/realgitdir" >expected && | |
363 | test_cmp expected newdir/.git && | |
364 | test -d realgitdir/refs | |
365 | ' | |
366 | ||
487a2b73 NTND |
367 | test_expect_success 're-init on .git file' ' |
368 | ( cd newdir && git init ) | |
369 | ' | |
370 | ||
b57fb80a NTND |
371 | test_expect_success 're-init to update git link' ' |
372 | ( | |
373 | cd newdir && | |
374 | git init --separate-git-dir ../surrealgitdir | |
375 | ) && | |
376 | echo "gitdir: `pwd`/surrealgitdir" >expected && | |
377 | test_cmp expected newdir/.git && | |
378 | test -d surrealgitdir/refs && | |
379 | ! test -d realgitdir/refs | |
380 | ' | |
381 | ||
382 | test_expect_success 're-init to move gitdir' ' | |
383 | rm -rf newdir realgitdir surrealgitdir && | |
384 | git init newdir && | |
385 | ( | |
386 | cd newdir && | |
387 | git init --separate-git-dir ../realgitdir | |
388 | ) && | |
389 | echo "gitdir: `pwd`/realgitdir" >expected && | |
390 | test_cmp expected newdir/.git && | |
391 | test -d realgitdir/refs | |
392 | ' | |
393 | ||
4e95fb6c | 394 | test_expect_success SYMLINKS 're-init to move gitdir symlink' ' |
b57fb80a NTND |
395 | rm -rf newdir realgitdir && |
396 | git init newdir && | |
397 | ( | |
398 | cd newdir && | |
399 | mv .git here && | |
400 | ln -s here .git && | |
09ffc706 | 401 | git init --separate-git-dir ../realgitdir |
b57fb80a NTND |
402 | ) && |
403 | echo "gitdir: `pwd`/realgitdir" >expected && | |
404 | test_cmp expected newdir/.git && | |
405 | test -d realgitdir/refs && | |
406 | ! test -d newdir/here | |
407 | ' | |
408 | ||
6adcca3f | 409 | test_done |