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>
This commit is contained in:
committed by
Junio C Hamano
parent
337e51cedf
commit
e6aea2dba2
@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user