253
254
git_config_set("core.filemode", filemode ? "true" : "false");
255
if (is_bare_repository()) {
256
if (is_bare_repository())
256
257
git_config_set("core.bare", "true");
259
const char *work_tree = get_git_work_tree();
259
260
git_config_set("core.bare", "false");
260
261
/* allow template config file to override the default */
261
262
if (log_all_ref_updates == -1)
262
263
git_config_set("core.logallrefupdates", "true");
264
if (work_tree != git_work_tree_cfg)
265
git_config_set("core.worktree", work_tree);
268
/* Check if symlink is supported in the work tree */
271
strcpy(path + len, "tXXXXXX");
272
if (!close(xmkstemp(path)) &&
274
!symlink("testing", path) &&
275
!lstat(path, &st1) &&
276
S_ISLNK(st1.st_mode))
277
unlink(path); /* good */
279
git_config_set("core.symlinks", "false");
285
static void guess_repository_type(const char *git_dir)
290
if (0 <= is_bare_repository_cfg)
296
* "GIT_DIR=. git init" is always bare.
297
* "GIT_DIR=`pwd` git init" too.
299
if (!strcmp(".", git_dir))
301
if (!getcwd(cwd, sizeof(cwd)))
302
die("cannot tell cwd");
303
if (!strcmp(git_dir, cwd))
306
* "GIT_DIR=.git or GIT_DIR=something/.git is usually not.
308
if (!strcmp(git_dir, ".git"))
310
slash = strrchr(git_dir, '/');
311
if (slash && !strcmp(slash, "/.git"))
315
* Otherwise it is often bare. At this point
316
* we are just guessing.
319
is_bare_repository_cfg = 1;
267
323
static const char init_db_usage[] =
268
"git-init [--template=<template-directory>] [--shared]";
324
"git-init [-q | --quiet] [--template=<template-directory>] [--shared]";
271
327
* If you want to, you can share the DB area with any number of branches.
289
346
shared_repository = PERM_GROUP;
290
347
else if (!prefixcmp(arg, "--shared="))
291
348
shared_repository = git_config_perm("arg", arg+9);
349
else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
293
352
usage(init_db_usage);
356
* GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
357
* without --bare. Catch the error early.
359
git_dir = getenv(GIT_DIR_ENVIRONMENT);
360
if ((!git_dir || is_bare_repository_cfg == 1)
361
&& getenv(GIT_WORK_TREE_ENVIRONMENT))
362
die("%s (or --work-tree=<directory>) not allowed without "
363
"specifying %s (or --git-dir=<directory>)",
364
GIT_WORK_TREE_ENVIRONMENT,
365
GIT_DIR_ENVIRONMENT);
367
guess_repository_type(git_dir);
369
if (is_bare_repository_cfg <= 0) {
370
git_work_tree_cfg = xcalloc(PATH_MAX, 1);
371
if (!getcwd(git_work_tree_cfg, PATH_MAX))
372
die ("Cannot access current working directory.");
373
if (access(get_git_work_tree(), X_OK))
374
die ("Cannot access work tree '%s'",
375
get_git_work_tree());
297
379
* Set up the default .git directory contents
299
381
git_dir = getenv(GIT_DIR_ENVIRONMENT);
335
417
git_config_set("receive.denyNonFastforwards", "true");
338
printf("%s%s Git repository in %s/\n",
339
reinit ? "Reinitialized existing" : "Initialized empty",
340
shared_repository ? " shared" : "",
421
printf("%s%s Git repository in %s/\n",
422
reinit ? "Reinitialized existing" : "Initialized empty",
423
shared_repository ? " shared" : "",