From e6aea2dba27798f5d1eca32435e407541caca400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 26 Nov 2010 22:32:35 +0700 Subject: setup: limit get_git_work_tree()'s to explicit setup case only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit get_git_work_tree() takes input as core.worktree, core.bare, GIT_WORK_TREE and decides correct worktree setting. Unfortunately it does not do its job well. core.worktree and GIT_WORK_TREE should only be taken into account, if GIT_DIR is set (which is handled by setup_explicit_git_dir). For other setup cases, only core.bare matters. Add a temporary variable setup_explicit to adjust get_git_work_tree() behavior as such. This variable will be gone once setup_* rework is done. Also remove is_bare_repository_cfg check in set_git_work_tree() to ease the rework. We are going to check for core.bare and core.worktree early before setting worktree. For example, if core.bare is true, no need to set worktree. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- environment.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'environment.c') diff --git a/environment.c b/environment.c index de5581fe5..d811049a7 100644 --- a/environment.c +++ b/environment.c @@ -137,8 +137,6 @@ static int git_work_tree_initialized; */ void set_git_work_tree(const char *new_work_tree) { - if (is_bare_repository_cfg >= 0) - die("cannot set work tree after initialization"); git_work_tree_initialized = 1; free(work_tree); work_tree = xstrdup(make_absolute_path(new_work_tree)); @@ -147,6 +145,14 @@ void set_git_work_tree(const char *new_work_tree) const char *get_git_work_tree(void) { + if (startup_info && !startup_info->setup_explicit) { + if (is_bare_repository_cfg == 1) + return NULL; + if (work_tree) + is_bare_repository_cfg = 0; + return work_tree; + } + if (!git_work_tree_initialized) { work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT); /* core.bare = true overrides implicit and config work tree */ -- cgit v1.2.1