]>
Commit | Line | Data |
---|---|---|
6adcca3f JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git init' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
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 | |
14 | fi | |
15 | bare=$(GIT_CONFIG="$1/config" git config --bool core.bare) | |
16 | worktree=$(GIT_CONFIG="$1/config" git config core.worktree) || | |
17 | worktree=unset | |
18 | ||
19 | test "$bare" = "$2" && test "$worktree" = "$3" || { | |
20 | echo "expected bare=$2 worktree=$3" | |
21 | echo " got bare=$bare worktree=$worktree" | |
22 | return 1 | |
23 | } | |
24 | } | |
25 | ||
26 | test_expect_success 'plain' ' | |
27 | ( | |
51884080 | 28 | unset GIT_DIR GIT_WORK_TREE |
6adcca3f JH |
29 | mkdir plain && |
30 | cd plain && | |
31 | git init | |
32 | ) && | |
33 | check_config plain/.git false unset | |
34 | ' | |
35 | ||
36 | test_expect_success 'plain with GIT_WORK_TREE' ' | |
37 | if ( | |
51884080 | 38 | unset GIT_DIR |
6adcca3f JH |
39 | mkdir plain-wt && |
40 | cd plain-wt && | |
41 | GIT_WORK_TREE=$(pwd) git init | |
42 | ) | |
43 | then | |
44 | echo Should have failed -- GIT_WORK_TREE should not be used | |
45 | false | |
46 | fi | |
47 | ' | |
48 | ||
49 | test_expect_success 'plain bare' ' | |
50 | ( | |
51884080 | 51 | unset GIT_DIR GIT_WORK_TREE GIT_CONFIG |
6adcca3f JH |
52 | mkdir plain-bare-1 && |
53 | cd plain-bare-1 && | |
54 | git --bare init | |
55 | ) && | |
56 | check_config plain-bare-1 true unset | |
57 | ' | |
58 | ||
59 | test_expect_success 'plain bare with GIT_WORK_TREE' ' | |
60 | if ( | |
51884080 | 61 | unset GIT_DIR GIT_CONFIG |
6adcca3f JH |
62 | mkdir plain-bare-2 && |
63 | cd plain-bare-2 && | |
64 | GIT_WORK_TREE=$(pwd) git --bare init | |
65 | ) | |
66 | then | |
67 | echo Should have failed -- GIT_WORK_TREE should not be used | |
68 | false | |
69 | fi | |
70 | ' | |
71 | ||
72 | test_expect_success 'GIT_DIR bare' ' | |
73 | ||
74 | ( | |
51884080 | 75 | unset GIT_CONFIG |
6adcca3f JH |
76 | mkdir git-dir-bare.git && |
77 | GIT_DIR=git-dir-bare.git git init | |
78 | ) && | |
79 | check_config git-dir-bare.git true unset | |
80 | ' | |
81 | ||
74d3b23f LR |
82 | test_expect_success 'init --bare' ' |
83 | ||
84 | ( | |
85 | unset GIT_DIR GIT_WORK_TREE GIT_CONFIG | |
b6138273 MV |
86 | mkdir init-bare.git && |
87 | cd init-bare.git && | |
74d3b23f LR |
88 | git init --bare |
89 | ) && | |
b6138273 | 90 | check_config init-bare.git true unset |
74d3b23f LR |
91 | ' |
92 | ||
6adcca3f JH |
93 | test_expect_success 'GIT_DIR non-bare' ' |
94 | ||
95 | ( | |
51884080 | 96 | unset GIT_CONFIG |
6adcca3f JH |
97 | mkdir non-bare && |
98 | cd non-bare && | |
99 | GIT_DIR=.git git init | |
100 | ) && | |
101 | check_config non-bare/.git false unset | |
102 | ' | |
103 | ||
104 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' | |
105 | ||
106 | ( | |
51884080 | 107 | unset GIT_CONFIG |
6adcca3f JH |
108 | mkdir git-dir-wt-1.git && |
109 | GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init | |
110 | ) && | |
111 | check_config git-dir-wt-1.git false "$(pwd)" | |
112 | ' | |
113 | ||
114 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' | |
115 | ||
116 | if ( | |
51884080 | 117 | unset GIT_CONFIG |
6adcca3f JH |
118 | mkdir git-dir-wt-2.git && |
119 | GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init | |
120 | ) | |
121 | then | |
122 | echo Should have failed -- --bare should not be used | |
123 | false | |
124 | fi | |
125 | ' | |
126 | ||
5cc8f372 JS |
127 | test_expect_success 'reinit' ' |
128 | ||
129 | ( | |
130 | unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG | |
131 | ||
132 | mkdir again && | |
133 | cd again && | |
134 | git init >out1 2>err1 && | |
135 | git init >out2 2>err2 | |
136 | ) && | |
137 | grep "Initialized empty" again/out1 && | |
138 | grep "Reinitialized existing" again/out2 && | |
139 | >again/empty && | |
140 | test_cmp again/empty again/err1 && | |
141 | test_cmp again/empty again/err2 | |
142 | ' | |
143 | ||
172035f0 JK |
144 | test_expect_success 'init with --template' ' |
145 | mkdir template-source && | |
146 | echo content >template-source/file && | |
147 | ( | |
148 | mkdir template-custom && | |
149 | cd template-custom && | |
150 | git init --template=../template-source | |
151 | ) && | |
152 | test_cmp template-source/file template-custom/.git/file | |
153 | ' | |
154 | ||
155 | test_expect_success 'init with --template (blank)' ' | |
156 | ( | |
157 | mkdir template-plain && | |
158 | cd template-plain && | |
159 | git init | |
160 | ) && | |
161 | test -f template-plain/.git/info/exclude && | |
162 | ( | |
163 | mkdir template-blank && | |
164 | cd template-blank && | |
165 | git init --template= | |
166 | ) && | |
167 | ! test -f template-blank/.git/info/exclude | |
168 | ' | |
169 | ||
a94d305b SD |
170 | test_expect_success 'init with init.templatedir set' ' |
171 | mkdir templatedir-source && | |
172 | echo Content >templatedir-source/file && | |
173 | ( | |
a94d305b SD |
174 | test_config="${HOME}/.gitconfig" && |
175 | git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" && | |
176 | mkdir templatedir-set && | |
177 | cd templatedir-set && | |
178 | unset GIT_CONFIG_NOGLOBAL && | |
179 | unset GIT_TEMPLATE_DIR && | |
180 | NO_SET_GIT_TEMPLATE_DIR=t && | |
181 | export NO_SET_GIT_TEMPLATE_DIR && | |
182 | git init | |
183 | ) && | |
184 | test_cmp templatedir-source/file templatedir-set/.git/file | |
185 | ' | |
186 | ||
0a2c7eea DM |
187 | test_expect_success 'init --bare/--shared overrides system/global config' ' |
188 | ( | |
0a2c7eea DM |
189 | test_config="$HOME"/.gitconfig && |
190 | unset GIT_CONFIG_NOGLOBAL && | |
191 | git config -f "$test_config" core.bare false && | |
192 | git config -f "$test_config" core.sharedRepository 0640 && | |
193 | mkdir init-bare-shared-override && | |
194 | cd init-bare-shared-override && | |
195 | git init --bare --shared=0666 | |
196 | ) && | |
197 | check_config init-bare-shared-override true unset && | |
198 | test x0666 = \ | |
199 | x`git config -f init-bare-shared-override/config core.sharedRepository` | |
200 | ' | |
201 | ||
202 | test_expect_success 'init honors global core.sharedRepository' ' | |
203 | ( | |
0a2c7eea DM |
204 | test_config="$HOME"/.gitconfig && |
205 | unset GIT_CONFIG_NOGLOBAL && | |
206 | git config -f "$test_config" core.sharedRepository 0666 && | |
207 | mkdir shared-honor-global && | |
208 | cd shared-honor-global && | |
209 | git init | |
210 | ) && | |
211 | test x0666 = \ | |
212 | x`git config -f shared-honor-global/.git/config core.sharedRepository` | |
213 | ' | |
214 | ||
32d1776b FL |
215 | test_expect_success 'init rejects insanely long --template' ' |
216 | ( | |
217 | insane=$(printf "x%09999dx" 1) && | |
218 | mkdir test && | |
219 | cd test && | |
220 | test_must_fail git init --template=$insane | |
221 | ) | |
222 | ' | |
223 | ||
53d48885 NS |
224 | test_expect_success 'init creates a new directory' ' |
225 | rm -fr newdir && | |
226 | ( | |
227 | git init newdir && | |
228 | test -d newdir/.git/refs | |
229 | ) | |
230 | ' | |
231 | ||
232 | test_expect_success 'init creates a new bare directory' ' | |
233 | rm -fr newdir && | |
234 | ( | |
235 | git init --bare newdir && | |
236 | test -d newdir/refs | |
237 | ) | |
238 | ' | |
239 | ||
240 | test_expect_success 'init recreates a directory' ' | |
241 | rm -fr newdir && | |
242 | ( | |
243 | mkdir newdir && | |
244 | git init newdir && | |
245 | test -d newdir/.git/refs | |
246 | ) | |
247 | ' | |
248 | ||
249 | test_expect_success 'init recreates a new bare directory' ' | |
250 | rm -fr newdir && | |
251 | ( | |
252 | mkdir newdir && | |
253 | git init --bare newdir && | |
254 | test -d newdir/refs | |
255 | ) | |
256 | ' | |
257 | ||
258 | test_expect_success 'init creates a new deep directory' ' | |
d82e75e8 JS |
259 | rm -fr newdir && |
260 | git init newdir/a/b/c && | |
261 | test -d newdir/a/b/c/.git/refs | |
262 | ' | |
263 | ||
264 | test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' ' | |
53d48885 NS |
265 | rm -fr newdir && |
266 | ( | |
267 | # Leading directories should honor umask while | |
268 | # the repository itself should follow "shared" | |
269 | umask 002 && | |
270 | git init --bare --shared=0660 newdir/a/b/c && | |
271 | test -d newdir/a/b/c/refs && | |
272 | ls -ld newdir/a newdir/a/b > lsab.out && | |
7d53a07a | 273 | ! grep -v "^drwxrw[sx]r-x" lsab.out && |
53d48885 NS |
274 | ls -ld newdir/a/b/c > lsc.out && |
275 | ! grep -v "^drwxrw[sx]---" lsc.out | |
276 | ) | |
277 | ' | |
278 | ||
279 | test_expect_success 'init notices EEXIST (1)' ' | |
280 | rm -fr newdir && | |
281 | ( | |
282 | >newdir && | |
283 | test_must_fail git init newdir && | |
284 | test -f newdir | |
285 | ) | |
286 | ' | |
287 | ||
288 | test_expect_success 'init notices EEXIST (2)' ' | |
289 | rm -fr newdir && | |
290 | ( | |
291 | mkdir newdir && | |
292 | >newdir/a | |
293 | test_must_fail git init newdir/a/b && | |
294 | test -f newdir/a | |
295 | ) | |
296 | ' | |
297 | ||
c91cfd19 | 298 | test_expect_success POSIXPERM,SANITY 'init notices EPERM' ' |
53d48885 NS |
299 | rm -fr newdir && |
300 | ( | |
301 | mkdir newdir && | |
302 | chmod -w newdir && | |
303 | test_must_fail git init newdir/a/b | |
304 | ) | |
305 | ' | |
306 | ||
87a074df JK |
307 | test_expect_success 'init creates a new bare directory with global --bare' ' |
308 | rm -rf newdir && | |
309 | git --bare init newdir && | |
310 | test -d newdir/refs | |
311 | ' | |
312 | ||
313 | test_expect_success 'init prefers command line to GIT_DIR' ' | |
314 | rm -rf newdir && | |
315 | mkdir otherdir && | |
316 | GIT_DIR=otherdir git --bare init newdir && | |
317 | test -d newdir/refs && | |
318 | ! test -d otherdir/refs | |
319 | ' | |
320 | ||
6adcca3f | 321 | test_done |