3 test_description='git init'
8 if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
12 echo "expected a directory $1, a file $1/config and $1/refs"
15 bare=$(GIT_CONFIG="$1/config" git config --bool core.bare)
16 worktree=$(GIT_CONFIG="$1/config" git config core.worktree) ||
19 test "$bare" = "$2" && test "$worktree" = "$3" || {
20 echo "expected bare=$2 worktree=$3"
21 echo " got bare=$bare worktree=$worktree"
26 test_expect_success 'plain' '
28 sane_unset GIT_DIR GIT_WORK_TREE &&
33 check_config plain/.git false unset
36 test_expect_success 'plain with GIT_WORK_TREE' '
41 GIT_WORK_TREE=$(pwd) git init
44 echo Should have failed -- GIT_WORK_TREE should not be used
49 test_expect_success 'plain bare' '
51 sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
56 check_config plain-bare-1 true unset
59 test_expect_success 'plain bare with GIT_WORK_TREE' '
61 sane_unset GIT_DIR GIT_CONFIG &&
64 GIT_WORK_TREE=$(pwd) git --bare init
67 echo Should have failed -- GIT_WORK_TREE should not be used
72 test_expect_success 'GIT_DIR bare' '
75 sane_unset GIT_CONFIG &&
76 mkdir git-dir-bare.git &&
77 GIT_DIR=git-dir-bare.git git init
79 check_config git-dir-bare.git true unset
82 test_expect_success 'init --bare' '
85 sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
86 mkdir init-bare.git &&
90 check_config init-bare.git true unset
93 test_expect_success 'GIT_DIR non-bare' '
96 sane_unset GIT_CONFIG &&
101 check_config non-bare/.git false unset
104 test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
107 sane_unset GIT_CONFIG &&
108 mkdir git-dir-wt-1.git &&
109 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
111 check_config git-dir-wt-1.git false "$(pwd)"
114 test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
117 sane_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
122 echo Should have failed -- --bare should not be used
127 test_expect_success 'reinit' '
130 sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG &&
134 git init >out1 2>err1 &&
135 git init >out2 2>err2
137 grep "Initialized empty" again/out1 &&
138 grep "Reinitialized existing" again/out2 &&
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
152 test_cmp template-source/file template-custom/.git/file
155 test_expect_success 'init with --template (blank)' '
157 mkdir template-plain &&
161 test -f template-plain/.git/info/exclude &&
163 mkdir template-blank &&
167 ! test -f template-blank/.git/info/exclude
170 test_expect_success 'init with init.templatedir set' '
171 mkdir templatedir-source &&
172 echo Content >templatedir-source/file &&
174 test_config="${HOME}/.gitconfig" &&
175 git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" &&
176 mkdir templatedir-set &&
177 cd templatedir-set &&
178 sane_unset GIT_CONFIG_NOGLOBAL &&
179 sane_unset GIT_TEMPLATE_DIR &&
180 NO_SET_GIT_TEMPLATE_DIR=t &&
181 export NO_SET_GIT_TEMPLATE_DIR &&
184 test_cmp templatedir-source/file templatedir-set/.git/file
187 test_expect_success 'init --bare/--shared overrides system/global config' '
189 test_config="$HOME"/.gitconfig &&
190 sane_unset GIT_CONFIG_NOGLOBAL &&
191 git config -f "$test_config" core.bare false &&
192 git config -f "$test_config" core.sharedRepository 0640 &&
193 mkdir init-bare-shared-override &&
194 cd init-bare-shared-override &&
195 git init --bare --shared=0666
197 check_config init-bare-shared-override true unset &&
199 x`git config -f init-bare-shared-override/config core.sharedRepository`
202 test_expect_success 'init honors global core.sharedRepository' '
204 test_config="$HOME"/.gitconfig &&
205 sane_unset GIT_CONFIG_NOGLOBAL &&
206 git config -f "$test_config" core.sharedRepository 0666 &&
207 mkdir shared-honor-global &&
208 cd shared-honor-global &&
212 x`git config -f shared-honor-global/.git/config core.sharedRepository`
215 test_expect_success 'init rejects insanely long --template' '
217 insane=$(printf "x%09999dx" 1) &&
220 test_must_fail git init --template=$insane
224 test_expect_success 'init creates a new directory' '
228 test -d newdir/.git/refs
232 test_expect_success 'init creates a new bare directory' '
235 git init --bare newdir &&
240 test_expect_success 'init recreates a directory' '
245 test -d newdir/.git/refs
249 test_expect_success 'init recreates a new bare directory' '
253 git init --bare newdir &&
258 test_expect_success 'init creates a new deep directory' '
260 git init newdir/a/b/c &&
261 test -d newdir/a/b/c/.git/refs
264 test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' '
267 # Leading directories should honor umask while
268 # the repository itself should follow "shared"
270 git init --bare --shared=0660 newdir/a/b/c &&
271 test -d newdir/a/b/c/refs &&
272 ls -ld newdir/a newdir/a/b > lsab.out &&
273 ! grep -v "^drwxrw[sx]r-x" lsab.out &&
274 ls -ld newdir/a/b/c > lsc.out &&
275 ! grep -v "^drwxrw[sx]---" lsc.out
279 test_expect_success 'init notices EEXIST (1)' '
283 test_must_fail git init newdir &&
288 test_expect_success 'init notices EEXIST (2)' '
293 test_must_fail git init newdir/a/b &&
298 test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
303 test_must_fail git init newdir/a/b
307 test_expect_success 'init creates a new bare directory with global --bare' '
309 git --bare init newdir &&
313 test_expect_success 'init prefers command line to GIT_DIR' '
316 GIT_DIR=otherdir git --bare init newdir &&
317 test -d newdir/refs &&
318 ! test -d otherdir/refs