Skip to content

Commit f2bd231

Browse files
committed
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
2 parents 6356003 + fada767 commit f2bd231

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
@@ -286,6 +287,10 @@ void setup_work_tree(void)
286287

287288
if (initialized)
288289
return;
290+
291+
if (work_tree_config_is_bogus)
292+
die("unable to set up work tree using invalid config");
293+
289294
work_tree = get_git_work_tree();
290295
git_dir = get_git_dir();
291296
if (!is_absolute_path(git_dir))
@@ -422,8 +427,11 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
422427
if (work_tree_env)
423428
set_git_work_tree(work_tree_env);
424429
else if (is_bare_repository_cfg > 0) {
425-
if (git_work_tree_cfg) /* #22.2, #30 */
426-
die("core.bare and core.worktree do not make sense");
430+
if (git_work_tree_cfg) {
431+
/* #22.2, #30 */
432+
warning("core.bare and core.worktree do not make sense");
433+
work_tree_config_is_bogus = 1;
434+
}
427435

428436
/* #18, #26 */
429437
set_git_dir(gitdirenv);

t/t1510-repo-setup.sh

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

606+
test_expect_success '#20d: core.worktree and core.bare OK when working tree not needed' '
607+
setup_repo 20d non-existent "" true &&
608+
mkdir -p 20d/.git/wt/sub &&
609+
(
610+
cd 20d/.git &&
611+
git config foo.bar value
612+
)
613+
'
614+
606615
# Case #21: core.worktree/GIT_WORK_TREE overrides core.bare' '
607616
test_expect_success '#21: setup, core.worktree warns before overriding core.bare' '
608617
setup_repo 21 non-existent "" unset &&
@@ -611,7 +620,7 @@ test_expect_success '#21: setup, core.worktree warns before overriding core.bare
611620
cd 21/.git &&
612621
GIT_WORK_TREE="$here/21" &&
613622
export GIT_WORK_TREE &&
614-
git symbolic-ref HEAD >/dev/null
623+
git status >/dev/null
615624
) 2>message &&
616625
! test -s message
617626
@@ -700,13 +709,13 @@ test_expect_success '#22.2: core.worktree and core.bare conflict' '
700709
cd 22/.git &&
701710
GIT_DIR=. &&
702711
export GIT_DIR &&
703-
test_must_fail git symbolic-ref HEAD 2>result
712+
test_must_fail git status 2>result
704713
) &&
705714
(
706715
cd 22 &&
707716
GIT_DIR=.git &&
708717
export GIT_DIR &&
709-
test_must_fail git symbolic-ref HEAD 2>result
718+
test_must_fail git status 2>result
710719
) &&
711720
grep "core.bare and core.worktree" 22/.git/result &&
712721
grep "core.bare and core.worktree" 22/result
@@ -752,9 +761,8 @@ test_expect_success '#28: core.worktree and core.bare conflict (gitfile case)' '
752761
setup_repo 28 "$here/28" gitfile true &&
753762
(
754763
cd 28 &&
755-
test_must_fail git symbolic-ref HEAD
764+
test_must_fail git status
756765
) 2>message &&
757-
! grep "^warning:" message &&
758766
grep "core.bare and core.worktree" message
759767
'
760768

@@ -766,7 +774,7 @@ test_expect_success '#29: setup' '
766774
cd 29 &&
767775
GIT_WORK_TREE="$here/29" &&
768776
export GIT_WORK_TREE &&
769-
git symbolic-ref HEAD >/dev/null
777+
git status
770778
) 2>message &&
771779
! test -s message
772780
'
@@ -777,7 +785,7 @@ test_expect_success '#30: core.worktree and core.bare conflict (gitfile version)
777785
setup_repo 30 "$here/30" gitfile true &&
778786
(
779787
cd 30 &&
780-
test_must_fail env GIT_DIR=.git git symbolic-ref HEAD 2>result
788+
test_must_fail env GIT_DIR=.git git status 2>result
781789
) &&
782790
grep "core.bare and core.worktree" 30/result
783791
'

0 commit comments

Comments
 (0)