Skip to content

Commit 103b6f9

Browse files
committed
Merge branch 'jk/die-on-bogus-worktree-late'
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
2 parents c7ca442 + fada767 commit 103b6f9

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

setup.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
static int inside_git_dir = -1;
66
static int inside_work_tree = -1;
7+
static int work_tree_config_is_bogus;
78

89
/*
910
* The input parameter must contain an absolute path, and it must already be
@@ -327,6 +328,10 @@ void setup_work_tree(void)
327328

328329
if (initialized)
329330
return;
331+
332+
if (work_tree_config_is_bogus)
333+
die("unable to set up work tree using invalid config");
334+
330335
work_tree = get_git_work_tree();
331336
git_dir = get_git_dir();
332337
if (!is_absolute_path(git_dir))
@@ -495,8 +500,11 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
495500
if (work_tree_env)
496501
set_git_work_tree(work_tree_env);
497502
else if (is_bare_repository_cfg > 0) {
498-
if (git_work_tree_cfg) /* #22.2, #30 */
499-
die("core.bare and core.worktree do not make sense");
503+
if (git_work_tree_cfg) {
504+
/* #22.2, #30 */
505+
warning("core.bare and core.worktree do not make sense");
506+
work_tree_config_is_bogus = 1;
507+
}
500508

501509
/* #18, #26 */
502510
set_git_dir(gitdirenv);

t/t1510-repo-setup.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,20 @@ test_expect_success '#20b/c: core.worktree and core.bare conflict' '
599599
mkdir -p 20b/.git/wt/sub &&
600600
(
601601
cd 20b/.git &&
602-
test_must_fail git symbolic-ref HEAD >/dev/null
602+
test_must_fail git status >/dev/null
603603
) 2>message &&
604604
grep "core.bare and core.worktree" message
605605
'
606606

607+
test_expect_success '#20d: core.worktree and core.bare OK when working tree not needed' '
608+
setup_repo 20d non-existent "" true &&
609+
mkdir -p 20d/.git/wt/sub &&
610+
(
611+
cd 20d/.git &&
612+
git config foo.bar value
613+
)
614+
'
615+
607616
# Case #21: core.worktree/GIT_WORK_TREE overrides core.bare' '
608617
test_expect_success '#21: setup, core.worktree warns before overriding core.bare' '
609618
setup_repo 21 non-existent "" unset &&
@@ -612,7 +621,7 @@ test_expect_success '#21: setup, core.worktree warns before overriding core.bare
612621
cd 21/.git &&
613622
GIT_WORK_TREE="$here/21" &&
614623
export GIT_WORK_TREE &&
615-
git symbolic-ref HEAD >/dev/null
624+
git status >/dev/null
616625
) 2>message &&
617626
! test -s message
618627
@@ -701,13 +710,13 @@ test_expect_success '#22.2: core.worktree and core.bare conflict' '
701710
cd 22/.git &&
702711
GIT_DIR=. &&
703712
export GIT_DIR &&
704-
test_must_fail git symbolic-ref HEAD 2>result
713+
test_must_fail git status 2>result
705714
) &&
706715
(
707716
cd 22 &&
708717
GIT_DIR=.git &&
709718
export GIT_DIR &&
710-
test_must_fail git symbolic-ref HEAD 2>result
719+
test_must_fail git status 2>result
711720
) &&
712721
grep "core.bare and core.worktree" 22/.git/result &&
713722
grep "core.bare and core.worktree" 22/result
@@ -753,9 +762,8 @@ test_expect_success '#28: core.worktree and core.bare conflict (gitfile case)' '
753762
setup_repo 28 "$here/28" gitfile true &&
754763
(
755764
cd 28 &&
756-
test_must_fail git symbolic-ref HEAD
765+
test_must_fail git status
757766
) 2>message &&
758-
! grep "^warning:" message &&
759767
grep "core.bare and core.worktree" message
760768
'
761769

@@ -767,7 +775,7 @@ test_expect_success '#29: setup' '
767775
cd 29 &&
768776
GIT_WORK_TREE="$here/29" &&
769777
export GIT_WORK_TREE &&
770-
git symbolic-ref HEAD >/dev/null
778+
git status
771779
) 2>message &&
772780
! test -s message
773781
'
@@ -778,7 +786,7 @@ test_expect_success '#30: core.worktree and core.bare conflict (gitfile version)
778786
setup_repo 30 "$here/30" gitfile true &&
779787
(
780788
cd 30 &&
781-
test_must_fail env GIT_DIR=.git git symbolic-ref HEAD 2>result
789+
test_must_fail env GIT_DIR=.git git status 2>result
782790
) &&
783791
grep "core.bare and core.worktree" 30/result
784792
'

0 commit comments

Comments
 (0)