aboutsummaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-11-26 22:32:35 +0700
committerJunio C Hamano <gitster@pobox.com>2010-12-22 14:34:24 -0800
commite6aea2dba27798f5d1eca32435e407541caca400 (patch)
tree7372724ac020f4c03f78df146c64080e60748b79 /environment.c
parent337e51cedfdf1f98e1c151b72f06c7ca8bcea0fd (diff)
downloadgit-e6aea2dba27798f5d1eca32435e407541caca400.tar.gz
git-e6aea2dba27798f5d1eca32435e407541caca400.tar.xz
setup: limit get_git_work_tree()'s to explicit setup case only
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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c10
1 files changed, 8 insertions, 2 deletions
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 */