t0001: drop useless subshells
[git/jrn.git] / t / t0001-init.sh
blobd8c00b44cc8275daffa84af1f6487407eb029c15
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=$(cd "$1" && git config --bool core.bare)
16 worktree=$(cd "$1" && 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 mkdir plain &&
29 cd plain &&
30 git init
31 ) &&
32 check_config plain/.git false unset
35 test_expect_success 'plain nested in bare' '
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
46 test_expect_success 'plain through aliased command, outside any git repo' '
48 HOME=$(pwd)/alias-config &&
49 export HOME &&
50 mkdir alias-config &&
51 echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
53 GIT_CEILING_DIRECTORIES=$(pwd) &&
54 export GIT_CEILING_DIRECTORIES &&
56 mkdir plain-aliased &&
57 cd plain-aliased &&
58 git aliasedinit
59 ) &&
60 check_config plain-aliased/.git false unset
63 test_expect_failure 'plain nested through aliased command' '
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
75 test_expect_failure 'plain nested in bare through aliased command' '
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
87 test_expect_success 'plain with GIT_WORK_TREE' '
88 mkdir plain-wt &&
89 test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt
92 test_expect_success 'plain bare' '
94 mkdir plain-bare-1 &&
95 cd plain-bare-1 &&
96 git --bare init
97 ) &&
98 check_config plain-bare-1 true unset
101 test_expect_success 'plain bare with GIT_WORK_TREE' '
102 mkdir plain-bare-2 &&
103 test_must_fail \
104 env GIT_WORK_TREE="$(pwd)/plain-bare-2" \
105 git --bare init plain-bare-2
108 test_expect_success 'GIT_DIR bare' '
109 mkdir git-dir-bare.git &&
110 GIT_DIR=git-dir-bare.git git init &&
111 check_config git-dir-bare.git true unset
114 test_expect_success 'init --bare' '
117 mkdir init-bare.git &&
118 cd init-bare.git &&
119 git init --bare
120 ) &&
121 check_config init-bare.git true unset
124 test_expect_success 'GIT_DIR non-bare' '
127 mkdir non-bare &&
128 cd non-bare &&
129 GIT_DIR=.git git init
130 ) &&
131 check_config non-bare/.git false unset
134 test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
137 mkdir git-dir-wt-1.git &&
138 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
139 ) &&
140 check_config git-dir-wt-1.git false "$(pwd)"
143 test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
144 mkdir git-dir-wt-2.git &&
145 test_must_fail env \
146 GIT_WORK_TREE="$(pwd)" \
147 GIT_DIR=git-dir-wt-2.git \
148 git --bare init
151 test_expect_success 'reinit' '
154 mkdir again &&
155 cd again &&
156 git init >out1 2>err1 &&
157 git init >out2 2>err2
158 ) &&
159 test_i18ngrep "Initialized empty" again/out1 &&
160 test_i18ngrep "Reinitialized existing" again/out2 &&
161 >again/empty &&
162 test_i18ncmp again/empty again/err1 &&
163 test_i18ncmp again/empty again/err2
166 test_expect_success 'init with --template' '
167 mkdir template-source &&
168 echo content >template-source/file &&
170 mkdir template-custom &&
171 cd template-custom &&
172 git init --template=../template-source
173 ) &&
174 test_cmp template-source/file template-custom/.git/file
177 test_expect_success 'init with --template (blank)' '
179 mkdir template-plain &&
180 cd template-plain &&
181 git init
182 ) &&
183 test_path_is_file template-plain/.git/info/exclude &&
185 mkdir template-blank &&
186 cd template-blank &&
187 git init --template=
188 ) &&
189 test_path_is_missing template-blank/.git/info/exclude
192 test_expect_success 'init with init.templatedir set' '
193 mkdir templatedir-source &&
194 echo Content >templatedir-source/file &&
195 test_config_global init.templatedir "${HOME}/templatedir-source" &&
197 mkdir templatedir-set &&
198 cd templatedir-set &&
199 sane_unset GIT_TEMPLATE_DIR &&
200 NO_SET_GIT_TEMPLATE_DIR=t &&
201 export NO_SET_GIT_TEMPLATE_DIR &&
202 git init
203 ) &&
204 test_cmp templatedir-source/file templatedir-set/.git/file
207 test_expect_success 'init --bare/--shared overrides system/global config' '
208 test_config_global core.bare false &&
209 test_config_global core.sharedRepository 0640 &&
211 mkdir init-bare-shared-override &&
212 cd init-bare-shared-override &&
213 git init --bare --shared=0666
214 ) &&
215 check_config init-bare-shared-override true unset &&
216 test x0666 = \
217 x`git config -f init-bare-shared-override/config core.sharedRepository`
220 test_expect_success 'init honors global core.sharedRepository' '
221 test_config_global core.sharedRepository 0666 &&
223 mkdir shared-honor-global &&
224 cd shared-honor-global &&
225 git init
226 ) &&
227 test x0666 = \
228 x`git config -f shared-honor-global/.git/config core.sharedRepository`
231 test_expect_success 'init rejects insanely long --template' '
233 insane=$(printf "x%09999dx" 1) &&
234 mkdir test &&
235 cd test &&
236 test_must_fail git init --template=$insane
240 test_expect_success 'init creates a new directory' '
241 rm -fr newdir &&
242 git init newdir &&
243 test_path_is_dir newdir/.git/refs
246 test_expect_success 'init creates a new bare directory' '
247 rm -fr newdir &&
248 git init --bare newdir &&
249 test_path_is_dir newdir/refs
252 test_expect_success 'init recreates a directory' '
253 rm -fr newdir &&
254 mkdir newdir &&
255 git init newdir &&
256 test_path_is_dir newdir/.git/refs
259 test_expect_success 'init recreates a new bare directory' '
260 rm -fr newdir &&
261 mkdir newdir &&
262 git init --bare newdir &&
263 test_path_is_dir newdir/refs
266 test_expect_success 'init creates a new deep directory' '
267 rm -fr newdir &&
268 git init newdir/a/b/c &&
269 test_path_is_dir newdir/a/b/c/.git/refs
272 test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' '
273 rm -fr newdir &&
275 # Leading directories should honor umask while
276 # the repository itself should follow "shared"
277 umask 002 &&
278 git init --bare --shared=0660 newdir/a/b/c &&
279 test_path_is_dir newdir/a/b/c/refs &&
280 ls -ld newdir/a newdir/a/b > lsab.out &&
281 ! grep -v "^drwxrw[sx]r-x" lsab.out &&
282 ls -ld newdir/a/b/c > lsc.out &&
283 ! grep -v "^drwxrw[sx]---" lsc.out
287 test_expect_success 'init notices EEXIST (1)' '
288 rm -fr newdir &&
289 >newdir &&
290 test_must_fail git init newdir &&
291 test_path_is_file newdir
294 test_expect_success 'init notices EEXIST (2)' '
295 rm -fr newdir &&
296 mkdir newdir &&
297 >newdir/a &&
298 test_must_fail git init newdir/a/b &&
299 test_path_is_file newdir/a
302 test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
303 rm -fr newdir &&
304 mkdir newdir &&
305 chmod -w newdir &&
306 test_must_fail git init newdir/a/b
309 test_expect_success 'init creates a new bare directory with global --bare' '
310 rm -rf newdir &&
311 git --bare init newdir &&
312 test_path_is_dir newdir/refs
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 &&
319 test_path_is_dir newdir/refs &&
320 test_path_is_missing otherdir/refs
323 test_expect_success 'init with separate gitdir' '
324 rm -rf newdir &&
325 git init --separate-git-dir realgitdir newdir &&
326 echo "gitdir: `pwd`/realgitdir" >expected &&
327 test_cmp expected newdir/.git &&
328 test_path_is_dir realgitdir/refs
331 test_expect_success 're-init on .git file' '
332 ( cd newdir && git init )
335 test_expect_success 're-init to update git link' '
337 cd newdir &&
338 git init --separate-git-dir ../surrealgitdir
339 ) &&
340 echo "gitdir: `pwd`/surrealgitdir" >expected &&
341 test_cmp expected newdir/.git &&
342 test_path_is_dir surrealgitdir/refs &&
343 test_path_is_missing realgitdir/refs
346 test_expect_success 're-init to move gitdir' '
347 rm -rf newdir realgitdir surrealgitdir &&
348 git init newdir &&
350 cd newdir &&
351 git init --separate-git-dir ../realgitdir
352 ) &&
353 echo "gitdir: `pwd`/realgitdir" >expected &&
354 test_cmp expected newdir/.git &&
355 test_path_is_dir realgitdir/refs
358 test_expect_success SYMLINKS 're-init to move gitdir symlink' '
359 rm -rf newdir realgitdir &&
360 git init newdir &&
362 cd newdir &&
363 mv .git here &&
364 ln -s here .git &&
365 git init --separate-git-dir ../realgitdir
366 ) &&
367 echo "gitdir: `pwd`/realgitdir" >expected &&
368 test_cmp expected newdir/.git &&
369 test_cmp expected newdir/here &&
370 test_path_is_dir realgitdir/refs
373 test_done