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