Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 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 | ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 28 | sane_unset GIT_DIR GIT_WORK_TREE && |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 29 | mkdir plain && |
| 30 | cd plain && |
| 31 | git init |
| 32 | ) && |
| 33 | check_config plain/.git false unset |
| 34 | ' |
| 35 | |
Jonathan Nieder | 4ad8332 | 2010-11-26 22:32:41 +0700 | [diff] [blame] | 36 | test_expect_success 'plain nested in bare' ' |
| 37 | ( |
Brandon Casey | ed40ec5 | 2011-01-05 18:30:02 -0600 | [diff] [blame] | 38 | sane_unset GIT_DIR GIT_WORK_TREE && |
Jonathan Nieder | 4ad8332 | 2010-11-26 22:32:41 +0700 | [diff] [blame] | 39 | git init --bare bare-ancestor.git && |
| 40 | cd bare-ancestor.git && |
| 41 | mkdir plain-nested && |
| 42 | cd plain-nested && |
| 43 | git init |
| 44 | ) && |
| 45 | check_config bare-ancestor.git/plain-nested/.git false unset |
| 46 | ' |
| 47 | |
| 48 | test_expect_success 'plain through aliased command, outside any git repo' ' |
| 49 | ( |
Jonathan Nieder | 8f323c0 | 2011-03-15 04:04:49 -0500 | [diff] [blame] | 50 | sane_unset GIT_DIR GIT_WORK_TREE && |
Jonathan Nieder | 4ad8332 | 2010-11-26 22:32:41 +0700 | [diff] [blame] | 51 | HOME=$(pwd)/alias-config && |
| 52 | export HOME && |
| 53 | mkdir alias-config && |
| 54 | echo "[alias] aliasedinit = init" >alias-config/.gitconfig && |
| 55 | |
| 56 | GIT_CEILING_DIRECTORIES=$(pwd) && |
| 57 | export GIT_CEILING_DIRECTORIES && |
| 58 | |
| 59 | mkdir plain-aliased && |
| 60 | cd plain-aliased && |
| 61 | git aliasedinit |
| 62 | ) && |
| 63 | check_config plain-aliased/.git false unset |
| 64 | ' |
| 65 | |
| 66 | test_expect_failure 'plain nested through aliased command' ' |
| 67 | ( |
Brandon Casey | ed40ec5 | 2011-01-05 18:30:02 -0600 | [diff] [blame] | 68 | sane_unset GIT_DIR GIT_WORK_TREE && |
Jonathan Nieder | 4ad8332 | 2010-11-26 22:32:41 +0700 | [diff] [blame] | 69 | git init plain-ancestor-aliased && |
| 70 | cd plain-ancestor-aliased && |
| 71 | echo "[alias] aliasedinit = init" >>.git/config && |
| 72 | mkdir plain-nested && |
| 73 | cd plain-nested && |
| 74 | git aliasedinit |
| 75 | ) && |
| 76 | check_config plain-ancestor-aliased/plain-nested/.git false unset |
| 77 | ' |
| 78 | |
| 79 | test_expect_failure 'plain nested in bare through aliased command' ' |
| 80 | ( |
Brandon Casey | ed40ec5 | 2011-01-05 18:30:02 -0600 | [diff] [blame] | 81 | sane_unset GIT_DIR GIT_WORK_TREE && |
Jonathan Nieder | 4ad8332 | 2010-11-26 22:32:41 +0700 | [diff] [blame] | 82 | git init --bare bare-ancestor-aliased.git && |
| 83 | cd bare-ancestor-aliased.git && |
| 84 | echo "[alias] aliasedinit = init" >>config && |
| 85 | mkdir plain-nested && |
| 86 | cd plain-nested && |
| 87 | git aliasedinit |
| 88 | ) && |
| 89 | check_config bare-ancestor-aliased.git/plain-nested/.git false unset |
| 90 | ' |
| 91 | |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 92 | test_expect_success 'plain with GIT_WORK_TREE' ' |
| 93 | if ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 94 | sane_unset GIT_DIR && |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 95 | mkdir plain-wt && |
| 96 | cd plain-wt && |
| 97 | GIT_WORK_TREE=$(pwd) git init |
| 98 | ) |
| 99 | then |
| 100 | echo Should have failed -- GIT_WORK_TREE should not be used |
| 101 | false |
| 102 | fi |
| 103 | ' |
| 104 | |
| 105 | test_expect_success 'plain bare' ' |
| 106 | ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 107 | sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 108 | mkdir plain-bare-1 && |
| 109 | cd plain-bare-1 && |
| 110 | git --bare init |
| 111 | ) && |
| 112 | check_config plain-bare-1 true unset |
| 113 | ' |
| 114 | |
| 115 | test_expect_success 'plain bare with GIT_WORK_TREE' ' |
| 116 | if ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 117 | sane_unset GIT_DIR GIT_CONFIG && |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 118 | mkdir plain-bare-2 && |
| 119 | cd plain-bare-2 && |
| 120 | GIT_WORK_TREE=$(pwd) git --bare init |
| 121 | ) |
| 122 | then |
| 123 | echo Should have failed -- GIT_WORK_TREE should not be used |
| 124 | false |
| 125 | fi |
| 126 | ' |
| 127 | |
| 128 | test_expect_success 'GIT_DIR bare' ' |
| 129 | |
| 130 | ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 131 | sane_unset GIT_CONFIG && |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 132 | mkdir git-dir-bare.git && |
| 133 | GIT_DIR=git-dir-bare.git git init |
| 134 | ) && |
| 135 | check_config git-dir-bare.git true unset |
| 136 | ' |
| 137 | |
Luciano Rocha | 74d3b23 | 2008-05-28 19:53:57 +0100 | [diff] [blame] | 138 | test_expect_success 'init --bare' ' |
| 139 | |
| 140 | ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 141 | sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && |
Miklos Vajna | b613827 | 2008-07-11 02:12:03 +0200 | [diff] [blame] | 142 | mkdir init-bare.git && |
| 143 | cd init-bare.git && |
Luciano Rocha | 74d3b23 | 2008-05-28 19:53:57 +0100 | [diff] [blame] | 144 | git init --bare |
| 145 | ) && |
Miklos Vajna | b613827 | 2008-07-11 02:12:03 +0200 | [diff] [blame] | 146 | check_config init-bare.git true unset |
Luciano Rocha | 74d3b23 | 2008-05-28 19:53:57 +0100 | [diff] [blame] | 147 | ' |
| 148 | |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 149 | test_expect_success 'GIT_DIR non-bare' ' |
| 150 | |
| 151 | ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 152 | sane_unset GIT_CONFIG && |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 153 | mkdir non-bare && |
| 154 | cd non-bare && |
| 155 | GIT_DIR=.git git init |
| 156 | ) && |
| 157 | check_config non-bare/.git false unset |
| 158 | ' |
| 159 | |
| 160 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' |
| 161 | |
| 162 | ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 163 | sane_unset GIT_CONFIG && |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 164 | mkdir git-dir-wt-1.git && |
| 165 | GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init |
| 166 | ) && |
| 167 | check_config git-dir-wt-1.git false "$(pwd)" |
| 168 | ' |
| 169 | |
| 170 | test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' |
| 171 | |
| 172 | if ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 173 | sane_unset GIT_CONFIG && |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 174 | mkdir git-dir-wt-2.git && |
| 175 | GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init |
| 176 | ) |
| 177 | then |
| 178 | echo Should have failed -- --bare should not be used |
| 179 | false |
| 180 | fi |
| 181 | ' |
| 182 | |
Junio C Hamano | 127df8c | 2011-04-12 15:57:08 -0700 | [diff] [blame] | 183 | test_expect_success 'reinit' ' |
Johannes Schindelin | 5cc8f37 | 2008-03-24 16:14:52 +0100 | [diff] [blame] | 184 | |
| 185 | ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 186 | sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG && |
Johannes Schindelin | 5cc8f37 | 2008-03-24 16:14:52 +0100 | [diff] [blame] | 187 | |
| 188 | mkdir again && |
| 189 | cd again && |
| 190 | git init >out1 2>err1 && |
| 191 | git init >out2 2>err2 |
| 192 | ) && |
Junio C Hamano | 127df8c | 2011-04-12 15:57:08 -0700 | [diff] [blame] | 193 | test_i18ngrep "Initialized empty" again/out1 && |
| 194 | test_i18ngrep "Reinitialized existing" again/out2 && |
Johannes Schindelin | 5cc8f37 | 2008-03-24 16:14:52 +0100 | [diff] [blame] | 195 | >again/empty && |
Junio C Hamano | 127df8c | 2011-04-12 15:57:08 -0700 | [diff] [blame] | 196 | test_i18ncmp again/empty again/err1 && |
| 197 | test_i18ncmp again/empty again/err2 |
Johannes Schindelin | 5cc8f37 | 2008-03-24 16:14:52 +0100 | [diff] [blame] | 198 | ' |
| 199 | |
Jeff King | 172035f | 2008-07-28 02:02:04 -0400 | [diff] [blame] | 200 | test_expect_success 'init with --template' ' |
| 201 | mkdir template-source && |
| 202 | echo content >template-source/file && |
| 203 | ( |
| 204 | mkdir template-custom && |
| 205 | cd template-custom && |
| 206 | git init --template=../template-source |
| 207 | ) && |
| 208 | test_cmp template-source/file template-custom/.git/file |
| 209 | ' |
| 210 | |
| 211 | test_expect_success 'init with --template (blank)' ' |
| 212 | ( |
| 213 | mkdir template-plain && |
| 214 | cd template-plain && |
| 215 | git init |
| 216 | ) && |
| 217 | test -f template-plain/.git/info/exclude && |
| 218 | ( |
| 219 | mkdir template-blank && |
| 220 | cd template-blank && |
| 221 | git init --template= |
| 222 | ) && |
| 223 | ! test -f template-blank/.git/info/exclude |
| 224 | ' |
| 225 | |
Steven Drake | a94d305 | 2010-02-26 17:00:21 +1300 | [diff] [blame] | 226 | test_expect_success 'init with init.templatedir set' ' |
| 227 | mkdir templatedir-source && |
| 228 | echo Content >templatedir-source/file && |
| 229 | ( |
Steven Drake | a94d305 | 2010-02-26 17:00:21 +1300 | [diff] [blame] | 230 | test_config="${HOME}/.gitconfig" && |
| 231 | git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" && |
| 232 | mkdir templatedir-set && |
| 233 | cd templatedir-set && |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 234 | sane_unset GIT_TEMPLATE_DIR && |
Steven Drake | a94d305 | 2010-02-26 17:00:21 +1300 | [diff] [blame] | 235 | NO_SET_GIT_TEMPLATE_DIR=t && |
| 236 | export NO_SET_GIT_TEMPLATE_DIR && |
| 237 | git init |
| 238 | ) && |
| 239 | test_cmp templatedir-source/file templatedir-set/.git/file |
| 240 | ' |
| 241 | |
Deskin Miller | 0a2c7ee | 2008-10-07 01:37:48 -0400 | [diff] [blame] | 242 | test_expect_success 'init --bare/--shared overrides system/global config' ' |
| 243 | ( |
Deskin Miller | 0a2c7ee | 2008-10-07 01:37:48 -0400 | [diff] [blame] | 244 | test_config="$HOME"/.gitconfig && |
Deskin Miller | 0a2c7ee | 2008-10-07 01:37:48 -0400 | [diff] [blame] | 245 | git config -f "$test_config" core.bare false && |
| 246 | git config -f "$test_config" core.sharedRepository 0640 && |
| 247 | mkdir init-bare-shared-override && |
| 248 | cd init-bare-shared-override && |
| 249 | git init --bare --shared=0666 |
| 250 | ) && |
| 251 | check_config init-bare-shared-override true unset && |
| 252 | test x0666 = \ |
| 253 | x`git config -f init-bare-shared-override/config core.sharedRepository` |
| 254 | ' |
| 255 | |
| 256 | test_expect_success 'init honors global core.sharedRepository' ' |
| 257 | ( |
Deskin Miller | 0a2c7ee | 2008-10-07 01:37:48 -0400 | [diff] [blame] | 258 | test_config="$HOME"/.gitconfig && |
Deskin Miller | 0a2c7ee | 2008-10-07 01:37:48 -0400 | [diff] [blame] | 259 | git config -f "$test_config" core.sharedRepository 0666 && |
| 260 | mkdir shared-honor-global && |
| 261 | cd shared-honor-global && |
| 262 | git init |
| 263 | ) && |
| 264 | test x0666 = \ |
| 265 | x`git config -f shared-honor-global/.git/config core.sharedRepository` |
| 266 | ' |
| 267 | |
Frank Lichtenheld | 32d1776 | 2009-04-18 16:14:02 +0200 | [diff] [blame] | 268 | test_expect_success 'init rejects insanely long --template' ' |
| 269 | ( |
| 270 | insane=$(printf "x%09999dx" 1) && |
| 271 | mkdir test && |
| 272 | cd test && |
| 273 | test_must_fail git init --template=$insane |
| 274 | ) |
| 275 | ' |
| 276 | |
Nanako Shiraishi | 53d4888 | 2009-07-25 06:59:28 +0900 | [diff] [blame] | 277 | test_expect_success 'init creates a new directory' ' |
| 278 | rm -fr newdir && |
| 279 | ( |
| 280 | git init newdir && |
| 281 | test -d newdir/.git/refs |
| 282 | ) |
| 283 | ' |
| 284 | |
| 285 | test_expect_success 'init creates a new bare directory' ' |
| 286 | rm -fr newdir && |
| 287 | ( |
| 288 | git init --bare newdir && |
| 289 | test -d newdir/refs |
| 290 | ) |
| 291 | ' |
| 292 | |
| 293 | test_expect_success 'init recreates a directory' ' |
| 294 | rm -fr newdir && |
| 295 | ( |
| 296 | mkdir newdir && |
| 297 | git init newdir && |
| 298 | test -d newdir/.git/refs |
| 299 | ) |
| 300 | ' |
| 301 | |
| 302 | test_expect_success 'init recreates a new bare directory' ' |
| 303 | rm -fr newdir && |
| 304 | ( |
| 305 | mkdir newdir && |
| 306 | git init --bare newdir && |
| 307 | test -d newdir/refs |
| 308 | ) |
| 309 | ' |
| 310 | |
| 311 | test_expect_success 'init creates a new deep directory' ' |
| 312 | rm -fr newdir && |
Johannes Sixt | d82e75e | 2009-08-09 18:02:55 +0200 | [diff] [blame] | 313 | git init newdir/a/b/c && |
| 314 | test -d newdir/a/b/c/.git/refs |
| 315 | ' |
| 316 | |
| 317 | test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' ' |
| 318 | rm -fr newdir && |
Nanako Shiraishi | 53d4888 | 2009-07-25 06:59:28 +0900 | [diff] [blame] | 319 | ( |
| 320 | # Leading directories should honor umask while |
| 321 | # the repository itself should follow "shared" |
| 322 | umask 002 && |
| 323 | git init --bare --shared=0660 newdir/a/b/c && |
| 324 | test -d newdir/a/b/c/refs && |
| 325 | ls -ld newdir/a newdir/a/b > lsab.out && |
Johannes Sixt | 7d53a07 | 2009-08-09 17:38:04 +0200 | [diff] [blame] | 326 | ! grep -v "^drwxrw[sx]r-x" lsab.out && |
Nanako Shiraishi | 53d4888 | 2009-07-25 06:59:28 +0900 | [diff] [blame] | 327 | ls -ld newdir/a/b/c > lsc.out && |
| 328 | ! grep -v "^drwxrw[sx]---" lsc.out |
| 329 | ) |
| 330 | ' |
| 331 | |
| 332 | test_expect_success 'init notices EEXIST (1)' ' |
| 333 | rm -fr newdir && |
| 334 | ( |
| 335 | >newdir && |
| 336 | test_must_fail git init newdir && |
| 337 | test -f newdir |
| 338 | ) |
| 339 | ' |
| 340 | |
| 341 | test_expect_success 'init notices EEXIST (2)' ' |
| 342 | rm -fr newdir && |
| 343 | ( |
| 344 | mkdir newdir && |
| 345 | >newdir/a |
| 346 | test_must_fail git init newdir/a/b && |
| 347 | test -f newdir/a |
| 348 | ) |
| 349 | ' |
| 350 | |
Ævar Arnfjörð Bjarmason | c91cfd1 | 2010-08-06 22:09:09 +0000 | [diff] [blame] | 351 | test_expect_success POSIXPERM,SANITY 'init notices EPERM' ' |
Nanako Shiraishi | 53d4888 | 2009-07-25 06:59:28 +0900 | [diff] [blame] | 352 | rm -fr newdir && |
| 353 | ( |
| 354 | mkdir newdir && |
| 355 | chmod -w newdir && |
| 356 | test_must_fail git init newdir/a/b |
| 357 | ) |
| 358 | ' |
| 359 | |
Jeff King | 87a074d | 2010-05-10 05:42:06 -0400 | [diff] [blame] | 360 | test_expect_success 'init creates a new bare directory with global --bare' ' |
| 361 | rm -rf newdir && |
| 362 | git --bare init newdir && |
| 363 | test -d newdir/refs |
| 364 | ' |
| 365 | |
| 366 | test_expect_success 'init prefers command line to GIT_DIR' ' |
| 367 | rm -rf newdir && |
| 368 | mkdir otherdir && |
| 369 | GIT_DIR=otherdir git --bare init newdir && |
| 370 | test -d newdir/refs && |
| 371 | ! test -d otherdir/refs |
| 372 | ' |
| 373 | |
Nguyễn Thái Ngọc Duy | b57fb80 | 2011-03-19 22:16:56 +0700 | [diff] [blame] | 374 | test_expect_success 'init with separate gitdir' ' |
| 375 | rm -rf newdir && |
| 376 | git init --separate-git-dir realgitdir newdir && |
| 377 | echo "gitdir: `pwd`/realgitdir" >expected && |
| 378 | test_cmp expected newdir/.git && |
| 379 | test -d realgitdir/refs |
| 380 | ' |
| 381 | |
| 382 | test_expect_success 're-init to update git link' ' |
| 383 | ( |
| 384 | cd newdir && |
| 385 | git init --separate-git-dir ../surrealgitdir |
| 386 | ) && |
| 387 | echo "gitdir: `pwd`/surrealgitdir" >expected && |
| 388 | test_cmp expected newdir/.git && |
| 389 | test -d surrealgitdir/refs && |
| 390 | ! test -d realgitdir/refs |
| 391 | ' |
| 392 | |
| 393 | test_expect_success 're-init to move gitdir' ' |
| 394 | rm -rf newdir realgitdir surrealgitdir && |
| 395 | git init newdir && |
| 396 | ( |
| 397 | cd newdir && |
| 398 | git init --separate-git-dir ../realgitdir |
| 399 | ) && |
| 400 | echo "gitdir: `pwd`/realgitdir" >expected && |
| 401 | test_cmp expected newdir/.git && |
| 402 | test -d realgitdir/refs |
| 403 | ' |
| 404 | |
Johannes Sixt | 4e95fb6 | 2011-04-12 08:30:49 +0200 | [diff] [blame] | 405 | test_expect_success SYMLINKS 're-init to move gitdir symlink' ' |
Nguyễn Thái Ngọc Duy | b57fb80 | 2011-03-19 22:16:56 +0700 | [diff] [blame] | 406 | rm -rf newdir realgitdir && |
| 407 | git init newdir && |
| 408 | ( |
| 409 | cd newdir && |
| 410 | mv .git here && |
| 411 | ln -s here .git && |
Nguyen Thai Ngoc Duy | 09ffc70 | 2011-05-24 23:40:32 +0700 | [diff] [blame] | 412 | git init --separate-git-dir ../realgitdir |
Nguyễn Thái Ngọc Duy | b57fb80 | 2011-03-19 22:16:56 +0700 | [diff] [blame] | 413 | ) && |
| 414 | echo "gitdir: `pwd`/realgitdir" >expected && |
| 415 | test_cmp expected newdir/.git && |
| 416 | test -d realgitdir/refs && |
| 417 | ! test -d newdir/here |
| 418 | ' |
| 419 | |
Junio C Hamano | 6adcca3 | 2007-08-27 00:58:06 -0700 | [diff] [blame] | 420 | test_done |