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' '
89 test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt
92 test_expect_success
'plain bare' '
98 check_config plain-bare-1 true unset
101 test_expect_success
'plain bare with GIT_WORK_TREE' '
102 mkdir plain-bare-2 &&
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 &&
121 check_config init-bare.git true unset
124 test_expect_success
'GIT_DIR non-bare' '
129 GIT_DIR=.git git init
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
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 &&
146 GIT_WORK_TREE="$(pwd)" \
147 GIT_DIR=git-dir-wt-2.git \
151 test_expect_success
'reinit' '
156 git init >out1 2>err1 &&
157 git init >out2 2>err2
159 test_i18ngrep "Initialized empty" again/out1 &&
160 test_i18ngrep "Reinitialized existing" again/out2 &&
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
174 test_cmp template-source/file template-custom/.git/file
177 test_expect_success
'init with --template (blank)' '
179 mkdir template-plain &&
183 test_path_is_file template-plain/.git/info/exclude &&
185 mkdir template-blank &&
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 &&
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
215 check_config init-bare-shared-override true unset &&
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 &&
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) &&
236 test_must_fail git init --template=$insane
240 test_expect_success
'init creates a new directory' '
243 test_path_is_dir newdir/.git/refs
246 test_expect_success
'init creates a new bare directory' '
248 git init --bare newdir &&
249 test_path_is_dir newdir/refs
252 test_expect_success
'init recreates a directory' '
256 test_path_is_dir newdir/.git/refs
259 test_expect_success
'init recreates a new bare directory' '
262 git init --bare newdir &&
263 test_path_is_dir newdir/refs
266 test_expect_success
'init creates a new deep directory' '
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)' '
275 # Leading directories should honor umask while
276 # the repository itself should follow "shared"
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)' '
290 test_must_fail git init newdir &&
291 test_path_is_file newdir
294 test_expect_success
'init notices EEXIST (2)' '
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' '
306 test_must_fail git init newdir/a/b
309 test_expect_success
'init creates a new bare directory with global --bare' '
311 git --bare init newdir &&
312 test_path_is_dir newdir/refs
315 test_expect_success
'init prefers command line to GIT_DIR' '
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' '
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' '
338 git init --separate-git-dir ../surrealgitdir
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 &&
351 git init --separate-git-dir ../realgitdir
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 &&
365 git init --separate-git-dir ../realgitdir
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