@@ -309,6 +309,69 @@ test_expect_success SYMLINKS 'conditional include, gitdir matching symlink, icas
)
'
+test_expect_success 'conditional worktree include, unanchored' '
+ (
+ cd foo &&
+ # Must add a commit for worktree add
+ git commit --allow-empty --allow-empty-message &&
+ sed -i "/includeIf/,\$d" .git/config &&
+ git worktree add ../foo.wt &&
+ echo "[includeIf \"worktree:foo.wt\"]path=bar" >>.git/config &&
+ echo "[test]one=1" >.git/bar &&
+ cd ../foo.wt &&
+ echo 1 >expect &&
+ git config test.one >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'conditional worktree include, $HOME expansion' '
+ (
+ cd foo &&
+ echo "[includeIf \"worktree:~/foo.wt\"]path=bar2" >>.git/config &&
+ echo "[test]two=2" >.git/bar2 &&
+ cd ../foo.wt &&
+ echo 2 >expect &&
+ git config test.two >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'conditional worktree include, full pattern' '
+ (
+ cd foo &&
+ echo "[includeIf \"worktree:**/foo.wt\"]path=bar3" >>.git/config &&
+ echo "[test]three=3" >.git/bar3 &&
+ cd ../foo.wt &&
+ echo 3 >expect &&
+ git config test.three >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'conditional worktree include, relative path' '
+ echo "[includeIf \"worktree:./foo.wt\"]path=bar4" >>.gitconfig &&
+ echo "[test]four=4" >bar4 &&
+ (
+ cd foo.wt &&
+ echo 4 >expect &&
+ git config test.four >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'conditional worktree include, both unanchored, icase' '
+ (
+ cd foo &&
+ echo "[includeIf \"worktree/i:FOO.WT\"]path=bar5" >>.git/config &&
+ echo "[test]five=5" >.git/bar5 &&
+ cd ../foo.wt &&
+ echo 5 >expect &&
+ git config test.five >actual &&
+ test_cmp expect actual
+ )
+'
+
test_expect_success 'conditional include, onbranch' '
echo "[includeIf \"onbranch:foo-branch\"]path=bar9" >>.git/config &&
echo "[test]nine=9" >.git/bar9 &&
@@ -348,6 +411,24 @@ test_expect_success 'conditional include, onbranch, implicit /** for /' '
test_cmp expect actual
'
+test_expect_success 'conditional worktree include, onbranch' '
+ (
+ cd foo &&
+ sed -i "/includeIf/,\$d" .git/config &&
+ echo "[includeIf \"onbranch:foo.wt2\"]path=bar12" >>.git/config &&
+ echo "[test]twelve=12" >.git/bar12
+ ) &&
+ (
+ cd foo.wt &&
+ git checkout -b main &&
+ test_must_fail git config test.twelve &&
+ git checkout -b foo.wt2 &&
+ echo 12 >expect &&
+ git config test.twelve >actual &&
+ test_cmp expect actual
+ )
+'
+
test_expect_success 'include cycles are detected' '
git init --bare cycle &&
git -C cycle config include.path cycle &&