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"
16 if test_have_prereq POSIXPERM
&& test -x "$1/config"
18 echo "$1/config is executable?"
22 bare
=$
(cd "$1" && git config
--bool core.bare
)
23 worktree
=$
(cd "$1" && git config core.worktree
) ||
26 test "$bare" = "$2" && test "$worktree" = "$3" ||
{
27 echo "expected bare=$2 worktree=$3"
28 echo " got bare=$bare worktree=$worktree"
33 test_expect_success
'plain' '
35 check_config plain/.git false unset
38 test_expect_success
'plain nested in bare' '
40 git init --bare bare-ancestor.git &&
41 cd bare-ancestor.git &&
46 check_config bare-ancestor.git/plain-nested/.git false unset
49 test_expect_success
'plain through aliased command, outside any git repo' '
51 HOME=$(pwd)/alias-config &&
54 echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
56 GIT_CEILING_DIRECTORIES=$(pwd) &&
57 export GIT_CEILING_DIRECTORIES &&
59 mkdir plain-aliased &&
63 check_config plain-aliased/.git false unset
66 test_expect_success
'plain nested through aliased command' '
68 git init plain-ancestor-aliased &&
69 cd plain-ancestor-aliased &&
70 echo "[alias] aliasedinit = init" >>.git/config &&
75 check_config plain-ancestor-aliased/plain-nested/.git false unset
78 test_expect_success
'plain nested in bare through aliased command' '
80 git init --bare bare-ancestor-aliased.git &&
81 cd bare-ancestor-aliased.git &&
82 echo "[alias] aliasedinit = init" >>config &&
87 check_config bare-ancestor-aliased.git/plain-nested/.git false unset
90 test_expect_success
'plain with GIT_WORK_TREE' '
92 test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt
95 test_expect_success
'plain bare' '
96 git --bare init plain-bare-1 &&
97 check_config plain-bare-1 true unset
100 test_expect_success
'plain bare with GIT_WORK_TREE' '
101 mkdir plain-bare-2 &&
103 env GIT_WORK_TREE="$(pwd)/plain-bare-2" \
104 git --bare init plain-bare-2
107 test_expect_success
'GIT_DIR bare' '
108 mkdir git-dir-bare.git &&
109 GIT_DIR=git-dir-bare.git git init &&
110 check_config git-dir-bare.git true unset
113 test_expect_success
'init --bare' '
114 git init --bare init-bare.git &&
115 check_config init-bare.git true unset
118 test_expect_success
'GIT_DIR non-bare' '
123 GIT_DIR=.git git init
125 check_config non-bare/.git false unset
128 test_expect_success
'GIT_DIR & GIT_WORK_TREE (1)' '
131 mkdir git-dir-wt-1.git &&
132 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
134 check_config git-dir-wt-1.git false "$(pwd)"
137 test_expect_success
'GIT_DIR & GIT_WORK_TREE (2)' '
138 mkdir git-dir-wt-2.git &&
140 GIT_WORK_TREE="$(pwd)" \
141 GIT_DIR=git-dir-wt-2.git \
145 test_expect_success
'reinit' '
150 git init >out1 2>err1 &&
151 git init >out2 2>err2
153 test_i18ngrep "Initialized empty" again/out1 &&
154 test_i18ngrep "Reinitialized existing" again/out2 &&
156 test_i18ncmp again/empty again/err1 &&
157 test_i18ncmp again/empty again/err2
160 test_expect_success
'init with --template' '
161 mkdir template-source &&
162 echo content >template-source/file &&
163 git init --template=../template-source template-custom &&
164 test_cmp template-source/file template-custom/.git/file
167 test_expect_success
'init with --template (blank)' '
168 git init template-plain &&
169 test_path_is_file template-plain/.git/info/exclude &&
170 git init --template= template-blank &&
171 test_path_is_missing template-blank/.git/info/exclude
174 test_expect_success
'init with init.templatedir set' '
175 mkdir templatedir-source &&
176 echo Content >templatedir-source/file &&
177 test_config_global init.templatedir "${HOME}/templatedir-source" &&
179 mkdir templatedir-set &&
180 cd templatedir-set &&
181 sane_unset GIT_TEMPLATE_DIR &&
182 NO_SET_GIT_TEMPLATE_DIR=t &&
183 export NO_SET_GIT_TEMPLATE_DIR &&
186 test_cmp templatedir-source/file templatedir-set/.git/file
189 test_expect_success
'init --bare/--shared overrides system/global config' '
190 test_config_global core.bare false &&
191 test_config_global core.sharedRepository 0640 &&
192 git init --bare --shared=0666 init-bare-shared-override &&
193 check_config init-bare-shared-override true unset &&
195 x$(git config -f init-bare-shared-override/config core.sharedRepository)
198 test_expect_success
'init honors global core.sharedRepository' '
199 test_config_global core.sharedRepository 0666 &&
200 git init shared-honor-global &&
202 x$(git config -f shared-honor-global/.git/config core.sharedRepository)
205 test_expect_success
'init rejects insanely long --template' '
206 test_must_fail git init --template=$(printf "x%09999dx" 1) test
209 test_expect_success
'init creates a new directory' '
212 test_path_is_dir newdir/.git/refs
215 test_expect_success
'init creates a new bare directory' '
217 git init --bare newdir &&
218 test_path_is_dir newdir/refs
221 test_expect_success
'init recreates a directory' '
225 test_path_is_dir newdir/.git/refs
228 test_expect_success
'init recreates a new bare directory' '
231 git init --bare newdir &&
232 test_path_is_dir newdir/refs
235 test_expect_success
'init creates a new deep directory' '
237 git init newdir/a/b/c &&
238 test_path_is_dir newdir/a/b/c/.git/refs
241 test_expect_success POSIXPERM
'init creates a new deep directory (umask vs. shared)' '
244 # Leading directories should honor umask while
245 # the repository itself should follow "shared"
247 git init --bare --shared=0660 newdir/a/b/c &&
248 test_path_is_dir newdir/a/b/c/refs &&
249 ls -ld newdir/a newdir/a/b > lsab.out &&
250 ! grep -v "^drwxrw[sx]r-x" lsab.out &&
251 ls -ld newdir/a/b/c > lsc.out &&
252 ! grep -v "^drwxrw[sx]---" lsc.out
256 test_expect_success
'init notices EEXIST (1)' '
259 test_must_fail git init newdir &&
260 test_path_is_file newdir
263 test_expect_success
'init notices EEXIST (2)' '
267 test_must_fail git init newdir/a/b &&
268 test_path_is_file newdir/a
271 test_expect_success POSIXPERM
,SANITY
'init notices EPERM' '
275 test_must_fail git init newdir/a/b
278 test_expect_success
'init creates a new bare directory with global --bare' '
280 git --bare init newdir &&
281 test_path_is_dir newdir/refs
284 test_expect_success
'init prefers command line to GIT_DIR' '
287 GIT_DIR=otherdir git --bare init newdir &&
288 test_path_is_dir newdir/refs &&
289 test_path_is_missing otherdir/refs
292 test_expect_success
'init with separate gitdir' '
294 git init --separate-git-dir realgitdir newdir &&
295 echo "gitdir: $(pwd)/realgitdir" >expected &&
296 test_cmp expected newdir/.git &&
297 test_path_is_dir realgitdir/refs
300 test_expect_success
're-init on .git file' '
301 ( cd newdir && git init )
304 test_expect_success
're-init to update git link' '
307 git init --separate-git-dir ../surrealgitdir
309 echo "gitdir: $(pwd)/surrealgitdir" >expected &&
310 test_cmp expected newdir/.git &&
311 test_path_is_dir surrealgitdir/refs &&
312 test_path_is_missing realgitdir/refs
315 test_expect_success
're-init to move gitdir' '
316 rm -rf newdir realgitdir surrealgitdir &&
320 git init --separate-git-dir ../realgitdir
322 echo "gitdir: $(pwd)/realgitdir" >expected &&
323 test_cmp expected newdir/.git &&
324 test_path_is_dir realgitdir/refs
327 test_expect_success SYMLINKS
're-init to move gitdir symlink' '
328 rm -rf newdir realgitdir &&
334 git init --separate-git-dir ../realgitdir
336 echo "gitdir: $(pwd)/realgitdir" >expected &&
337 test_cmp expected newdir/.git &&
338 test_cmp expected newdir/here &&
339 test_path_is_dir realgitdir/refs