]>
Commit | Line | Data |
---|---|---|
6adcca3f JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git init' | |
4 | ||
c150064d | 5 | TEST_PASSES_SANITIZE_LEAK=true |
6adcca3f JH |
6 | . ./test-lib.sh |
7 | ||
8 | check_config () { | |
d4fe066e SY |
9 | if test_path_is_dir "$1" && |
10 | test_path_is_file "$1/config" && test_path_is_dir "$1/refs" | |
6adcca3f JH |
11 | then |
12 | : happy | |
13 | else | |
14 | echo "expected a directory $1, a file $1/config and $1/refs" | |
15 | return 1 | |
16 | fi | |
1f32ecff MH |
17 | |
18 | if test_have_prereq POSIXPERM && test -x "$1/config" | |
19 | then | |
20 | echo "$1/config is executable?" | |
21 | return 1 | |
22 | fi | |
23 | ||
3cc6a6f0 JK |
24 | bare=$(cd "$1" && git config --bool core.bare) |
25 | worktree=$(cd "$1" && git config core.worktree) || | |
6adcca3f JH |
26 | worktree=unset |
27 | ||
28 | test "$bare" = "$2" && test "$worktree" = "$3" || { | |
29 | echo "expected bare=$2 worktree=$3" | |
30 | echo " got bare=$bare worktree=$worktree" | |
31 | return 1 | |
32 | } | |
33 | } | |
34 | ||
35 | test_expect_success 'plain' ' | |
410c3428 | 36 | git init plain && |
6adcca3f JH |
37 | check_config plain/.git false unset |
38 | ' | |
39 | ||
4ad8332e JN |
40 | test_expect_success 'plain nested in bare' ' |
41 | ( | |
4ad8332e JN |
42 | git init --bare bare-ancestor.git && |
43 | cd bare-ancestor.git && | |
44 | mkdir plain-nested && | |
45 | cd plain-nested && | |
46 | git init | |
47 | ) && | |
48 | check_config bare-ancestor.git/plain-nested/.git false unset | |
49 | ' | |
50 | ||
51 | test_expect_success 'plain through aliased command, outside any git repo' ' | |
52 | ( | |
4ad8332e JN |
53 | HOME=$(pwd)/alias-config && |
54 | export HOME && | |
55 | mkdir alias-config && | |
56 | echo "[alias] aliasedinit = init" >alias-config/.gitconfig && | |
57 | ||
58 | GIT_CEILING_DIRECTORIES=$(pwd) && | |
59 | export GIT_CEILING_DIRECTORIES && | |
60 | ||
61 | mkdir plain-aliased && | |
62 | cd plain-aliased && | |
63 | git aliasedinit | |
64 | ) && | |
65 | check_config plain-aliased/.git false unset | |
66 | ' | |
67 | ||
c0562611 | 68 | test_expect_success 'plain nested through aliased command' ' |
4ad8332e | 69 | ( |
4ad8332e JN |
70 | git init plain-ancestor-aliased && |
71 | cd plain-ancestor-aliased && | |
72 | echo "[alias] aliasedinit = init" >>.git/config && | |
73 | mkdir plain-nested && | |
74 | cd plain-nested && | |
75 | git aliasedinit | |
76 | ) && | |
77 | check_config plain-ancestor-aliased/plain-nested/.git false unset | |
78 | ' | |
79 | ||
c0562611 | 80 | test_expect_success 'plain nested in bare through aliased command' ' |
4ad8332e | 81 | ( |
4ad8332e JN |
82 | git init --bare bare-ancestor-aliased.git && |
83 | cd bare-ancestor-aliased.git && | |
84 | echo "[alias] aliasedinit = init" >>config && | |
85 | mkdir plain-nested && | |
86 | cd plain-nested && | |
87 | git aliasedinit | |
88 | ) && | |
89 | check_config bare-ancestor-aliased.git/plain-nested/.git false unset | |
6adcca3f JH |
90 | ' |
91 | ||
57ea7123 | 92 | test_expect_success 'No extra GIT_* on alias scripts' ' |
f3858f8e JS |
93 | write_script script <<-\EOF && |
94 | env | | |
95 | sed -n \ | |
96 | -e "/^GIT_PREFIX=/d" \ | |
97 | -e "/^GIT_TEXTDOMAINDIR=/d" \ | |
e4b75d6a | 98 | -e "/^GIT_TRACE2_PARENT/d" \ |
f3858f8e JS |
99 | -e "/^GIT_/s/=.*//p" | |
100 | sort | |
57ea7123 | 101 | EOF |
f3858f8e | 102 | ./script >expected && |
57ea7123 | 103 | git config alias.script \!./script && |
f3858f8e | 104 | ( mkdir sub && cd sub && git script >../actual ) && |
57ea7123 NTND |
105 | test_cmp expected actual |
106 | ' | |
107 | ||
6adcca3f | 108 | test_expect_success 'plain with GIT_WORK_TREE' ' |
0981140f JK |
109 | mkdir plain-wt && |
110 | test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt | |
6adcca3f JH |
111 | ' |
112 | ||
113 | test_expect_success 'plain bare' ' | |
410c3428 | 114 | git --bare init plain-bare-1 && |
6adcca3f JH |
115 | check_config plain-bare-1 true unset |
116 | ' | |
117 | ||
118 | test_expect_success 'plain bare with GIT_WORK_TREE' ' | |
0981140f JK |
119 | mkdir plain-bare-2 && |
120 | test_must_fail \ | |
121 | env GIT_WORK_TREE="$(pwd)/plain-bare-2" \ | |
122 | git --bare init plain-bare-2 | |
6adcca3f JH |
123 | ' |
124 | ||
125 | test_expect_success 'GIT_DIR bare' ' | |
99e1c736 JK |
126 | mkdir git-dir-bare.git && |
127 | GIT_DIR=git-dir-bare.git git init && | |
6adcca3f JH |
128 | check_config git-dir-bare.git true unset |
129 | ' | |
130 | ||
74d3b23f | 131 | test_expect_success 'init --bare' ' |
410c3428 | 132 | git init --bare init-bare.git && |
b6138273 | 133 | check_config init-bare.git true unset |
74d3b23f LR |
134 | ' |
135 | ||
6adcca3f JH |
136 | test_expect_success 'GIT_DIR non-bare' ' |
137 | ||
138 | ( | |
6adcca3f JH |
139 | mkdir non-bare && |
140 | cd non-bare && | |
141 | GIT_DIR=.git git init | |
142 | ) && | |
143 | check_config non-bare/.git false unset | |
144 | ' | |
145 | ||
146 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' | |
147 | ||
148 | ( | |
6adcca3f JH |
149 | mkdir git-dir-wt-1.git && |
150 | GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init | |
151 | ) && | |
152 | check_config git-dir-wt-1.git false "$(pwd)" | |
153 | ' | |
154 | ||
155 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' | |
0981140f JK |
156 | mkdir git-dir-wt-2.git && |
157 | test_must_fail env \ | |
158 | GIT_WORK_TREE="$(pwd)" \ | |
159 | GIT_DIR=git-dir-wt-2.git \ | |
160 | git --bare init | |
6adcca3f JH |
161 | ' |
162 | ||
127df8c6 | 163 | test_expect_success 'reinit' ' |
5cc8f372 JS |
164 | |
165 | ( | |
5cc8f372 JS |
166 | mkdir again && |
167 | cd again && | |
675704c7 | 168 | git -c init.defaultBranch=initial init >out1 2>err1 && |
5cc8f372 JS |
169 | git init >out2 2>err2 |
170 | ) && | |
6789275d JH |
171 | test_grep "Initialized empty" again/out1 && |
172 | test_grep "Reinitialized existing" again/out2 && | |
1c5e94f4 SG |
173 | test_must_be_empty again/err1 && |
174 | test_must_be_empty again/err2 | |
5cc8f372 JS |
175 | ' |
176 | ||
172035f0 JK |
177 | test_expect_success 'init with --template' ' |
178 | mkdir template-source && | |
179 | echo content >template-source/file && | |
e1df7fe4 | 180 | git init --template=template-source template-custom && |
172035f0 JK |
181 | test_cmp template-source/file template-custom/.git/file |
182 | ' | |
183 | ||
184 | test_expect_success 'init with --template (blank)' ' | |
410c3428 | 185 | git init template-plain && |
633734d4 | 186 | test_path_is_file template-plain/.git/info/exclude && |
410c3428 | 187 | git init --template= template-blank && |
633734d4 | 188 | test_path_is_missing template-blank/.git/info/exclude |
172035f0 JK |
189 | ' |
190 | ||
a185dd58 | 191 | init_no_templatedir_env () { |
a94d305b | 192 | ( |
00648ba0 | 193 | sane_unset GIT_TEMPLATE_DIR && |
a94d305b SD |
194 | NO_SET_GIT_TEMPLATE_DIR=t && |
195 | export NO_SET_GIT_TEMPLATE_DIR && | |
a185dd58 MT |
196 | git init "$1" |
197 | ) | |
198 | } | |
199 | ||
200 | test_expect_success 'init with init.templatedir set' ' | |
201 | mkdir templatedir-source && | |
202 | echo Content >templatedir-source/file && | |
203 | test_config_global init.templatedir "${HOME}/templatedir-source" && | |
204 | ||
205 | init_no_templatedir_env templatedir-set && | |
a94d305b SD |
206 | test_cmp templatedir-source/file templatedir-set/.git/file |
207 | ' | |
208 | ||
a185dd58 MT |
209 | test_expect_success 'init with init.templatedir using ~ expansion' ' |
210 | mkdir -p templatedir-source && | |
211 | echo Content >templatedir-source/file && | |
212 | test_config_global init.templatedir "~/templatedir-source" && | |
213 | ||
214 | init_no_templatedir_env templatedir-expansion && | |
215 | test_cmp templatedir-source/file templatedir-expansion/.git/file | |
216 | ' | |
217 | ||
0a2c7eea | 218 | test_expect_success 'init --bare/--shared overrides system/global config' ' |
2a472410 JK |
219 | test_config_global core.bare false && |
220 | test_config_global core.sharedRepository 0640 && | |
410c3428 | 221 | git init --bare --shared=0666 init-bare-shared-override && |
0a2c7eea DM |
222 | check_config init-bare-shared-override true unset && |
223 | test x0666 = \ | |
88619b3e | 224 | x$(git config -f init-bare-shared-override/config core.sharedRepository) |
0a2c7eea DM |
225 | ' |
226 | ||
227 | test_expect_success 'init honors global core.sharedRepository' ' | |
2a472410 | 228 | test_config_global core.sharedRepository 0666 && |
410c3428 | 229 | git init shared-honor-global && |
0a2c7eea | 230 | test x0666 = \ |
88619b3e | 231 | x$(git config -f shared-honor-global/.git/config core.sharedRepository) |
0a2c7eea DM |
232 | ' |
233 | ||
9c28390b JK |
234 | test_expect_success 'init allows insanely long --template' ' |
235 | git init --template=$(printf "x%09999dx" 1) test | |
32d1776b FL |
236 | ' |
237 | ||
53d48885 NS |
238 | test_expect_success 'init creates a new directory' ' |
239 | rm -fr newdir && | |
99e1c736 JK |
240 | git init newdir && |
241 | test_path_is_dir newdir/.git/refs | |
53d48885 NS |
242 | ' |
243 | ||
244 | test_expect_success 'init creates a new bare directory' ' | |
245 | rm -fr newdir && | |
99e1c736 JK |
246 | git init --bare newdir && |
247 | test_path_is_dir newdir/refs | |
53d48885 NS |
248 | ' |
249 | ||
250 | test_expect_success 'init recreates a directory' ' | |
251 | rm -fr newdir && | |
99e1c736 JK |
252 | mkdir newdir && |
253 | git init newdir && | |
254 | test_path_is_dir newdir/.git/refs | |
53d48885 NS |
255 | ' |
256 | ||
257 | test_expect_success 'init recreates a new bare directory' ' | |
258 | rm -fr newdir && | |
99e1c736 JK |
259 | mkdir newdir && |
260 | git init --bare newdir && | |
261 | test_path_is_dir newdir/refs | |
53d48885 NS |
262 | ' |
263 | ||
264 | test_expect_success 'init creates a new deep directory' ' | |
d82e75e8 JS |
265 | rm -fr newdir && |
266 | git init newdir/a/b/c && | |
633734d4 | 267 | test_path_is_dir newdir/a/b/c/.git/refs |
d82e75e8 JS |
268 | ' |
269 | ||
270 | test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' ' | |
53d48885 NS |
271 | rm -fr newdir && |
272 | ( | |
273 | # Leading directories should honor umask while | |
274 | # the repository itself should follow "shared" | |
d549d213 MM |
275 | mkdir newdir && |
276 | # Remove a default ACL if possible. | |
277 | (setfacl -k newdir 2>/dev/null || true) && | |
53d48885 NS |
278 | umask 002 && |
279 | git init --bare --shared=0660 newdir/a/b/c && | |
633734d4 | 280 | test_path_is_dir newdir/a/b/c/refs && |
53d48885 | 281 | ls -ld newdir/a newdir/a/b > lsab.out && |
7d53a07a | 282 | ! grep -v "^drwxrw[sx]r-x" lsab.out && |
53d48885 NS |
283 | ls -ld newdir/a/b/c > lsc.out && |
284 | ! grep -v "^drwxrw[sx]---" lsc.out | |
285 | ) | |
286 | ' | |
287 | ||
288 | test_expect_success 'init notices EEXIST (1)' ' | |
289 | rm -fr newdir && | |
99e1c736 JK |
290 | >newdir && |
291 | test_must_fail git init newdir && | |
292 | test_path_is_file newdir | |
53d48885 NS |
293 | ' |
294 | ||
295 | test_expect_success 'init notices EEXIST (2)' ' | |
296 | rm -fr newdir && | |
99e1c736 JK |
297 | mkdir newdir && |
298 | >newdir/a && | |
299 | test_must_fail git init newdir/a/b && | |
300 | test_path_is_file newdir/a | |
53d48885 NS |
301 | ' |
302 | ||
c91cfd19 | 303 | test_expect_success POSIXPERM,SANITY 'init notices EPERM' ' |
03771425 | 304 | test_when_finished "chmod +w newdir" && |
53d48885 | 305 | rm -fr newdir && |
99e1c736 JK |
306 | mkdir newdir && |
307 | chmod -w newdir && | |
308 | test_must_fail git init newdir/a/b | |
53d48885 NS |
309 | ' |
310 | ||
87a074df JK |
311 | test_expect_success 'init creates a new bare directory with global --bare' ' |
312 | rm -rf newdir && | |
313 | git --bare init newdir && | |
633734d4 | 314 | test_path_is_dir newdir/refs |
87a074df JK |
315 | ' |
316 | ||
317 | test_expect_success 'init prefers command line to GIT_DIR' ' | |
318 | rm -rf newdir && | |
319 | mkdir otherdir && | |
320 | GIT_DIR=otherdir git --bare init newdir && | |
633734d4 JK |
321 | test_path_is_dir newdir/refs && |
322 | test_path_is_missing otherdir/refs | |
87a074df JK |
323 | ' |
324 | ||
b57fb80a NTND |
325 | test_expect_success 'init with separate gitdir' ' |
326 | rm -rf newdir && | |
327 | git init --separate-git-dir realgitdir newdir && | |
ed33bd8f JS |
328 | newdir_git="$(cat newdir/.git)" && |
329 | test_cmp_fspath "$(pwd)/realgitdir" "${newdir_git#gitdir: }" && | |
633734d4 | 330 | test_path_is_dir realgitdir/refs |
b57fb80a NTND |
331 | ' |
332 | ||
ccf236a2 ES |
333 | test_expect_success 'explicit bare & --separate-git-dir incompatible' ' |
334 | test_must_fail git init --bare --separate-git-dir goop.git bare.git 2>err && | |
6789275d | 335 | test_grep "cannot be used together" err |
ccf236a2 ES |
336 | ' |
337 | ||
338 | test_expect_success 'implicit bare & --separate-git-dir incompatible' ' | |
339 | test_when_finished "rm -rf bare.git" && | |
340 | mkdir -p bare.git && | |
341 | test_must_fail env GIT_DIR=. \ | |
342 | git -C bare.git init --separate-git-dir goop.git 2>err && | |
6789275d | 343 | test_grep "incompatible" err |
ccf236a2 ES |
344 | ' |
345 | ||
59d876cc ES |
346 | test_expect_success 'bare & --separate-git-dir incompatible within worktree' ' |
347 | test_when_finished "rm -rf bare.git linkwt seprepo" && | |
348 | test_commit gumby && | |
349 | git clone --bare . bare.git && | |
350 | git -C bare.git worktree add --detach ../linkwt && | |
351 | test_must_fail git -C linkwt init --separate-git-dir seprepo 2>err && | |
6789275d | 352 | test_grep "incompatible" err |
59d876cc ES |
353 | ' |
354 | ||
bed67874 RS |
355 | test_lazy_prereq GETCWD_IGNORES_PERMS ' |
356 | base=GETCWD_TEST_BASE_DIR && | |
357 | mkdir -p $base/dir && | |
358 | chmod 100 $base || | |
165293af | 359 | BUG "cannot prepare $base" |
bed67874 | 360 | |
482e1488 ÆAB |
361 | ( |
362 | cd $base/dir && | |
363 | test-tool getcwd | |
364 | ) | |
bed67874 RS |
365 | status=$? |
366 | ||
367 | chmod 700 $base && | |
368 | rm -rf $base || | |
165293af | 369 | BUG "cannot clean $base" |
bed67874 RS |
370 | return $status |
371 | ' | |
372 | ||
373 | check_long_base_path () { | |
a54e938e RS |
374 | # exceed initial buffer size of strbuf_getcwd() |
375 | component=123456789abcdef && | |
376 | test_when_finished "chmod 0700 $component; rm -rf $component" && | |
377 | p31=$component/$component && | |
378 | p127=$p31/$p31/$p31/$p31 && | |
379 | mkdir -p $p127 && | |
bed67874 RS |
380 | if test $# = 1 |
381 | then | |
382 | chmod $1 $component | |
383 | fi && | |
a54e938e RS |
384 | ( |
385 | cd $p127 && | |
386 | git init newdir | |
387 | ) | |
bed67874 RS |
388 | } |
389 | ||
390 | test_expect_success 'init in long base path' ' | |
391 | check_long_base_path | |
392 | ' | |
393 | ||
394 | test_expect_success GETCWD_IGNORES_PERMS 'init in long restricted base path' ' | |
395 | check_long_base_path 0111 | |
a54e938e RS |
396 | ' |
397 | ||
487a2b73 NTND |
398 | test_expect_success 're-init on .git file' ' |
399 | ( cd newdir && git init ) | |
400 | ' | |
401 | ||
b57fb80a | 402 | test_expect_success 're-init to update git link' ' |
ed33bd8f JS |
403 | git -C newdir init --separate-git-dir ../surrealgitdir && |
404 | newdir_git="$(cat newdir/.git)" && | |
405 | test_cmp_fspath "$(pwd)/surrealgitdir" "${newdir_git#gitdir: }" && | |
633734d4 JK |
406 | test_path_is_dir surrealgitdir/refs && |
407 | test_path_is_missing realgitdir/refs | |
b57fb80a NTND |
408 | ' |
409 | ||
410 | test_expect_success 're-init to move gitdir' ' | |
411 | rm -rf newdir realgitdir surrealgitdir && | |
412 | git init newdir && | |
ed33bd8f JS |
413 | git -C newdir init --separate-git-dir ../realgitdir && |
414 | newdir_git="$(cat newdir/.git)" && | |
415 | test_cmp_fspath "$(pwd)/realgitdir" "${newdir_git#gitdir: }" && | |
633734d4 | 416 | test_path_is_dir realgitdir/refs |
b57fb80a NTND |
417 | ' |
418 | ||
4e95fb6c | 419 | test_expect_success SYMLINKS 're-init to move gitdir symlink' ' |
b57fb80a NTND |
420 | rm -rf newdir realgitdir && |
421 | git init newdir && | |
422 | ( | |
423 | cd newdir && | |
424 | mv .git here && | |
425 | ln -s here .git && | |
09ffc706 | 426 | git init --separate-git-dir ../realgitdir |
b57fb80a | 427 | ) && |
88619b3e | 428 | echo "gitdir: $(pwd)/realgitdir" >expected && |
b57fb80a | 429 | test_cmp expected newdir/.git && |
3d06c5f1 | 430 | test_cmp expected newdir/here && |
633734d4 | 431 | test_path_is_dir realgitdir/refs |
b57fb80a NTND |
432 | ' |
433 | ||
59d876cc | 434 | sep_git_dir_worktree () { |
42264bc8 ES |
435 | test_when_finished "rm -rf mainwt linkwt seprepo" && |
436 | git init mainwt && | |
437 | test_commit -C mainwt gumby && | |
438 | git -C mainwt worktree add --detach ../linkwt && | |
59d876cc | 439 | git -C "$1" init --separate-git-dir ../seprepo && |
42264bc8 ES |
440 | git -C mainwt rev-parse --git-common-dir >expect && |
441 | git -C linkwt rev-parse --git-common-dir >actual && | |
442 | test_cmp expect actual | |
59d876cc ES |
443 | } |
444 | ||
445 | test_expect_success 're-init to move gitdir with linked worktrees' ' | |
446 | sep_git_dir_worktree mainwt | |
447 | ' | |
448 | ||
449 | test_expect_success 're-init to move gitdir within linked worktree' ' | |
450 | sep_git_dir_worktree linkwt | |
42264bc8 ES |
451 | ' |
452 | ||
f30afdab JS |
453 | test_expect_success MINGW '.git hidden' ' |
454 | rm -rf newdir && | |
455 | ( | |
ed6c994a | 456 | sane_unset GIT_DIR GIT_WORK_TREE && |
f30afdab JS |
457 | mkdir newdir && |
458 | cd newdir && | |
459 | git init && | |
176a66a7 | 460 | test_path_is_hidden .git |
f30afdab JS |
461 | ) && |
462 | check_config newdir/.git false unset | |
463 | ' | |
464 | ||
465 | test_expect_success MINGW 'bare git dir not hidden' ' | |
466 | rm -rf newdir && | |
467 | ( | |
ed6c994a | 468 | sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && |
f30afdab JS |
469 | mkdir newdir && |
470 | cd newdir && | |
471 | git --bare init | |
472 | ) && | |
473 | ! is_hidden newdir | |
474 | ' | |
475 | ||
b9605bc4 JK |
476 | test_expect_success 'remote init from does not use config from cwd' ' |
477 | rm -rf newdir && | |
478 | test_config core.logallrefupdates true && | |
479 | git init newdir && | |
480 | echo true >expect && | |
481 | git -C newdir config --bool core.logallrefupdates >actual && | |
482 | test_cmp expect actual | |
483 | ' | |
484 | ||
fe9aa0b2 NTND |
485 | test_expect_success 're-init from a linked worktree' ' |
486 | git init main-worktree && | |
487 | ( | |
488 | cd main-worktree && | |
489 | test_commit first && | |
490 | git worktree add ../linked-worktree && | |
491 | mv .git/info/exclude expected-exclude && | |
6311cfaf | 492 | cp .git/config expected-config && |
fe9aa0b2 NTND |
493 | find .git/worktrees -print | sort >expected && |
494 | git -C ../linked-worktree init && | |
495 | test_cmp expected-exclude .git/info/exclude && | |
6311cfaf | 496 | test_cmp expected-config .git/config && |
fe9aa0b2 NTND |
497 | find .git/worktrees -print | sort >actual && |
498 | test_cmp expected actual | |
499 | ) | |
500 | ' | |
501 | ||
eff45daa | 502 | test_expect_success 'init honors GIT_DEFAULT_HASH' ' |
503 | GIT_DEFAULT_HASH=sha1 git init sha1 && | |
504 | git -C sha1 rev-parse --show-object-format >actual && | |
505 | echo sha1 >expected && | |
506 | test_cmp expected actual && | |
507 | GIT_DEFAULT_HASH=sha256 git init sha256 && | |
508 | git -C sha256 rev-parse --show-object-format >actual && | |
509 | echo sha256 >expected && | |
510 | test_cmp expected actual | |
511 | ' | |
512 | ||
513 | test_expect_success 'init honors --object-format' ' | |
514 | git init --object-format=sha1 explicit-sha1 && | |
515 | git -C explicit-sha1 rev-parse --show-object-format >actual && | |
516 | echo sha1 >expected && | |
517 | test_cmp expected actual && | |
518 | git init --object-format=sha256 explicit-sha256 && | |
519 | git -C explicit-sha256 rev-parse --show-object-format >actual && | |
520 | echo sha256 >expected && | |
521 | test_cmp expected actual | |
522 | ' | |
523 | ||
524 | test_expect_success 'extensions.objectFormat is not allowed with repo version 0' ' | |
525 | git init --object-format=sha256 explicit-v0 && | |
526 | git -C explicit-v0 config core.repositoryformatversion 0 && | |
527 | test_must_fail git -C explicit-v0 rev-parse --show-object-format | |
528 | ' | |
529 | ||
530 | test_expect_success 'init rejects attempts to initialize with different hash' ' | |
531 | test_must_fail git -C sha1 init --object-format=sha256 && | |
532 | test_must_fail git -C sha256 init --object-format=sha1 | |
533 | ' | |
534 | ||
d7497a42 PS |
535 | test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage is not allowed with repo version 0' ' |
536 | test_when_finished "rm -rf refstorage" && | |
537 | git init refstorage && | |
538 | git -C refstorage config extensions.refStorage files && | |
539 | test_must_fail git -C refstorage rev-parse 2>err && | |
540 | grep "repo version is 0, but v1-only extension found" err | |
541 | ' | |
542 | ||
543 | test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with files backend' ' | |
544 | test_when_finished "rm -rf refstorage" && | |
545 | git init refstorage && | |
546 | git -C refstorage config core.repositoryformatversion 1 && | |
547 | git -C refstorage config extensions.refStorage files && | |
548 | test_commit -C refstorage A && | |
549 | git -C refstorage rev-parse --verify HEAD | |
550 | ' | |
551 | ||
552 | test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown backend' ' | |
553 | test_when_finished "rm -rf refstorage" && | |
554 | git init refstorage && | |
555 | git -C refstorage config core.repositoryformatversion 1 && | |
556 | git -C refstorage config extensions.refStorage garbage && | |
557 | test_must_fail git -C refstorage rev-parse 2>err && | |
558 | grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err | |
559 | ' | |
560 | ||
aa19619a PS |
561 | test_expect_success DEFAULT_REPO_FORMAT 'init with GIT_DEFAULT_REF_FORMAT=files' ' |
562 | test_when_finished "rm -rf refformat" && | |
563 | GIT_DEFAULT_REF_FORMAT=files git init refformat && | |
564 | echo 0 >expect && | |
565 | git -C refformat config core.repositoryformatversion >actual && | |
566 | test_cmp expect actual && | |
567 | test_must_fail git -C refformat config extensions.refstorage | |
568 | ' | |
569 | ||
570 | test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' ' | |
571 | test_when_finished "rm -rf refformat" && | |
572 | cat >expect <<-EOF && | |
573 | fatal: unknown ref storage format ${SQ}garbage${SQ} | |
574 | EOF | |
575 | test_must_fail env GIT_DEFAULT_REF_FORMAT=garbage git init refformat 2>err && | |
576 | test_cmp expect err | |
577 | ' | |
578 | ||
48fa45f5 PS |
579 | test_expect_success 'init with --ref-format=files' ' |
580 | test_when_finished "rm -rf refformat" && | |
581 | git init --ref-format=files refformat && | |
582 | echo files >expect && | |
583 | git -C refformat rev-parse --show-ref-format >actual && | |
584 | test_cmp expect actual | |
585 | ' | |
586 | ||
587 | test_expect_success 're-init with same format' ' | |
588 | test_when_finished "rm -rf refformat" && | |
589 | git init --ref-format=files refformat && | |
590 | git init --ref-format=files refformat && | |
591 | echo files >expect && | |
592 | git -C refformat rev-parse --show-ref-format >actual && | |
593 | test_cmp expect actual | |
594 | ' | |
595 | ||
596 | test_expect_success 'init with --ref-format=garbage' ' | |
597 | test_when_finished "rm -rf refformat" && | |
598 | cat >expect <<-EOF && | |
599 | fatal: unknown ref storage format ${SQ}garbage${SQ} | |
600 | EOF | |
601 | test_must_fail git init --ref-format=garbage refformat 2>err && | |
602 | test_cmp expect err | |
603 | ' | |
604 | ||
28785339 JS |
605 | test_expect_success MINGW 'core.hidedotfiles = false' ' |
606 | git config --global core.hidedotfiles false && | |
607 | rm -rf newdir && | |
608 | mkdir newdir && | |
609 | ( | |
610 | sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && | |
611 | git -C newdir init | |
612 | ) && | |
613 | ! is_hidden newdir/.git | |
614 | ' | |
615 | ||
3f944424 JS |
616 | test_expect_success MINGW 'redirect std handles' ' |
617 | GIT_REDIRECT_STDOUT=output.txt git rev-parse --git-dir && | |
618 | test .git = "$(cat output.txt)" && | |
1a172e4a JS |
619 | test -z "$(GIT_REDIRECT_STDOUT=off git rev-parse --git-dir)" && |
620 | test_must_fail env \ | |
621 | GIT_REDIRECT_STDOUT=output.txt \ | |
622 | GIT_REDIRECT_STDERR="2>&1" \ | |
623 | git rev-parse --git-dir --verify refs/invalid && | |
fdda1ac6 JS |
624 | grep "^\\.git\$" output.txt && |
625 | grep "Needed a single revision" output.txt | |
3f944424 JS |
626 | ' |
627 | ||
32ba12da JS |
628 | test_expect_success '--initial-branch' ' |
629 | git init --initial-branch=hello initial-branch-option && | |
630 | git -C initial-branch-option symbolic-ref HEAD >actual && | |
631 | echo refs/heads/hello >expect && | |
632 | test_cmp expect actual && | |
633 | ||
634 | : re-initializing should not change the branch name && | |
635 | git init --initial-branch=ignore initial-branch-option 2>err && | |
6789275d | 636 | test_grep "ignored --initial-branch" err && |
32ba12da JS |
637 | git -C initial-branch-option symbolic-ref HEAD >actual && |
638 | grep hello actual | |
639 | ' | |
640 | ||
8747ebb7 DGW |
641 | test_expect_success 'overridden default initial branch name (config)' ' |
642 | test_config_global init.defaultBranch nmb && | |
704fed9e | 643 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git init initial-branch-config && |
8747ebb7 DGW |
644 | git -C initial-branch-config symbolic-ref HEAD >actual && |
645 | grep nmb actual | |
646 | ' | |
647 | ||
675704c7 JS |
648 | test_expect_success 'advice on unconfigured init.defaultBranch' ' |
649 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \ | |
650 | init unconfigured-default-branch-name 2>err && | |
651 | test_decode_color <err >decoded && | |
6789275d | 652 | test_grep "<YELLOW>hint: " decoded |
675704c7 JS |
653 | ' |
654 | ||
704fed9e JS |
655 | test_expect_success 'overridden default main branch name (env)' ' |
656 | test_config_global init.defaultBranch nmb && | |
657 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env && | |
658 | git -C main-branch-env symbolic-ref HEAD >actual && | |
659 | grep env actual | |
660 | ' | |
661 | ||
8747ebb7 | 662 | test_expect_success 'invalid default branch name' ' |
704fed9e JS |
663 | test_must_fail env GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME="with space" \ |
664 | git init initial-branch-invalid 2>err && | |
6789275d | 665 | test_grep "invalid branch name" err |
8747ebb7 DGW |
666 | ' |
667 | ||
cfaff3aa JS |
668 | test_expect_success 'branch -m with the initial branch' ' |
669 | git init rename-initial && | |
670 | git -C rename-initial branch -m renamed && | |
4bd0785d ÆAB |
671 | echo renamed >expect && |
672 | git -C rename-initial symbolic-ref --short HEAD >actual && | |
673 | test_cmp expect actual && | |
674 | ||
cfaff3aa | 675 | git -C rename-initial branch -m renamed again && |
4bd0785d ÆAB |
676 | echo again >expect && |
677 | git -C rename-initial symbolic-ref --short HEAD >actual && | |
678 | test_cmp expect actual | |
cfaff3aa JS |
679 | ' |
680 | ||
6adcca3f | 681 | test_done |