Make <identifier> lowercase as per CodingGuidelines
[git/dkf.git] / t / t0001-init.sh
blobf6849932112f1bbea1dafad09150857a707b64e4
1 #!/bin/sh
3 test_description='git init'
5 . ./test-lib.sh
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
15 bare=$(GIT_CONFIG="$1/config" git config --bool core.bare)
16 worktree=$(GIT_CONFIG="$1/config" git config core.worktree) ||
17 worktree=unset
19 test "$bare" = "$2" && test "$worktree" = "$3" || {
20 echo "expected bare=$2 worktree=$3"
21 echo " got bare=$bare worktree=$worktree"
22 return 1
26 test_expect_success 'plain' '
28 sane_unset GIT_DIR GIT_WORK_TREE &&
29 mkdir plain &&
30 cd plain &&
31 git init
32 ) &&
33 check_config plain/.git false unset
36 test_expect_success 'plain nested in bare' '
38 sane_unset GIT_DIR GIT_WORK_TREE &&
39 git init --bare bare-ancestor.git &&
40 cd bare-ancestor.git &&
41 mkdir plain-nested &&
42 cd plain-nested &&
43 git init
44 ) &&
45 check_config bare-ancestor.git/plain-nested/.git false unset
48 test_expect_success 'plain through aliased command, outside any git repo' '
50 sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG_NOGLOBAL &&
51 HOME=$(pwd)/alias-config &&
52 export HOME &&
53 mkdir alias-config &&
54 echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
56 GIT_CEILING_DIRECTORIES=$(pwd) &&
57 export GIT_CEILING_DIRECTORIES &&
59 mkdir plain-aliased &&
60 cd plain-aliased &&
61 git aliasedinit
62 ) &&
63 check_config plain-aliased/.git false unset
66 test_expect_failure 'plain nested through aliased command' '
68 sane_unset GIT_DIR GIT_WORK_TREE &&
69 git init plain-ancestor-aliased &&
70 cd plain-ancestor-aliased &&
71 echo "[alias] aliasedinit = init" >>.git/config &&
72 mkdir plain-nested &&
73 cd plain-nested &&
74 git aliasedinit
75 ) &&
76 check_config plain-ancestor-aliased/plain-nested/.git false unset
79 test_expect_failure 'plain nested in bare through aliased command' '
81 sane_unset GIT_DIR GIT_WORK_TREE &&
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
92 test_expect_success 'plain with GIT_WORK_TREE' '
93 if (
94 sane_unset GIT_DIR &&
95 mkdir plain-wt &&
96 cd plain-wt &&
97 GIT_WORK_TREE=$(pwd) git init
99 then
100 echo Should have failed -- GIT_WORK_TREE should not be used
101 false
105 test_expect_success 'plain bare' '
107 sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
108 mkdir plain-bare-1 &&
109 cd plain-bare-1 &&
110 git --bare init
111 ) &&
112 check_config plain-bare-1 true unset
115 test_expect_success 'plain bare with GIT_WORK_TREE' '
116 if (
117 sane_unset GIT_DIR GIT_CONFIG &&
118 mkdir plain-bare-2 &&
119 cd plain-bare-2 &&
120 GIT_WORK_TREE=$(pwd) git --bare init
122 then
123 echo Should have failed -- GIT_WORK_TREE should not be used
124 false
128 test_expect_success 'GIT_DIR bare' '
131 sane_unset GIT_CONFIG &&
132 mkdir git-dir-bare.git &&
133 GIT_DIR=git-dir-bare.git git init
134 ) &&
135 check_config git-dir-bare.git true unset
138 test_expect_success 'init --bare' '
141 sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
142 mkdir init-bare.git &&
143 cd init-bare.git &&
144 git init --bare
145 ) &&
146 check_config init-bare.git true unset
149 test_expect_success 'GIT_DIR non-bare' '
152 sane_unset GIT_CONFIG &&
153 mkdir non-bare &&
154 cd non-bare &&
155 GIT_DIR=.git git init
156 ) &&
157 check_config non-bare/.git false unset
160 test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
163 sane_unset GIT_CONFIG &&
164 mkdir git-dir-wt-1.git &&
165 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
166 ) &&
167 check_config git-dir-wt-1.git false "$(pwd)"
170 test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
172 if (
173 sane_unset GIT_CONFIG &&
174 mkdir git-dir-wt-2.git &&
175 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init
177 then
178 echo Should have failed -- --bare should not be used
179 false
183 test_expect_success 'reinit' '
186 sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG &&
188 mkdir again &&
189 cd again &&
190 git init >out1 2>err1 &&
191 git init >out2 2>err2
192 ) &&
193 grep "Initialized empty" again/out1 &&
194 grep "Reinitialized existing" again/out2 &&
195 >again/empty &&
196 test_cmp again/empty again/err1 &&
197 test_cmp again/empty again/err2
200 test_expect_success 'init with --template' '
201 mkdir template-source &&
202 echo content >template-source/file &&
204 mkdir template-custom &&
205 cd template-custom &&
206 git init --template=../template-source
207 ) &&
208 test_cmp template-source/file template-custom/.git/file
211 test_expect_success 'init with --template (blank)' '
213 mkdir template-plain &&
214 cd template-plain &&
215 git init
216 ) &&
217 test -f template-plain/.git/info/exclude &&
219 mkdir template-blank &&
220 cd template-blank &&
221 git init --template=
222 ) &&
223 ! test -f template-blank/.git/info/exclude
226 test_expect_success 'init with init.templatedir set' '
227 mkdir templatedir-source &&
228 echo Content >templatedir-source/file &&
230 test_config="${HOME}/.gitconfig" &&
231 git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" &&
232 mkdir templatedir-set &&
233 cd templatedir-set &&
234 sane_unset GIT_CONFIG_NOGLOBAL &&
235 sane_unset GIT_TEMPLATE_DIR &&
236 NO_SET_GIT_TEMPLATE_DIR=t &&
237 export NO_SET_GIT_TEMPLATE_DIR &&
238 git init
239 ) &&
240 test_cmp templatedir-source/file templatedir-set/.git/file
243 test_expect_success 'init --bare/--shared overrides system/global config' '
245 test_config="$HOME"/.gitconfig &&
246 sane_unset GIT_CONFIG_NOGLOBAL &&
247 git config -f "$test_config" core.bare false &&
248 git config -f "$test_config" core.sharedRepository 0640 &&
249 mkdir init-bare-shared-override &&
250 cd init-bare-shared-override &&
251 git init --bare --shared=0666
252 ) &&
253 check_config init-bare-shared-override true unset &&
254 test x0666 = \
255 x`git config -f init-bare-shared-override/config core.sharedRepository`
258 test_expect_success 'init honors global core.sharedRepository' '
260 test_config="$HOME"/.gitconfig &&
261 sane_unset GIT_CONFIG_NOGLOBAL &&
262 git config -f "$test_config" core.sharedRepository 0666 &&
263 mkdir shared-honor-global &&
264 cd shared-honor-global &&
265 git init
266 ) &&
267 test x0666 = \
268 x`git config -f shared-honor-global/.git/config core.sharedRepository`
271 test_expect_success 'init rejects insanely long --template' '
273 insane=$(printf "x%09999dx" 1) &&
274 mkdir test &&
275 cd test &&
276 test_must_fail git init --template=$insane
280 test_expect_success 'init creates a new directory' '
281 rm -fr newdir &&
283 git init newdir &&
284 test -d newdir/.git/refs
288 test_expect_success 'init creates a new bare directory' '
289 rm -fr newdir &&
291 git init --bare newdir &&
292 test -d newdir/refs
296 test_expect_success 'init recreates a directory' '
297 rm -fr newdir &&
299 mkdir newdir &&
300 git init newdir &&
301 test -d newdir/.git/refs
305 test_expect_success 'init recreates a new bare directory' '
306 rm -fr newdir &&
308 mkdir newdir &&
309 git init --bare newdir &&
310 test -d newdir/refs
314 test_expect_success 'init creates a new deep directory' '
315 rm -fr newdir &&
316 git init newdir/a/b/c &&
317 test -d newdir/a/b/c/.git/refs
320 test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' '
321 rm -fr newdir &&
323 # Leading directories should honor umask while
324 # the repository itself should follow "shared"
325 umask 002 &&
326 git init --bare --shared=0660 newdir/a/b/c &&
327 test -d newdir/a/b/c/refs &&
328 ls -ld newdir/a newdir/a/b > lsab.out &&
329 ! grep -v "^drwxrw[sx]r-x" lsab.out &&
330 ls -ld newdir/a/b/c > lsc.out &&
331 ! grep -v "^drwxrw[sx]---" lsc.out
335 test_expect_success 'init notices EEXIST (1)' '
336 rm -fr newdir &&
338 >newdir &&
339 test_must_fail git init newdir &&
340 test -f newdir
344 test_expect_success 'init notices EEXIST (2)' '
345 rm -fr newdir &&
347 mkdir newdir &&
348 >newdir/a
349 test_must_fail git init newdir/a/b &&
350 test -f newdir/a
354 test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
355 rm -fr newdir &&
357 mkdir newdir &&
358 chmod -w newdir &&
359 test_must_fail git init newdir/a/b
363 test_expect_success 'init creates a new bare directory with global --bare' '
364 rm -rf newdir &&
365 git --bare init newdir &&
366 test -d newdir/refs
369 test_expect_success 'init prefers command line to GIT_DIR' '
370 rm -rf newdir &&
371 mkdir otherdir &&
372 GIT_DIR=otherdir git --bare init newdir &&
373 test -d newdir/refs &&
374 ! test -d otherdir/refs
377 test_done