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=$(cd "$1" && git config --bool core.bare)
16 worktree=$(cd "$1" && 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' '
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 &&
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 &&
51 echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
53 GIT_CEILING_DIRECTORIES=$(pwd) &&
54 export GIT_CEILING_DIRECTORIES &&
56 mkdir plain-aliased &&
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 &&
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 &&
84 check_config bare-ancestor-aliased.git/plain-nested/.git false unset
87 test_expect_success 'plain with GIT_WORK_TREE' '
91 GIT_WORK_TREE=$(pwd) git init
94 echo Should have failed -- GIT_WORK_TREE should not be used
99 test_expect_success 'plain bare' '
101 mkdir plain-bare-1 &&
105 check_config plain-bare-1 true unset
108 test_expect_success 'plain bare with GIT_WORK_TREE' '
110 mkdir plain-bare-2 &&
112 GIT_WORK_TREE=$(pwd) git --bare init
115 echo Should have failed -- GIT_WORK_TREE should not be used
120 test_expect_success 'GIT_DIR bare' '
123 mkdir git-dir-bare.git &&
124 GIT_DIR=git-dir-bare.git git init
126 check_config git-dir-bare.git true unset
129 test_expect_success 'init --bare' '
132 mkdir init-bare.git &&
136 check_config init-bare.git true unset
139 test_expect_success 'GIT_DIR non-bare' '
144 GIT_DIR=.git git init
146 check_config non-bare/.git false unset
149 test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
152 mkdir git-dir-wt-1.git &&
153 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
155 check_config git-dir-wt-1.git false "$(pwd)"
158 test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
161 mkdir git-dir-wt-2.git &&
162 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init
165 echo Should have failed -- --bare should not be used
170 test_expect_success 'reinit' '
175 git init >out1 2>err1 &&
176 git init >out2 2>err2
178 test_i18ngrep "Initialized empty" again/out1 &&
179 test_i18ngrep "Reinitialized existing" again/out2 &&
181 test_i18ncmp again/empty again/err1 &&
182 test_i18ncmp again/empty again/err2
185 test_expect_success 'init with --template' '
186 mkdir template-source &&
187 echo content >template-source/file &&
189 mkdir template-custom &&
190 cd template-custom &&
191 git init --template=../template-source
193 test_cmp template-source/file template-custom/.git/file
196 test_expect_success 'init with --template (blank)' '
198 mkdir template-plain &&
202 test_path_is_file template-plain/.git/info/exclude &&
204 mkdir template-blank &&
208 test_path_is_missing template-blank/.git/info/exclude
211 test_expect_success 'init with init.templatedir set' '
212 mkdir templatedir-source &&
213 echo Content >templatedir-source/file &&
215 test_config="${HOME}/.gitconfig" &&
216 git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" &&
217 mkdir templatedir-set &&
218 cd templatedir-set &&
219 sane_unset GIT_TEMPLATE_DIR &&
220 NO_SET_GIT_TEMPLATE_DIR=t &&
221 export NO_SET_GIT_TEMPLATE_DIR &&
224 test_cmp templatedir-source/file templatedir-set/.git/file
227 test_expect_success 'init --bare/--shared overrides system/global config' '
229 test_config="$HOME"/.gitconfig &&
230 git config -f "$test_config" core.bare false &&
231 git config -f "$test_config" core.sharedRepository 0640 &&
232 mkdir init-bare-shared-override &&
233 cd init-bare-shared-override &&
234 git init --bare --shared=0666
236 check_config init-bare-shared-override true unset &&
238 x`git config -f init-bare-shared-override/config core.sharedRepository`
241 test_expect_success 'init honors global core.sharedRepository' '
243 test_config="$HOME"/.gitconfig &&
244 git config -f "$test_config" core.sharedRepository 0666 &&
245 mkdir shared-honor-global &&
246 cd shared-honor-global &&
250 x`git config -f shared-honor-global/.git/config core.sharedRepository`
253 test_expect_success 'init rejects insanely long --template' '
255 insane=$(printf "x%09999dx" 1) &&
258 test_must_fail git init --template=$insane
262 test_expect_success 'init creates a new directory' '
266 test_path_is_dir newdir/.git/refs
270 test_expect_success 'init creates a new bare directory' '
273 git init --bare newdir &&
274 test_path_is_dir newdir/refs
278 test_expect_success 'init recreates a directory' '
283 test_path_is_dir newdir/.git/refs
287 test_expect_success 'init recreates a new bare directory' '
291 git init --bare newdir &&
292 test_path_is_dir newdir/refs
296 test_expect_success 'init creates a new deep directory' '
298 git init newdir/a/b/c &&
299 test_path_is_dir newdir/a/b/c/.git/refs
302 test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' '
305 # Leading directories should honor umask while
306 # the repository itself should follow "shared"
308 git init --bare --shared=0660 newdir/a/b/c &&
309 test_path_is_dir newdir/a/b/c/refs &&
310 ls -ld newdir/a newdir/a/b > lsab.out &&
311 ! grep -v "^drwxrw[sx]r-x" lsab.out &&
312 ls -ld newdir/a/b/c > lsc.out &&
313 ! grep -v "^drwxrw[sx]---" lsc.out
317 test_expect_success 'init notices EEXIST (1)' '
321 test_must_fail git init newdir &&
322 test_path_is_file newdir
326 test_expect_success 'init notices EEXIST (2)' '
331 test_must_fail git init newdir/a/b &&
332 test_path_is_file newdir/a
336 test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
341 test_must_fail git init newdir/a/b
345 test_expect_success 'init creates a new bare directory with global --bare' '
347 git --bare init newdir &&
348 test_path_is_dir newdir/refs
351 test_expect_success 'init prefers command line to GIT_DIR' '
354 GIT_DIR=otherdir git --bare init newdir &&
355 test_path_is_dir newdir/refs &&
356 test_path_is_missing otherdir/refs
359 test_expect_success 'init with separate gitdir' '
361 git init --separate-git-dir realgitdir newdir &&
362 echo "gitdir: `pwd`/realgitdir" >expected &&
363 test_cmp expected newdir/.git &&
364 test_path_is_dir realgitdir/refs
367 test_expect_success 're-init on .git file' '
368 ( cd newdir && git init )
371 test_expect_success 're-init to update git link' '
374 git init --separate-git-dir ../surrealgitdir
376 echo "gitdir: `pwd`/surrealgitdir" >expected &&
377 test_cmp expected newdir/.git &&
378 test_path_is_dir surrealgitdir/refs &&
379 test_path_is_missing realgitdir/refs
382 test_expect_success 're-init to move gitdir' '
383 rm -rf newdir realgitdir surrealgitdir &&
387 git init --separate-git-dir ../realgitdir
389 echo "gitdir: `pwd`/realgitdir" >expected &&
390 test_cmp expected newdir/.git &&
391 test_path_is_dir realgitdir/refs
394 test_expect_success SYMLINKS 're-init to move gitdir symlink' '
395 rm -rf newdir realgitdir &&
401 git init --separate-git-dir ../realgitdir
403 echo "gitdir: `pwd`/realgitdir" >expected &&
404 test_cmp expected newdir/.git &&
405 test_cmp expected newdir/here &&
406 test_path_is_dir realgitdir/refs