From: Matthias Lederhofer Date: Mon, 12 Mar 2007 19:23:01 GMT Subject: [PATCH(amend)] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set Message-ID: <20070312192301.GB29327@moooo.ath.cx> In-Reply-To: <20070312115350.GA15179@moooo.ath.cx> Signed-off-by: Matthias Lederhofer --- It's much easier when $GIT_WORK_DIR is always interpreted relative to $GIT_DIR. --- builtin-init-db.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/builtin-init-db.c b/builtin-init-db.c index 4df9fd0..8d0065c 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -182,6 +182,7 @@ static int create_default_files(const char *git_dir, const char *template_path) char repo_version_string[10]; int reinit; int filemode; + const char *gitwd = getenv(GIT_WORKING_DIR_ENVIRONMENT); if (len > sizeof(path)-50) die("insane git directory %s", git_dir); @@ -252,10 +253,21 @@ 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() && !gitwd) { git_config_set("core.bare", "true"); } else { + if (gitwd) { + FILE *fp = NULL; + + path[len] = 0; + strcpy(path + len, "workdir"); + if (!(fp = fopen(path, "w"))) + die("Cannot open GIT_DIR/workdir"); + fprintf(fp, "%s\n", gitwd); + fclose(fp); + } + git_config_set("core.bare", "false"); /* allow template config file to override the default */ if (log_all_ref_updates == -1) -- 1.5.0.3.1007.g7ff7