提交 f2bd2314 编写于 作者: J Junio C Hamano

Merge branch 'jk/die-on-bogus-worktree-late' into maint

The setup code used to die when core.bare and core.worktree are set
inconsistently, even for commands that do not need working tree.

* jk/die-on-bogus-worktree-late:
  setup_git_directory: delay core.bare/core.worktree errors
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
static int inside_git_dir = -1; static int inside_git_dir = -1;
static int inside_work_tree = -1; static int inside_work_tree = -1;
static int work_tree_config_is_bogus;
/* /*
* The input parameter must contain an absolute path, and it must already be * The input parameter must contain an absolute path, and it must already be
...@@ -286,6 +287,10 @@ void setup_work_tree(void) ...@@ -286,6 +287,10 @@ void setup_work_tree(void)
if (initialized) if (initialized)
return; return;
if (work_tree_config_is_bogus)
die("unable to set up work tree using invalid config");
work_tree = get_git_work_tree(); work_tree = get_git_work_tree();
git_dir = get_git_dir(); git_dir = get_git_dir();
if (!is_absolute_path(git_dir)) if (!is_absolute_path(git_dir))
...@@ -422,8 +427,11 @@ static const char *setup_explicit_git_dir(const char *gitdirenv, ...@@ -422,8 +427,11 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
if (work_tree_env) if (work_tree_env)
set_git_work_tree(work_tree_env); set_git_work_tree(work_tree_env);
else if (is_bare_repository_cfg > 0) { else if (is_bare_repository_cfg > 0) {
if (git_work_tree_cfg) /* #22.2, #30 */ if (git_work_tree_cfg) {
die("core.bare and core.worktree do not make sense"); /* #22.2, #30 */
warning("core.bare and core.worktree do not make sense");
work_tree_config_is_bogus = 1;
}
/* #18, #26 */ /* #18, #26 */
set_git_dir(gitdirenv); set_git_dir(gitdirenv);
......
...@@ -598,11 +598,20 @@ test_expect_success '#20b/c: core.worktree and core.bare conflict' ' ...@@ -598,11 +598,20 @@ test_expect_success '#20b/c: core.worktree and core.bare conflict' '
mkdir -p 20b/.git/wt/sub && mkdir -p 20b/.git/wt/sub &&
( (
cd 20b/.git && cd 20b/.git &&
test_must_fail git symbolic-ref HEAD >/dev/null test_must_fail git status >/dev/null
) 2>message && ) 2>message &&
grep "core.bare and core.worktree" message grep "core.bare and core.worktree" message
' '
test_expect_success '#20d: core.worktree and core.bare OK when working tree not needed' '
setup_repo 20d non-existent "" true &&
mkdir -p 20d/.git/wt/sub &&
(
cd 20d/.git &&
git config foo.bar value
)
'
# Case #21: core.worktree/GIT_WORK_TREE overrides core.bare' ' # Case #21: core.worktree/GIT_WORK_TREE overrides core.bare' '
test_expect_success '#21: setup, core.worktree warns before overriding core.bare' ' test_expect_success '#21: setup, core.worktree warns before overriding core.bare' '
setup_repo 21 non-existent "" unset && setup_repo 21 non-existent "" unset &&
...@@ -611,7 +620,7 @@ test_expect_success '#21: setup, core.worktree warns before overriding core.bare ...@@ -611,7 +620,7 @@ test_expect_success '#21: setup, core.worktree warns before overriding core.bare
cd 21/.git && cd 21/.git &&
GIT_WORK_TREE="$here/21" && GIT_WORK_TREE="$here/21" &&
export GIT_WORK_TREE && export GIT_WORK_TREE &&
git symbolic-ref HEAD >/dev/null git status >/dev/null
) 2>message && ) 2>message &&
! test -s message ! test -s message
...@@ -700,13 +709,13 @@ test_expect_success '#22.2: core.worktree and core.bare conflict' ' ...@@ -700,13 +709,13 @@ test_expect_success '#22.2: core.worktree and core.bare conflict' '
cd 22/.git && cd 22/.git &&
GIT_DIR=. && GIT_DIR=. &&
export GIT_DIR && export GIT_DIR &&
test_must_fail git symbolic-ref HEAD 2>result test_must_fail git status 2>result
) && ) &&
( (
cd 22 && cd 22 &&
GIT_DIR=.git && GIT_DIR=.git &&
export GIT_DIR && export GIT_DIR &&
test_must_fail git symbolic-ref HEAD 2>result test_must_fail git status 2>result
) && ) &&
grep "core.bare and core.worktree" 22/.git/result && grep "core.bare and core.worktree" 22/.git/result &&
grep "core.bare and core.worktree" 22/result grep "core.bare and core.worktree" 22/result
...@@ -752,9 +761,8 @@ test_expect_success '#28: core.worktree and core.bare conflict (gitfile case)' ' ...@@ -752,9 +761,8 @@ test_expect_success '#28: core.worktree and core.bare conflict (gitfile case)' '
setup_repo 28 "$here/28" gitfile true && setup_repo 28 "$here/28" gitfile true &&
( (
cd 28 && cd 28 &&
test_must_fail git symbolic-ref HEAD test_must_fail git status
) 2>message && ) 2>message &&
! grep "^warning:" message &&
grep "core.bare and core.worktree" message grep "core.bare and core.worktree" message
' '
...@@ -766,7 +774,7 @@ test_expect_success '#29: setup' ' ...@@ -766,7 +774,7 @@ test_expect_success '#29: setup' '
cd 29 && cd 29 &&
GIT_WORK_TREE="$here/29" && GIT_WORK_TREE="$here/29" &&
export GIT_WORK_TREE && export GIT_WORK_TREE &&
git symbolic-ref HEAD >/dev/null git status
) 2>message && ) 2>message &&
! test -s message ! test -s message
' '
...@@ -777,7 +785,7 @@ test_expect_success '#30: core.worktree and core.bare conflict (gitfile version) ...@@ -777,7 +785,7 @@ test_expect_success '#30: core.worktree and core.bare conflict (gitfile version)
setup_repo 30 "$here/30" gitfile true && setup_repo 30 "$here/30" gitfile true &&
( (
cd 30 && cd 30 &&
test_must_fail env GIT_DIR=.git git symbolic-ref HEAD 2>result test_must_fail env GIT_DIR=.git git status 2>result
) && ) &&
grep "core.bare and core.worktree" 30/result grep "core.bare and core.worktree" 30/result
' '
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册