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