]> git.ipfire.org Git - thirdparty/git.git/blob - builtin/init-db.c
Merge branch 'ds/remove-idx-before-pack'
[thirdparty/git.git] / builtin / init-db.c
1 /*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "cache.h"
7 #include "abspath.h"
8 #include "config.h"
9 #include "copy.h"
10 #include "environment.h"
11 #include "gettext.h"
12 #include "refs.h"
13 #include "builtin.h"
14 #include "exec-cmd.h"
15 #include "object-file.h"
16 #include "parse-options.h"
17 #include "path.h"
18 #include "setup.h"
19 #include "worktree.h"
20 #include "wrapper.h"
21
22 #ifndef DEFAULT_GIT_TEMPLATE_DIR
23 #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
24 #endif
25
26 #ifdef NO_TRUSTABLE_FILEMODE
27 #define TEST_FILEMODE 0
28 #else
29 #define TEST_FILEMODE 1
30 #endif
31
32 #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
33
34 static int init_is_bare_repository = 0;
35 static int init_shared_repository = -1;
36
37 static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
38 DIR *dir)
39 {
40 size_t path_baselen = path->len;
41 size_t template_baselen = template_path->len;
42 struct dirent *de;
43
44 /* Note: if ".git/hooks" file exists in the repository being
45 * re-initialized, /etc/core-git/templates/hooks/update would
46 * cause "git init" to fail here. I think this is sane but
47 * it means that the set of templates we ship by default, along
48 * with the way the namespace under .git/ is organized, should
49 * be really carefully chosen.
50 */
51 safe_create_dir(path->buf, 1);
52 while ((de = readdir(dir)) != NULL) {
53 struct stat st_git, st_template;
54 int exists = 0;
55
56 strbuf_setlen(path, path_baselen);
57 strbuf_setlen(template_path, template_baselen);
58
59 if (de->d_name[0] == '.')
60 continue;
61 strbuf_addstr(path, de->d_name);
62 strbuf_addstr(template_path, de->d_name);
63 if (lstat(path->buf, &st_git)) {
64 if (errno != ENOENT)
65 die_errno(_("cannot stat '%s'"), path->buf);
66 }
67 else
68 exists = 1;
69
70 if (lstat(template_path->buf, &st_template))
71 die_errno(_("cannot stat template '%s'"), template_path->buf);
72
73 if (S_ISDIR(st_template.st_mode)) {
74 DIR *subdir = opendir(template_path->buf);
75 if (!subdir)
76 die_errno(_("cannot opendir '%s'"), template_path->buf);
77 strbuf_addch(path, '/');
78 strbuf_addch(template_path, '/');
79 copy_templates_1(path, template_path, subdir);
80 closedir(subdir);
81 }
82 else if (exists)
83 continue;
84 else if (S_ISLNK(st_template.st_mode)) {
85 struct strbuf lnk = STRBUF_INIT;
86 if (strbuf_readlink(&lnk, template_path->buf,
87 st_template.st_size) < 0)
88 die_errno(_("cannot readlink '%s'"), template_path->buf);
89 if (symlink(lnk.buf, path->buf))
90 die_errno(_("cannot symlink '%s' '%s'"),
91 lnk.buf, path->buf);
92 strbuf_release(&lnk);
93 }
94 else if (S_ISREG(st_template.st_mode)) {
95 if (copy_file(path->buf, template_path->buf, st_template.st_mode))
96 die_errno(_("cannot copy '%s' to '%s'"),
97 template_path->buf, path->buf);
98 }
99 else
100 error(_("ignoring template %s"), template_path->buf);
101 }
102 }
103
104 static void copy_templates(const char *template_dir, const char *init_template_dir)
105 {
106 struct strbuf path = STRBUF_INIT;
107 struct strbuf template_path = STRBUF_INIT;
108 size_t template_len;
109 struct repository_format template_format = REPOSITORY_FORMAT_INIT;
110 struct strbuf err = STRBUF_INIT;
111 DIR *dir;
112 char *to_free = NULL;
113
114 if (!template_dir)
115 template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
116 if (!template_dir)
117 template_dir = init_template_dir;
118 if (!template_dir)
119 template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
120 if (!template_dir[0]) {
121 free(to_free);
122 return;
123 }
124
125 strbuf_addstr(&template_path, template_dir);
126 strbuf_complete(&template_path, '/');
127 template_len = template_path.len;
128
129 dir = opendir(template_path.buf);
130 if (!dir) {
131 warning(_("templates not found in %s"), template_dir);
132 goto free_return;
133 }
134
135 /* Make sure that template is from the correct vintage */
136 strbuf_addstr(&template_path, "config");
137 read_repository_format(&template_format, template_path.buf);
138 strbuf_setlen(&template_path, template_len);
139
140 /*
141 * No mention of version at all is OK, but anything else should be
142 * verified.
143 */
144 if (template_format.version >= 0 &&
145 verify_repository_format(&template_format, &err) < 0) {
146 warning(_("not copying templates from '%s': %s"),
147 template_dir, err.buf);
148 strbuf_release(&err);
149 goto close_free_return;
150 }
151
152 strbuf_addstr(&path, get_git_common_dir());
153 strbuf_complete(&path, '/');
154 copy_templates_1(&path, &template_path, dir);
155 close_free_return:
156 closedir(dir);
157 free_return:
158 free(to_free);
159 strbuf_release(&path);
160 strbuf_release(&template_path);
161 clear_repository_format(&template_format);
162 }
163
164 /*
165 * If the git_dir is not directly inside the working tree, then git will not
166 * find it by default, and we need to set the worktree explicitly.
167 */
168 static int needs_work_tree_config(const char *git_dir, const char *work_tree)
169 {
170 if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
171 return 0;
172 if (skip_prefix(git_dir, work_tree, &git_dir) &&
173 !strcmp(git_dir, "/.git"))
174 return 0;
175 return 1;
176 }
177
178 void initialize_repository_version(int hash_algo, int reinit)
179 {
180 char repo_version_string[10];
181 int repo_version = GIT_REPO_VERSION;
182
183 if (hash_algo != GIT_HASH_SHA1)
184 repo_version = GIT_REPO_VERSION_READ;
185
186 /* This forces creation of new config file */
187 xsnprintf(repo_version_string, sizeof(repo_version_string),
188 "%d", repo_version);
189 git_config_set("core.repositoryformatversion", repo_version_string);
190
191 if (hash_algo != GIT_HASH_SHA1)
192 git_config_set("extensions.objectformat",
193 hash_algos[hash_algo].name);
194 else if (reinit)
195 git_config_set_gently("extensions.objectformat", NULL);
196 }
197
198 static int create_default_files(const char *template_path,
199 const char *original_git_dir,
200 const char *initial_branch,
201 const struct repository_format *fmt,
202 int quiet)
203 {
204 struct stat st1;
205 struct strbuf buf = STRBUF_INIT;
206 char *path;
207 char junk[2];
208 int reinit;
209 int filemode;
210 struct strbuf err = STRBUF_INIT;
211 const char *init_template_dir = NULL;
212 const char *work_tree = get_git_work_tree();
213
214 /*
215 * First copy the templates -- we might have the default
216 * config file there, in which case we would want to read
217 * from it after installing.
218 *
219 * Before reading that config, we also need to clear out any cached
220 * values (since we've just potentially changed what's available on
221 * disk).
222 */
223 git_config_get_pathname("init.templatedir", &init_template_dir);
224 copy_templates(template_path, init_template_dir);
225 free((char *)init_template_dir);
226 git_config_clear();
227 reset_shared_repository();
228 git_config(git_default_config, NULL);
229
230 /*
231 * We must make sure command-line options continue to override any
232 * values we might have just re-read from the config.
233 */
234 is_bare_repository_cfg = init_is_bare_repository || !work_tree;
235 if (init_shared_repository != -1)
236 set_shared_repository(init_shared_repository);
237
238 /*
239 * We would have created the above under user's umask -- under
240 * shared-repository settings, we would need to fix them up.
241 */
242 if (get_shared_repository()) {
243 adjust_shared_perm(get_git_dir());
244 }
245
246 /*
247 * We need to create a "refs" dir in any case so that older
248 * versions of git can tell that this is a repository.
249 */
250 safe_create_dir(git_path("refs"), 1);
251 adjust_shared_perm(git_path("refs"));
252
253 if (refs_init_db(&err))
254 die("failed to set up refs db: %s", err.buf);
255
256 /*
257 * Point the HEAD symref to the initial branch with if HEAD does
258 * not yet exist.
259 */
260 path = git_path_buf(&buf, "HEAD");
261 reinit = (!access(path, R_OK)
262 || readlink(path, junk, sizeof(junk)-1) != -1);
263 if (!reinit) {
264 char *ref;
265
266 if (!initial_branch)
267 initial_branch = git_default_branch_name(quiet);
268
269 ref = xstrfmt("refs/heads/%s", initial_branch);
270 if (check_refname_format(ref, 0) < 0)
271 die(_("invalid initial branch name: '%s'"),
272 initial_branch);
273
274 if (create_symref("HEAD", ref, NULL) < 0)
275 exit(1);
276 free(ref);
277 }
278
279 initialize_repository_version(fmt->hash_algo, 0);
280
281 /* Check filemode trustability */
282 path = git_path_buf(&buf, "config");
283 filemode = TEST_FILEMODE;
284 if (TEST_FILEMODE && !lstat(path, &st1)) {
285 struct stat st2;
286 filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
287 !lstat(path, &st2) &&
288 st1.st_mode != st2.st_mode &&
289 !chmod(path, st1.st_mode));
290 if (filemode && !reinit && (st1.st_mode & S_IXUSR))
291 filemode = 0;
292 }
293 git_config_set("core.filemode", filemode ? "true" : "false");
294
295 if (is_bare_repository())
296 git_config_set("core.bare", "true");
297 else {
298 git_config_set("core.bare", "false");
299 /* allow template config file to override the default */
300 if (log_all_ref_updates == LOG_REFS_UNSET)
301 git_config_set("core.logallrefupdates", "true");
302 if (needs_work_tree_config(original_git_dir, work_tree))
303 git_config_set("core.worktree", work_tree);
304 }
305
306 if (!reinit) {
307 /* Check if symlink is supported in the work tree */
308 path = git_path_buf(&buf, "tXXXXXX");
309 if (!close(xmkstemp(path)) &&
310 !unlink(path) &&
311 !symlink("testing", path) &&
312 !lstat(path, &st1) &&
313 S_ISLNK(st1.st_mode))
314 unlink(path); /* good */
315 else
316 git_config_set("core.symlinks", "false");
317
318 /* Check if the filesystem is case-insensitive */
319 path = git_path_buf(&buf, "CoNfIg");
320 if (!access(path, F_OK))
321 git_config_set("core.ignorecase", "true");
322 probe_utf8_pathname_composition();
323 }
324
325 strbuf_release(&buf);
326 return reinit;
327 }
328
329 static void create_object_directory(void)
330 {
331 struct strbuf path = STRBUF_INIT;
332 size_t baselen;
333
334 strbuf_addstr(&path, get_object_directory());
335 baselen = path.len;
336
337 safe_create_dir(path.buf, 1);
338
339 strbuf_setlen(&path, baselen);
340 strbuf_addstr(&path, "/pack");
341 safe_create_dir(path.buf, 1);
342
343 strbuf_setlen(&path, baselen);
344 strbuf_addstr(&path, "/info");
345 safe_create_dir(path.buf, 1);
346
347 strbuf_release(&path);
348 }
349
350 static void separate_git_dir(const char *git_dir, const char *git_link)
351 {
352 struct stat st;
353
354 if (!stat(git_link, &st)) {
355 const char *src;
356
357 if (S_ISREG(st.st_mode))
358 src = read_gitfile(git_link);
359 else if (S_ISDIR(st.st_mode))
360 src = git_link;
361 else
362 die(_("unable to handle file type %d"), (int)st.st_mode);
363
364 if (rename(src, git_dir))
365 die_errno(_("unable to move %s to %s"), src, git_dir);
366 repair_worktrees(NULL, NULL);
367 }
368
369 write_file(git_link, "gitdir: %s", git_dir);
370 }
371
372 static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
373 {
374 const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
375 /*
376 * If we already have an initialized repo, don't allow the user to
377 * specify a different algorithm, as that could cause corruption.
378 * Otherwise, if the user has specified one on the command line, use it.
379 */
380 if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
381 die(_("attempt to reinitialize repository with different hash"));
382 else if (hash != GIT_HASH_UNKNOWN)
383 repo_fmt->hash_algo = hash;
384 else if (env) {
385 int env_algo = hash_algo_by_name(env);
386 if (env_algo == GIT_HASH_UNKNOWN)
387 die(_("unknown hash algorithm '%s'"), env);
388 repo_fmt->hash_algo = env_algo;
389 }
390 }
391
392 int init_db(const char *git_dir, const char *real_git_dir,
393 const char *template_dir, int hash, const char *initial_branch,
394 unsigned int flags)
395 {
396 int reinit;
397 int exist_ok = flags & INIT_DB_EXIST_OK;
398 char *original_git_dir = real_pathdup(git_dir, 1);
399 struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
400
401 if (real_git_dir) {
402 struct stat st;
403
404 if (!exist_ok && !stat(git_dir, &st))
405 die(_("%s already exists"), git_dir);
406
407 if (!exist_ok && !stat(real_git_dir, &st))
408 die(_("%s already exists"), real_git_dir);
409
410 set_git_dir(real_git_dir, 1);
411 git_dir = get_git_dir();
412 separate_git_dir(git_dir, original_git_dir);
413 }
414 else {
415 set_git_dir(git_dir, 1);
416 git_dir = get_git_dir();
417 }
418 startup_info->have_repository = 1;
419
420 /* Ensure `core.hidedotfiles` is processed */
421 git_config(platform_core_config, NULL);
422
423 safe_create_dir(git_dir, 0);
424
425 init_is_bare_repository = is_bare_repository();
426
427 /* Check to see if the repository version is right.
428 * Note that a newly created repository does not have
429 * config file, so this will not fail. What we are catching
430 * is an attempt to reinitialize new repository with an old tool.
431 */
432 check_repository_format(&repo_fmt);
433
434 validate_hash_algorithm(&repo_fmt, hash);
435
436 reinit = create_default_files(template_dir, original_git_dir,
437 initial_branch, &repo_fmt,
438 flags & INIT_DB_QUIET);
439 if (reinit && initial_branch)
440 warning(_("re-init: ignored --initial-branch=%s"),
441 initial_branch);
442
443 create_object_directory();
444
445 if (get_shared_repository()) {
446 char buf[10];
447 /* We do not spell "group" and such, so that
448 * the configuration can be read by older version
449 * of git. Note, we use octal numbers for new share modes,
450 * and compatibility values for PERM_GROUP and
451 * PERM_EVERYBODY.
452 */
453 if (get_shared_repository() < 0)
454 /* force to the mode value */
455 xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
456 else if (get_shared_repository() == PERM_GROUP)
457 xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
458 else if (get_shared_repository() == PERM_EVERYBODY)
459 xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
460 else
461 BUG("invalid value for shared_repository");
462 git_config_set("core.sharedrepository", buf);
463 git_config_set("receive.denyNonFastforwards", "true");
464 }
465
466 if (!(flags & INIT_DB_QUIET)) {
467 int len = strlen(git_dir);
468
469 if (reinit)
470 printf(get_shared_repository()
471 ? _("Reinitialized existing shared Git repository in %s%s\n")
472 : _("Reinitialized existing Git repository in %s%s\n"),
473 git_dir, len && git_dir[len-1] != '/' ? "/" : "");
474 else
475 printf(get_shared_repository()
476 ? _("Initialized empty shared Git repository in %s%s\n")
477 : _("Initialized empty Git repository in %s%s\n"),
478 git_dir, len && git_dir[len-1] != '/' ? "/" : "");
479 }
480
481 free(original_git_dir);
482 return 0;
483 }
484
485 static int guess_repository_type(const char *git_dir)
486 {
487 const char *slash;
488 char *cwd;
489 int cwd_is_git_dir;
490
491 /*
492 * "GIT_DIR=. git init" is always bare.
493 * "GIT_DIR=`pwd` git init" too.
494 */
495 if (!strcmp(".", git_dir))
496 return 1;
497 cwd = xgetcwd();
498 cwd_is_git_dir = !strcmp(git_dir, cwd);
499 free(cwd);
500 if (cwd_is_git_dir)
501 return 1;
502 /*
503 * "GIT_DIR=.git or GIT_DIR=something/.git is usually not.
504 */
505 if (!strcmp(git_dir, ".git"))
506 return 0;
507 slash = strrchr(git_dir, '/');
508 if (slash && !strcmp(slash, "/.git"))
509 return 0;
510
511 /*
512 * Otherwise it is often bare. At this point
513 * we are just guessing.
514 */
515 return 1;
516 }
517
518 static int shared_callback(const struct option *opt, const char *arg, int unset)
519 {
520 BUG_ON_OPT_NEG(unset);
521 *((int *) opt->value) = (arg) ? git_config_perm("arg", arg) : PERM_GROUP;
522 return 0;
523 }
524
525 static const char *const init_db_usage[] = {
526 N_("git init [-q | --quiet] [--bare] [--template=<template-directory>]\n"
527 " [--separate-git-dir <git-dir>] [--object-format=<format>]\n"
528 " [-b <branch-name> | --initial-branch=<branch-name>]\n"
529 " [--shared[=<permissions>]] [<directory>]"),
530 NULL
531 };
532
533 /*
534 * If you want to, you can share the DB area with any number of branches.
535 * That has advantages: you can save space by sharing all the SHA1 objects.
536 * On the other hand, it might just make lookup slower and messier. You
537 * be the judge. The default case is to have one DB per managed directory.
538 */
539 int cmd_init_db(int argc, const char **argv, const char *prefix)
540 {
541 const char *git_dir;
542 const char *real_git_dir = NULL;
543 const char *work_tree;
544 const char *template_dir = NULL;
545 unsigned int flags = 0;
546 const char *object_format = NULL;
547 const char *initial_branch = NULL;
548 int hash_algo = GIT_HASH_UNKNOWN;
549 const struct option init_db_options[] = {
550 OPT_STRING(0, "template", &template_dir, N_("template-directory"),
551 N_("directory from which templates will be used")),
552 OPT_SET_INT(0, "bare", &is_bare_repository_cfg,
553 N_("create a bare repository"), 1),
554 { OPTION_CALLBACK, 0, "shared", &init_shared_repository,
555 N_("permissions"),
556 N_("specify that the git repository is to be shared amongst several users"),
557 PARSE_OPT_OPTARG | PARSE_OPT_NONEG, shared_callback, 0},
558 OPT_BIT('q', "quiet", &flags, N_("be quiet"), INIT_DB_QUIET),
559 OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
560 N_("separate git dir from working tree")),
561 OPT_STRING('b', "initial-branch", &initial_branch, N_("name"),
562 N_("override the name of the initial branch")),
563 OPT_STRING(0, "object-format", &object_format, N_("hash"),
564 N_("specify the hash algorithm to use")),
565 OPT_END()
566 };
567
568 argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
569
570 if (real_git_dir && is_bare_repository_cfg == 1)
571 die(_("options '%s' and '%s' cannot be used together"), "--separate-git-dir", "--bare");
572
573 if (real_git_dir && !is_absolute_path(real_git_dir))
574 real_git_dir = real_pathdup(real_git_dir, 1);
575
576 if (template_dir && *template_dir && !is_absolute_path(template_dir)) {
577 template_dir = absolute_pathdup(template_dir);
578 UNLEAK(template_dir);
579 }
580
581 if (argc == 1) {
582 int mkdir_tried = 0;
583 retry:
584 if (chdir(argv[0]) < 0) {
585 if (!mkdir_tried) {
586 int saved;
587 /*
588 * At this point we haven't read any configuration,
589 * and we know shared_repository should always be 0;
590 * but just in case we play safe.
591 */
592 saved = get_shared_repository();
593 set_shared_repository(0);
594 switch (safe_create_leading_directories_const(argv[0])) {
595 case SCLD_OK:
596 case SCLD_PERMS:
597 break;
598 case SCLD_EXISTS:
599 errno = EEXIST;
600 /* fallthru */
601 default:
602 die_errno(_("cannot mkdir %s"), argv[0]);
603 break;
604 }
605 set_shared_repository(saved);
606 if (mkdir(argv[0], 0777) < 0)
607 die_errno(_("cannot mkdir %s"), argv[0]);
608 mkdir_tried = 1;
609 goto retry;
610 }
611 die_errno(_("cannot chdir to %s"), argv[0]);
612 }
613 } else if (0 < argc) {
614 usage(init_db_usage[0]);
615 }
616 if (is_bare_repository_cfg == 1) {
617 char *cwd = xgetcwd();
618 setenv(GIT_DIR_ENVIRONMENT, cwd, argc > 0);
619 free(cwd);
620 }
621
622 if (object_format) {
623 hash_algo = hash_algo_by_name(object_format);
624 if (hash_algo == GIT_HASH_UNKNOWN)
625 die(_("unknown hash algorithm '%s'"), object_format);
626 }
627
628 if (init_shared_repository != -1)
629 set_shared_repository(init_shared_repository);
630
631 /*
632 * GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
633 * without --bare. Catch the error early.
634 */
635 git_dir = xstrdup_or_null(getenv(GIT_DIR_ENVIRONMENT));
636 work_tree = xstrdup_or_null(getenv(GIT_WORK_TREE_ENVIRONMENT));
637 if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
638 die(_("%s (or --work-tree=<directory>) not allowed without "
639 "specifying %s (or --git-dir=<directory>)"),
640 GIT_WORK_TREE_ENVIRONMENT,
641 GIT_DIR_ENVIRONMENT);
642
643 /*
644 * Set up the default .git directory contents
645 */
646 if (!git_dir)
647 git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
648
649 /*
650 * When --separate-git-dir is used inside a linked worktree, take
651 * care to ensure that the common .git/ directory is relocated, not
652 * the worktree-specific .git/worktrees/<id>/ directory.
653 */
654 if (real_git_dir) {
655 int err;
656 const char *p;
657 struct strbuf sb = STRBUF_INIT;
658
659 p = read_gitfile_gently(git_dir, &err);
660 if (p && get_common_dir(&sb, p)) {
661 struct strbuf mainwt = STRBUF_INIT;
662
663 strbuf_addbuf(&mainwt, &sb);
664 strbuf_strip_suffix(&mainwt, "/.git");
665 if (chdir(mainwt.buf) < 0)
666 die_errno(_("cannot chdir to %s"), mainwt.buf);
667 strbuf_release(&mainwt);
668 git_dir = strbuf_detach(&sb, NULL);
669 }
670 strbuf_release(&sb);
671 }
672
673 if (is_bare_repository_cfg < 0)
674 is_bare_repository_cfg = guess_repository_type(git_dir);
675
676 if (!is_bare_repository_cfg) {
677 const char *git_dir_parent = strrchr(git_dir, '/');
678 if (git_dir_parent) {
679 char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
680 git_work_tree_cfg = real_pathdup(rel, 1);
681 free(rel);
682 }
683 if (!git_work_tree_cfg)
684 git_work_tree_cfg = xgetcwd();
685 if (work_tree)
686 set_git_work_tree(work_tree);
687 else
688 set_git_work_tree(git_work_tree_cfg);
689 if (access(get_git_work_tree(), X_OK))
690 die_errno (_("Cannot access work tree '%s'"),
691 get_git_work_tree());
692 }
693 else {
694 if (real_git_dir)
695 die(_("--separate-git-dir incompatible with bare repository"));
696 if (work_tree)
697 set_git_work_tree(work_tree);
698 }
699
700 UNLEAK(real_git_dir);
701 UNLEAK(git_dir);
702 UNLEAK(work_tree);
703
704 flags |= INIT_DB_EXIST_OK;
705 return init_db(git_dir, real_git_dir, template_dir, hash_algo,
706 initial_branch, flags);
707 }