| 2810 | } |
| 2811 | |
| 2812 | int init_db(struct repository *repo, |
| 2813 | const char *git_dir, const char *real_git_dir, |
| 2814 | const char *template_dir, int hash, |
| 2815 | enum ref_storage_format ref_storage_format, |
| 2816 | const char *initial_branch, |
| 2817 | int init_shared_repository, unsigned int flags) |
| 2818 | { |
| 2819 | int reinit; |
| 2820 | int exist_ok = flags & INIT_DB_EXIST_OK; |
| 2821 | char *original_git_dir = real_pathdup(git_dir, 1); |
| 2822 | struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; |
| 2823 | |
| 2824 | if (real_git_dir) { |
| 2825 | struct stat st; |
| 2826 | |
| 2827 | if (!exist_ok && !stat(git_dir, &st)) |
| 2828 | die(_("%s already exists"), git_dir); |
| 2829 | |
| 2830 | if (!exist_ok && !stat(real_git_dir, &st)) |
| 2831 | die(_("%s already exists"), real_git_dir); |
| 2832 | |
| 2833 | set_git_dir(repo, real_git_dir, 1); |
| 2834 | git_dir = repo_get_git_dir(repo); |
| 2835 | separate_git_dir(git_dir, original_git_dir); |
| 2836 | } |
| 2837 | else { |
| 2838 | set_git_dir(repo, git_dir, 1); |
| 2839 | git_dir = repo_get_git_dir(repo); |
| 2840 | } |
| 2841 | startup_info->have_repository = 1; |
| 2842 | |
| 2843 | /* |
| 2844 | * Check to see if the repository version is right. |
| 2845 | * Note that a newly created repository does not have |
| 2846 | * config file, so this will not fail. What we are catching |
| 2847 | * is an attempt to reinitialize new repository with an old tool. |
| 2848 | */ |
| 2849 | check_and_apply_repository_format(repo, &repo_fmt, |
| 2850 | APPLY_REPOSITORY_FORMAT_HONOR_ENV); |
| 2851 | |
| 2852 | repository_format_configure(repo, &repo_fmt, hash, ref_storage_format); |
| 2853 | |
| 2854 | /* |
| 2855 | * Ensure `core.hidedotfiles` is processed. This must happen after we |
| 2856 | * have set up the repository format such that we can evaluate |
| 2857 | * includeIf conditions correctly in the case of re-initialization. |
| 2858 | */ |
| 2859 | repo_config(repo, git_default_core_config, NULL); |
| 2860 | |
| 2861 | safe_create_dir(repo, git_dir, 0); |
| 2862 | |
| 2863 | reinit = create_default_files(repo, template_dir, original_git_dir, |
| 2864 | &repo_fmt, init_shared_repository); |
| 2865 | |
| 2866 | if (!(flags & INIT_DB_SKIP_REFDB)) |
| 2867 | create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET); |
| 2868 | create_object_directory(repo); |
| 2869 |
no test coverage detected