Teach diff --submodule and status to handle .git files in submodules
[git/jrn.git] / t / t0001-init.sh
blob5386504790deea55d127f053f7b714cd121a2d57
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 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 with GIT_WORK_TREE' '
37 if (
38 unset GIT_DIR
39 mkdir plain-wt &&
40 cd plain-wt &&
41 GIT_WORK_TREE=$(pwd) git init
43 then
44 echo Should have failed -- GIT_WORK_TREE should not be used
45 false
49 test_expect_success 'plain bare' '
51 unset GIT_DIR GIT_WORK_TREE GIT_CONFIG
52 mkdir plain-bare-1 &&
53 cd plain-bare-1 &&
54 git --bare init
55 ) &&
56 check_config plain-bare-1 true unset
59 test_expect_success 'plain bare with GIT_WORK_TREE' '
60 if (
61 unset GIT_DIR GIT_CONFIG
62 mkdir plain-bare-2 &&
63 cd plain-bare-2 &&
64 GIT_WORK_TREE=$(pwd) git --bare init
66 then
67 echo Should have failed -- GIT_WORK_TREE should not be used
68 false
72 test_expect_success 'GIT_DIR bare' '
75 unset GIT_CONFIG
76 mkdir git-dir-bare.git &&
77 GIT_DIR=git-dir-bare.git git init
78 ) &&
79 check_config git-dir-bare.git true unset
82 test_expect_success 'init --bare' '
85 unset GIT_DIR GIT_WORK_TREE GIT_CONFIG
86 mkdir init-bare.git &&
87 cd init-bare.git &&
88 git init --bare
89 ) &&
90 check_config init-bare.git true unset
93 test_expect_success 'GIT_DIR non-bare' '
96 unset GIT_CONFIG
97 mkdir non-bare &&
98 cd non-bare &&
99 GIT_DIR=.git git init
100 ) &&
101 check_config non-bare/.git false unset
104 test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
107 unset GIT_CONFIG
108 mkdir git-dir-wt-1.git &&
109 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
110 ) &&
111 check_config git-dir-wt-1.git false "$(pwd)"
114 test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
116 if (
117 unset GIT_CONFIG
118 mkdir git-dir-wt-2.git &&
119 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init
121 then
122 echo Should have failed -- --bare should not be used
123 false
127 test_expect_success 'reinit' '
130 unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG
132 mkdir again &&
133 cd again &&
134 git init >out1 2>err1 &&
135 git init >out2 2>err2
136 ) &&
137 grep "Initialized empty" again/out1 &&
138 grep "Reinitialized existing" again/out2 &&
139 >again/empty &&
140 test_cmp again/empty again/err1 &&
141 test_cmp again/empty again/err2
144 test_expect_success 'init with --template' '
145 mkdir template-source &&
146 echo content >template-source/file &&
148 mkdir template-custom &&
149 cd template-custom &&
150 git init --template=../template-source
151 ) &&
152 test_cmp template-source/file template-custom/.git/file
155 test_expect_success 'init with --template (blank)' '
157 mkdir template-plain &&
158 cd template-plain &&
159 git init
160 ) &&
161 test -f template-plain/.git/info/exclude &&
163 mkdir template-blank &&
164 cd template-blank &&
165 git init --template=
166 ) &&
167 ! test -f template-blank/.git/info/exclude
170 test_expect_success 'init --bare/--shared overrides system/global config' '
172 HOME="`pwd`" &&
173 export HOME &&
174 test_config="$HOME"/.gitconfig &&
175 unset GIT_CONFIG_NOGLOBAL &&
176 git config -f "$test_config" core.bare false &&
177 git config -f "$test_config" core.sharedRepository 0640 &&
178 mkdir init-bare-shared-override &&
179 cd init-bare-shared-override &&
180 git init --bare --shared=0666
181 ) &&
182 check_config init-bare-shared-override true unset &&
183 test x0666 = \
184 x`git config -f init-bare-shared-override/config core.sharedRepository`
187 test_expect_success 'init honors global core.sharedRepository' '
189 HOME="`pwd`" &&
190 export HOME &&
191 test_config="$HOME"/.gitconfig &&
192 unset GIT_CONFIG_NOGLOBAL &&
193 git config -f "$test_config" core.sharedRepository 0666 &&
194 mkdir shared-honor-global &&
195 cd shared-honor-global &&
196 git init
197 ) &&
198 test x0666 = \
199 x`git config -f shared-honor-global/.git/config core.sharedRepository`
202 test_expect_success 'init rejects insanely long --template' '
204 insane=$(printf "x%09999dx" 1) &&
205 mkdir test &&
206 cd test &&
207 test_must_fail git init --template=$insane
211 test_expect_success 'init creates a new directory' '
212 rm -fr newdir &&
214 git init newdir &&
215 test -d newdir/.git/refs
219 test_expect_success 'init creates a new bare directory' '
220 rm -fr newdir &&
222 git init --bare newdir &&
223 test -d newdir/refs
227 test_expect_success 'init recreates a directory' '
228 rm -fr newdir &&
230 mkdir newdir &&
231 git init newdir &&
232 test -d newdir/.git/refs
236 test_expect_success 'init recreates a new bare directory' '
237 rm -fr newdir &&
239 mkdir newdir &&
240 git init --bare newdir &&
241 test -d newdir/refs
245 test_expect_success 'init creates a new deep directory' '
246 rm -fr newdir &&
247 git init newdir/a/b/c &&
248 test -d newdir/a/b/c/.git/refs
251 test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' '
252 rm -fr newdir &&
254 # Leading directories should honor umask while
255 # the repository itself should follow "shared"
256 umask 002 &&
257 git init --bare --shared=0660 newdir/a/b/c &&
258 test -d newdir/a/b/c/refs &&
259 ls -ld newdir/a newdir/a/b > lsab.out &&
260 ! grep -v "^drwxrw[sx]r-x" lsab.out &&
261 ls -ld newdir/a/b/c > lsc.out &&
262 ! grep -v "^drwxrw[sx]---" lsc.out
266 test_expect_success 'init notices EEXIST (1)' '
267 rm -fr newdir &&
269 >newdir &&
270 test_must_fail git init newdir &&
271 test -f newdir
275 test_expect_success 'init notices EEXIST (2)' '
276 rm -fr newdir &&
278 mkdir newdir &&
279 >newdir/a
280 test_must_fail git init newdir/a/b &&
281 test -f newdir/a
285 test_expect_success POSIXPERM 'init notices EPERM' '
286 rm -fr newdir &&
288 mkdir newdir &&
289 chmod -w newdir &&
290 test_must_fail git init newdir/a/b
294 test_done