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' '
28 check_config plain/.git false unset
31 test_expect_success 'plain nested in bare' '
33 git init --bare bare-ancestor.git &&
34 cd bare-ancestor.git &&
39 check_config bare-ancestor.git/plain-nested/.git false unset
42 test_expect_success 'plain through aliased command, outside any git repo' '
44 HOME=$(pwd)/alias-config &&
47 echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
49 GIT_CEILING_DIRECTORIES=$(pwd) &&
50 export GIT_CEILING_DIRECTORIES &&
52 mkdir plain-aliased &&
56 check_config plain-aliased/.git false unset
59 test_expect_failure 'plain nested through aliased command' '
61 git init plain-ancestor-aliased &&
62 cd plain-ancestor-aliased &&
63 echo "[alias] aliasedinit = init" >>.git/config &&
68 check_config plain-ancestor-aliased/plain-nested/.git false unset
71 test_expect_failure 'plain nested in bare through aliased command' '
73 git init --bare bare-ancestor-aliased.git &&
74 cd bare-ancestor-aliased.git &&
75 echo "[alias] aliasedinit = init" >>config &&
80 check_config bare-ancestor-aliased.git/plain-nested/.git false unset
83 test_expect_success 'plain with GIT_WORK_TREE' '
85 test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt
88 test_expect_success 'plain bare' '
89 git --bare init plain-bare-1 &&
90 check_config plain-bare-1 true unset
93 test_expect_success 'plain bare with GIT_WORK_TREE' '
96 env GIT_WORK_TREE="$(pwd)/plain-bare-2" \
97 git --bare init plain-bare-2
100 test_expect_success 'GIT_DIR bare' '
101 mkdir git-dir-bare.git &&
102 GIT_DIR=git-dir-bare.git git init &&
103 check_config git-dir-bare.git true unset
106 test_expect_success 'init --bare' '
107 git init --bare init-bare.git &&
108 check_config init-bare.git true unset
111 test_expect_success 'GIT_DIR non-bare' '
116 GIT_DIR=.git git init
118 check_config non-bare/.git false unset
121 test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
124 mkdir git-dir-wt-1.git &&
125 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
127 check_config git-dir-wt-1.git false "$(pwd)"
130 test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
131 mkdir git-dir-wt-2.git &&
133 GIT_WORK_TREE="$(pwd)" \
134 GIT_DIR=git-dir-wt-2.git \
138 test_expect_success 'reinit' '
143 git init >out1 2>err1 &&
144 git init >out2 2>err2
146 test_i18ngrep "Initialized empty" again/out1 &&
147 test_i18ngrep "Reinitialized existing" again/out2 &&
149 test_i18ncmp again/empty again/err1 &&
150 test_i18ncmp again/empty again/err2
153 test_expect_success 'init with --template' '
154 mkdir template-source &&
155 echo content >template-source/file &&
156 git init --template=../template-source template-custom &&
157 test_cmp template-source/file template-custom/.git/file
160 test_expect_success 'init with --template (blank)' '
161 git init template-plain &&
162 test_path_is_file template-plain/.git/info/exclude &&
163 git init --template= template-blank &&
164 test_path_is_missing template-blank/.git/info/exclude
167 test_expect_success 'init with init.templatedir set' '
168 mkdir templatedir-source &&
169 echo Content >templatedir-source/file &&
170 test_config_global init.templatedir "${HOME}/templatedir-source" &&
172 mkdir templatedir-set &&
173 cd templatedir-set &&
174 sane_unset GIT_TEMPLATE_DIR &&
175 NO_SET_GIT_TEMPLATE_DIR=t &&
176 export NO_SET_GIT_TEMPLATE_DIR &&
179 test_cmp templatedir-source/file templatedir-set/.git/file
182 test_expect_success 'init --bare/--shared overrides system/global config' '
183 test_config_global core.bare false &&
184 test_config_global core.sharedRepository 0640 &&
185 git init --bare --shared=0666 init-bare-shared-override &&
186 check_config init-bare-shared-override true unset &&
188 x`git config -f init-bare-shared-override/config core.sharedRepository`
191 test_expect_success 'init honors global core.sharedRepository' '
192 test_config_global core.sharedRepository 0666 &&
193 git init shared-honor-global &&
195 x`git config -f shared-honor-global/.git/config core.sharedRepository`
198 test_expect_success 'init rejects insanely long --template' '
199 test_must_fail git init --template=$(printf "x%09999dx" 1) test
202 test_expect_success 'init creates a new directory' '
205 test_path_is_dir newdir/.git/refs
208 test_expect_success 'init creates a new bare directory' '
210 git init --bare newdir &&
211 test_path_is_dir newdir/refs
214 test_expect_success 'init recreates a directory' '
218 test_path_is_dir newdir/.git/refs
221 test_expect_success 'init recreates a new bare directory' '
224 git init --bare newdir &&
225 test_path_is_dir newdir/refs
228 test_expect_success 'init creates a new deep directory' '
230 git init newdir/a/b/c &&
231 test_path_is_dir newdir/a/b/c/.git/refs
234 test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' '
237 # Leading directories should honor umask while
238 # the repository itself should follow "shared"
240 git init --bare --shared=0660 newdir/a/b/c &&
241 test_path_is_dir newdir/a/b/c/refs &&
242 ls -ld newdir/a newdir/a/b > lsab.out &&
243 ! grep -v "^drwxrw[sx]r-x" lsab.out &&
244 ls -ld newdir/a/b/c > lsc.out &&
245 ! grep -v "^drwxrw[sx]---" lsc.out
249 test_expect_success 'init notices EEXIST (1)' '
252 test_must_fail git init newdir &&
253 test_path_is_file newdir
256 test_expect_success 'init notices EEXIST (2)' '
260 test_must_fail git init newdir/a/b &&
261 test_path_is_file newdir/a
264 test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
268 test_must_fail git init newdir/a/b
271 test_expect_success 'init creates a new bare directory with global --bare' '
273 git --bare init newdir &&
274 test_path_is_dir newdir/refs
277 test_expect_success 'init prefers command line to GIT_DIR' '
280 GIT_DIR=otherdir git --bare init newdir &&
281 test_path_is_dir newdir/refs &&
282 test_path_is_missing otherdir/refs
285 test_expect_success 'init with separate gitdir' '
287 git init --separate-git-dir realgitdir newdir &&
288 echo "gitdir: `pwd`/realgitdir" >expected &&
289 test_cmp expected newdir/.git &&
290 test_path_is_dir realgitdir/refs
293 test_expect_success 're-init on .git file' '
294 ( cd newdir && git init )
297 test_expect_success 're-init to update git link' '
300 git init --separate-git-dir ../surrealgitdir
302 echo "gitdir: `pwd`/surrealgitdir" >expected &&
303 test_cmp expected newdir/.git &&
304 test_path_is_dir surrealgitdir/refs &&
305 test_path_is_missing realgitdir/refs
308 test_expect_success 're-init to move gitdir' '
309 rm -rf newdir realgitdir surrealgitdir &&
313 git init --separate-git-dir ../realgitdir
315 echo "gitdir: `pwd`/realgitdir" >expected &&
316 test_cmp expected newdir/.git &&
317 test_path_is_dir realgitdir/refs
320 test_expect_success SYMLINKS 're-init to move gitdir symlink' '
321 rm -rf newdir realgitdir &&
327 git init --separate-git-dir ../realgitdir
329 echo "gitdir: `pwd`/realgitdir" >expected &&
330 test_cmp expected newdir/.git &&
331 test_cmp expected newdir/here &&
332 test_path_is_dir realgitdir/refs