]>
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 | |
3cc6a6f0 JK |
15 | bare=$(cd "$1" && git config --bool core.bare) |
16 | worktree=$(cd "$1" && git config core.worktree) || | |
6adcca3f JH |
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' ' | |
410c3428 | 27 | git init plain && |
6adcca3f JH |
28 | check_config plain/.git false unset |
29 | ' | |
30 | ||
4ad8332e JN |
31 | test_expect_success 'plain nested in bare' ' |
32 | ( | |
4ad8332e JN |
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 | |
40 | ' | |
41 | ||
42 | test_expect_success 'plain through aliased command, outside any git repo' ' | |
43 | ( | |
4ad8332e JN |
44 | HOME=$(pwd)/alias-config && |
45 | export HOME && | |
46 | mkdir alias-config && | |
47 | echo "[alias] aliasedinit = init" >alias-config/.gitconfig && | |
48 | ||
49 | GIT_CEILING_DIRECTORIES=$(pwd) && | |
50 | export GIT_CEILING_DIRECTORIES && | |
51 | ||
52 | mkdir plain-aliased && | |
53 | cd plain-aliased && | |
54 | git aliasedinit | |
55 | ) && | |
56 | check_config plain-aliased/.git false unset | |
57 | ' | |
58 | ||
c0562611 | 59 | test_expect_success 'plain nested through aliased command' ' |
4ad8332e | 60 | ( |
4ad8332e JN |
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 | |
69 | ' | |
70 | ||
c0562611 | 71 | test_expect_success 'plain nested in bare through aliased command' ' |
4ad8332e | 72 | ( |
4ad8332e JN |
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 | |
6adcca3f JH |
81 | ' |
82 | ||
83 | test_expect_success 'plain with GIT_WORK_TREE' ' | |
0981140f JK |
84 | mkdir plain-wt && |
85 | test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt | |
6adcca3f JH |
86 | ' |
87 | ||
88 | test_expect_success 'plain bare' ' | |
410c3428 | 89 | git --bare init plain-bare-1 && |
6adcca3f JH |
90 | check_config plain-bare-1 true unset |
91 | ' | |
92 | ||
93 | test_expect_success 'plain bare with GIT_WORK_TREE' ' | |
0981140f JK |
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 | |
6adcca3f JH |
98 | ' |
99 | ||
100 | test_expect_success 'GIT_DIR bare' ' | |
99e1c736 JK |
101 | mkdir git-dir-bare.git && |
102 | GIT_DIR=git-dir-bare.git git init && | |
6adcca3f JH |
103 | check_config git-dir-bare.git true unset |
104 | ' | |
105 | ||
74d3b23f | 106 | test_expect_success 'init --bare' ' |
410c3428 | 107 | git init --bare init-bare.git && |
b6138273 | 108 | check_config init-bare.git true unset |
74d3b23f LR |
109 | ' |
110 | ||
6adcca3f JH |
111 | test_expect_success 'GIT_DIR non-bare' ' |
112 | ||
113 | ( | |
6adcca3f JH |
114 | mkdir non-bare && |
115 | cd non-bare && | |
116 | GIT_DIR=.git git init | |
117 | ) && | |
118 | check_config non-bare/.git false unset | |
119 | ' | |
120 | ||
121 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' | |
122 | ||
123 | ( | |
6adcca3f JH |
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)" | |
128 | ' | |
129 | ||
130 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' | |
0981140f JK |
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 | |
6adcca3f JH |
136 | ' |
137 | ||
127df8c6 | 138 | test_expect_success 'reinit' ' |
5cc8f372 JS |
139 | |
140 | ( | |
5cc8f372 JS |
141 | mkdir again && |
142 | cd again && | |
143 | git init >out1 2>err1 && | |
144 | git init >out2 2>err2 | |
145 | ) && | |
127df8c6 JH |
146 | test_i18ngrep "Initialized empty" again/out1 && |
147 | test_i18ngrep "Reinitialized existing" again/out2 && | |
5cc8f372 | 148 | >again/empty && |
127df8c6 JH |
149 | test_i18ncmp again/empty again/err1 && |
150 | test_i18ncmp again/empty again/err2 | |
5cc8f372 JS |
151 | ' |
152 | ||
172035f0 JK |
153 | test_expect_success 'init with --template' ' |
154 | mkdir template-source && | |
155 | echo content >template-source/file && | |
410c3428 | 156 | git init --template=../template-source template-custom && |
172035f0 JK |
157 | test_cmp template-source/file template-custom/.git/file |
158 | ' | |
159 | ||
160 | test_expect_success 'init with --template (blank)' ' | |
410c3428 | 161 | git init template-plain && |
633734d4 | 162 | test_path_is_file template-plain/.git/info/exclude && |
410c3428 | 163 | git init --template= template-blank && |
633734d4 | 164 | test_path_is_missing template-blank/.git/info/exclude |
172035f0 JK |
165 | ' |
166 | ||
a94d305b SD |
167 | test_expect_success 'init with init.templatedir set' ' |
168 | mkdir templatedir-source && | |
169 | echo Content >templatedir-source/file && | |
2a472410 | 170 | test_config_global init.templatedir "${HOME}/templatedir-source" && |
a94d305b | 171 | ( |
a94d305b SD |
172 | mkdir templatedir-set && |
173 | cd templatedir-set && | |
00648ba0 | 174 | sane_unset GIT_TEMPLATE_DIR && |
a94d305b SD |
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 | |
180 | ' | |
181 | ||
0a2c7eea | 182 | test_expect_success 'init --bare/--shared overrides system/global config' ' |
2a472410 JK |
183 | test_config_global core.bare false && |
184 | test_config_global core.sharedRepository 0640 && | |
410c3428 | 185 | git init --bare --shared=0666 init-bare-shared-override && |
0a2c7eea DM |
186 | check_config init-bare-shared-override true unset && |
187 | test x0666 = \ | |
88619b3e | 188 | x$(git config -f init-bare-shared-override/config core.sharedRepository) |
0a2c7eea DM |
189 | ' |
190 | ||
191 | test_expect_success 'init honors global core.sharedRepository' ' | |
2a472410 | 192 | test_config_global core.sharedRepository 0666 && |
410c3428 | 193 | git init shared-honor-global && |
0a2c7eea | 194 | test x0666 = \ |
88619b3e | 195 | x$(git config -f shared-honor-global/.git/config core.sharedRepository) |
0a2c7eea DM |
196 | ' |
197 | ||
32d1776b | 198 | test_expect_success 'init rejects insanely long --template' ' |
410c3428 | 199 | test_must_fail git init --template=$(printf "x%09999dx" 1) test |
32d1776b FL |
200 | ' |
201 | ||
53d48885 NS |
202 | test_expect_success 'init creates a new directory' ' |
203 | rm -fr newdir && | |
99e1c736 JK |
204 | git init newdir && |
205 | test_path_is_dir newdir/.git/refs | |
53d48885 NS |
206 | ' |
207 | ||
208 | test_expect_success 'init creates a new bare directory' ' | |
209 | rm -fr newdir && | |
99e1c736 JK |
210 | git init --bare newdir && |
211 | test_path_is_dir newdir/refs | |
53d48885 NS |
212 | ' |
213 | ||
214 | test_expect_success 'init recreates a directory' ' | |
215 | rm -fr newdir && | |
99e1c736 JK |
216 | mkdir newdir && |
217 | git init newdir && | |
218 | test_path_is_dir newdir/.git/refs | |
53d48885 NS |
219 | ' |
220 | ||
221 | test_expect_success 'init recreates a new bare directory' ' | |
222 | rm -fr newdir && | |
99e1c736 JK |
223 | mkdir newdir && |
224 | git init --bare newdir && | |
225 | test_path_is_dir newdir/refs | |
53d48885 NS |
226 | ' |
227 | ||
228 | test_expect_success 'init creates a new deep directory' ' | |
d82e75e8 JS |
229 | rm -fr newdir && |
230 | git init newdir/a/b/c && | |
633734d4 | 231 | test_path_is_dir newdir/a/b/c/.git/refs |
d82e75e8 JS |
232 | ' |
233 | ||
234 | test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' ' | |
53d48885 NS |
235 | rm -fr newdir && |
236 | ( | |
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 && | |
633734d4 | 241 | test_path_is_dir newdir/a/b/c/refs && |
53d48885 | 242 | ls -ld newdir/a newdir/a/b > lsab.out && |
7d53a07a | 243 | ! grep -v "^drwxrw[sx]r-x" lsab.out && |
53d48885 NS |
244 | ls -ld newdir/a/b/c > lsc.out && |
245 | ! grep -v "^drwxrw[sx]---" lsc.out | |
246 | ) | |
247 | ' | |
248 | ||
249 | test_expect_success 'init notices EEXIST (1)' ' | |
250 | rm -fr newdir && | |
99e1c736 JK |
251 | >newdir && |
252 | test_must_fail git init newdir && | |
253 | test_path_is_file newdir | |
53d48885 NS |
254 | ' |
255 | ||
256 | test_expect_success 'init notices EEXIST (2)' ' | |
257 | rm -fr newdir && | |
99e1c736 JK |
258 | mkdir newdir && |
259 | >newdir/a && | |
260 | test_must_fail git init newdir/a/b && | |
261 | test_path_is_file newdir/a | |
53d48885 NS |
262 | ' |
263 | ||
c91cfd19 | 264 | test_expect_success POSIXPERM,SANITY 'init notices EPERM' ' |
53d48885 | 265 | rm -fr newdir && |
99e1c736 JK |
266 | mkdir newdir && |
267 | chmod -w newdir && | |
268 | test_must_fail git init newdir/a/b | |
53d48885 NS |
269 | ' |
270 | ||
87a074df JK |
271 | test_expect_success 'init creates a new bare directory with global --bare' ' |
272 | rm -rf newdir && | |
273 | git --bare init newdir && | |
633734d4 | 274 | test_path_is_dir newdir/refs |
87a074df JK |
275 | ' |
276 | ||
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 && | |
633734d4 JK |
281 | test_path_is_dir newdir/refs && |
282 | test_path_is_missing otherdir/refs | |
87a074df JK |
283 | ' |
284 | ||
b57fb80a NTND |
285 | test_expect_success 'init with separate gitdir' ' |
286 | rm -rf newdir && | |
287 | git init --separate-git-dir realgitdir newdir && | |
88619b3e | 288 | echo "gitdir: $(pwd)/realgitdir" >expected && |
b57fb80a | 289 | test_cmp expected newdir/.git && |
633734d4 | 290 | test_path_is_dir realgitdir/refs |
b57fb80a NTND |
291 | ' |
292 | ||
487a2b73 NTND |
293 | test_expect_success 're-init on .git file' ' |
294 | ( cd newdir && git init ) | |
295 | ' | |
296 | ||
b57fb80a NTND |
297 | test_expect_success 're-init to update git link' ' |
298 | ( | |
299 | cd newdir && | |
300 | git init --separate-git-dir ../surrealgitdir | |
301 | ) && | |
88619b3e | 302 | echo "gitdir: $(pwd)/surrealgitdir" >expected && |
b57fb80a | 303 | test_cmp expected newdir/.git && |
633734d4 JK |
304 | test_path_is_dir surrealgitdir/refs && |
305 | test_path_is_missing realgitdir/refs | |
b57fb80a NTND |
306 | ' |
307 | ||
308 | test_expect_success 're-init to move gitdir' ' | |
309 | rm -rf newdir realgitdir surrealgitdir && | |
310 | git init newdir && | |
311 | ( | |
312 | cd newdir && | |
313 | git init --separate-git-dir ../realgitdir | |
314 | ) && | |
88619b3e | 315 | echo "gitdir: $(pwd)/realgitdir" >expected && |
b57fb80a | 316 | test_cmp expected newdir/.git && |
633734d4 | 317 | test_path_is_dir realgitdir/refs |
b57fb80a NTND |
318 | ' |
319 | ||
4e95fb6c | 320 | test_expect_success SYMLINKS 're-init to move gitdir symlink' ' |
b57fb80a NTND |
321 | rm -rf newdir realgitdir && |
322 | git init newdir && | |
323 | ( | |
324 | cd newdir && | |
325 | mv .git here && | |
326 | ln -s here .git && | |
09ffc706 | 327 | git init --separate-git-dir ../realgitdir |
b57fb80a | 328 | ) && |
88619b3e | 329 | echo "gitdir: $(pwd)/realgitdir" >expected && |
b57fb80a | 330 | test_cmp expected newdir/.git && |
3d06c5f1 | 331 | test_cmp expected newdir/here && |
633734d4 | 332 | test_path_is_dir realgitdir/refs |
b57fb80a NTND |
333 | ' |
334 | ||
6adcca3f | 335 | test_done |