Merge branch 'mr/msvc-link-with-invalidcontinue'
[git/mingw.git] / t / t0001-init.sh
blobbbc9cb60ddea49f1ce3f0b0d124f704c30a61346
1 #!/bin/sh
3 test_description='git init'
5 . ./test-lib.sh
7 check_config () {
8 if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
9 then
10 : happy
11 else
12 echo "expected a directory $1, a file $1/config and $1/refs"
13 return 1
15 bare=$(cd "$1" && git config --bool core.bare)
16 worktree=$(cd "$1" && git config core.worktree) ||
17 worktree=unset
19 test "$bare" = "$2" && test "$worktree" = "$3" || {
20 echo "expected bare=$2 worktree=$3"
21 echo " got bare=$bare worktree=$worktree"
22 return 1
26 test_expect_success 'plain' '
27 git init 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 &&
35 mkdir plain-nested &&
36 cd plain-nested &&
37 git init
38 ) &&
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 &&
45 export HOME &&
46 mkdir alias-config &&
47 echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
49 GIT_CEILING_DIRECTORIES=$(pwd) &&
50 export GIT_CEILING_DIRECTORIES &&
52 mkdir plain-aliased &&
53 cd plain-aliased &&
54 git aliasedinit
55 ) &&
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 &&
64 mkdir plain-nested &&
65 cd plain-nested &&
66 git aliasedinit
67 ) &&
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 &&
76 mkdir plain-nested &&
77 cd plain-nested &&
78 git aliasedinit
79 ) &&
80 check_config bare-ancestor-aliased.git/plain-nested/.git false unset
83 test_expect_success 'plain with GIT_WORK_TREE' '
84 mkdir plain-wt &&
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' '
94 mkdir plain-bare-2 &&
95 test_must_fail \
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' '
114 mkdir non-bare &&
115 cd non-bare &&
116 GIT_DIR=.git git init
117 ) &&
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
126 ) &&
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 &&
132 test_must_fail env \
133 GIT_WORK_TREE="$(pwd)" \
134 GIT_DIR=git-dir-wt-2.git \
135 git --bare init
138 test_expect_success 'reinit' '
141 mkdir again &&
142 cd again &&
143 git init >out1 2>err1 &&
144 git init >out2 2>err2
145 ) &&
146 test_i18ngrep "Initialized empty" again/out1 &&
147 test_i18ngrep "Reinitialized existing" again/out2 &&
148 >again/empty &&
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 &&
177 git init
178 ) &&
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 &&
187 test x0666 = \
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 &&
194 test x0666 = \
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' '
203 rm -fr newdir &&
204 git init newdir &&
205 test_path_is_dir newdir/.git/refs
208 test_expect_success 'init creates a new bare directory' '
209 rm -fr newdir &&
210 git init --bare newdir &&
211 test_path_is_dir newdir/refs
214 test_expect_success 'init recreates a directory' '
215 rm -fr newdir &&
216 mkdir newdir &&
217 git init newdir &&
218 test_path_is_dir newdir/.git/refs
221 test_expect_success 'init recreates a new bare directory' '
222 rm -fr newdir &&
223 mkdir newdir &&
224 git init --bare newdir &&
225 test_path_is_dir newdir/refs
228 test_expect_success 'init creates a new deep directory' '
229 rm -fr newdir &&
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)' '
235 rm -fr newdir &&
237 # Leading directories should honor umask while
238 # the repository itself should follow "shared"
239 umask 002 &&
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)' '
250 rm -fr newdir &&
251 >newdir &&
252 test_must_fail git init newdir &&
253 test_path_is_file newdir
256 test_expect_success 'init notices EEXIST (2)' '
257 rm -fr newdir &&
258 mkdir newdir &&
259 >newdir/a &&
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' '
265 rm -fr newdir &&
266 mkdir newdir &&
267 chmod -w newdir &&
268 test_must_fail git init newdir/a/b
271 test_expect_success 'init creates a new bare directory with global --bare' '
272 rm -rf newdir &&
273 git --bare init newdir &&
274 test_path_is_dir newdir/refs
277 test_expect_success 'init prefers command line to GIT_DIR' '
278 rm -rf newdir &&
279 mkdir otherdir &&
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' '
286 rm -rf newdir &&
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' '
299 cd newdir &&
300 git init --separate-git-dir ../surrealgitdir
301 ) &&
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 &&
310 git init newdir &&
312 cd newdir &&
313 git init --separate-git-dir ../realgitdir
314 ) &&
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 &&
322 git init newdir &&
324 cd newdir &&
325 mv .git here &&
326 ln -s here .git &&
327 git init --separate-git-dir ../realgitdir
328 ) &&
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
335 test_done