git-sh-setup.sh: make GIT_EDITOR/core.editor/VISUAL/EDITOR accept commands
[gitweb.git] / builtin-init-db.c
index d429ceda369ed4810ee42ae9aea6da105b795cc7..0d9b1e0559d04ebda464d2975aaf196378eeb481 100644 (file)
@@ -253,14 +253,16 @@ static int create_default_files(const char *git_dir, const char *template_path)
        }
        git_config_set("core.filemode", filemode ? "true" : "false");
 
-       if (is_bare_repository()) {
+       if (is_bare_repository())
                git_config_set("core.bare", "true");
-       }
        else {
+               const char *work_tree = get_git_work_tree();
                git_config_set("core.bare", "false");
                /* allow template config file to override the default */
                if (log_all_ref_updates == -1)
                    git_config_set("core.logallrefupdates", "true");
+               if (work_tree != git_work_tree_cfg)
+                       git_config_set("core.worktree", work_tree);
        }
        return reinit;
 }
@@ -297,6 +299,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
                        usage(init_db_usage);
        }
 
+       git_work_tree_cfg = xcalloc(PATH_MAX, 1);
+       if (!getcwd(git_work_tree_cfg, PATH_MAX))
+               die ("Cannot access current working directory.");
+       if (access(get_git_work_tree(), X_OK))
+               die ("Cannot access work tree '%s'", get_git_work_tree());
+
        /*
         * Set up the default .git directory contents
         */