Thread (45 messages) flat view 45 messages, 2 authors, 2016-06-15
DORMANTno replies

Revision v1 of 2 in this series.

Revisions (2)
  1. v1 [diff vs current]
  2. v1 current

[PATCH 3/7] setup: do not allow core.{bare,worktree} set at the same time

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:49:55
Subsystem: the rest · Maintainer: Linus Torvalds

---
 setup.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/setup.c b/setup.c
index 992a944..bbb430a 100644
--- a/setup.c
+++ b/setup.c
@@ -4,6 +4,8 @@
 static int inside_git_dir = -1;
 static int inside_work_tree = -1;
 
+static int has_core_worktree, has_core_bare;
+
 const char *prefix_path(const char *prefix, int len, const char *path)
 {
 	const char *orig = path;
@@ -245,6 +247,7 @@ void setup_work_tree(void)
 
 static int check_repository_format_gently(int *nongit_ok)
 {
+	has_core_worktree = has_core_bare = 0;
 	git_config(check_repository_format_version, NULL);
 	if (GIT_REPO_VERSION < repository_format_version) {
 		if (!nongit_ok)
@@ -256,6 +259,12 @@ static int check_repository_format_gently(int *nongit_ok)
 		*nongit_ok = -1;
 		return -1;
 	}
+	if (has_core_worktree && has_core_bare) {
+		if (!nongit_ok)
+			die("core.bare and core.worktree do not make sense");
+		*nongit_ok = -1;
+		return -1;
+	}
 	return 0;
 }
 
@@ -579,14 +588,20 @@ int check_repository_format_version(const char *var, const char *value, void *cb
 		shared_repository = git_config_perm(var, value);
 	else if (strcmp(var, "core.bare") == 0) {
 		is_bare_repository_cfg = git_config_bool(var, value);
-		if (is_bare_repository_cfg == 1)
+		if (is_bare_repository_cfg == 1) {
 			inside_work_tree = -1;
+			has_core_bare = 1;
+		}
 	} else if (strcmp(var, "core.worktree") == 0) {
 		if (!value)
 			return config_error_nonbool(var);
 		free(git_work_tree_cfg);
 		git_work_tree_cfg = xstrdup(value);
 		inside_work_tree = -1;
+
+		/* GIT_WORK_TREE overrides core.worktree */
+		if (!getenv(GIT_WORK_TREE_ENVIRONMENT))
+			has_core_worktree = 1;
 	}
 	return 0;
 }
-- 
1.7.0.2.445.gcbdb3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help