]> git.ipfire.org Git - thirdparty/git.git/commit
config: add "worktree" and "worktree/i" includeIf conditions
authorChen Linxuan <me@black-desk.cn>
Wed, 13 May 2026 08:08:18 +0000 (16:08 +0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 May 2026 08:19:21 +0000 (17:19 +0900)
commitb542e46bdbcbfb359d1f6d5dcc5538d3f5cafa62
treed9f02f80c22621dd0ca7da31502001be671b60cb
parent67a8e425847d3ffae119b35443714fcb0fb4cdeb
config: add "worktree" and "worktree/i" includeIf conditions

The includeIf mechanism already supports matching on the .git
directory path (gitdir) and the currently checked out branch
(onbranch).  But in multi-worktree setups the .git directory of a
linked worktree points into the main repository's .git/worktrees/
area, which makes gitdir patterns cumbersome when one wants to
include config based on the working tree's checkout path instead.

Introduce two new condition keywords:

  - worktree:<pattern> matches the realpath of the current worktree's
    working directory (i.e. repo_get_work_tree()) against a glob
    pattern.  This is the path returned by git rev-parse
    --show-toplevel.

  - worktree/i:<pattern> is the case-insensitive variant.

The implementation reuses the include_by_path() helper introduced in
the previous commit, passing the worktree path in place of the
gitdir.  The condition never matches in bare repositories (where
there is no worktree) or during early config reading (where no
repository is available).

Add documentation describing the new conditions, including a comparison
with extensions.worktreeConfig.  Add tests covering bare repositories,
multiple worktrees, symlinked worktree paths, case-insensitive matching,
early config reading, and non-repository scenarios.

Signed-off-by: Chen Linxuan <me@black-desk.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.adoc
config.c
t/t1305-config-include.sh