Thread (21 messages) flat view 21 messages, 4 authors, 2016-06-15

[PATCH(amend)] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set

From: Matthias Lederhofer <hidden>
Date: 2016-06-15 22:42:59
Subsystem: the rest · Maintainer: Linus Torvalds

Signed-off-by: Matthias Lederhofer <redacted>
---
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help