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