]> git.99rst.org Git - git.git/commit
config: add "worktree" and "worktree/i" includeIf conditions
authorChen Linxuan <redacted>
Fri, 10 Jul 2026 06:43:30 +0000 (14:43 +0800)
committerJunio C Hamano <redacted>
Fri, 10 Jul 2026 15:19:15 +0000 (08:19 -0700)
commit5004829756596498a20305b3fce8387629396835
treeeeb0918a190fbee15480559bd8f00447820d918c
parent52bd2ff2741e376ab8b92c354ba64bdf9d1c2c0a
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 and a note that worktree matching currently
uses the realpath-resolved worktree location.  Add tests covering bare
repositories, multiple worktrees, realpath-resolved symlinked worktree
paths, case-sensitive and case-insensitive matching, early config reading,
and non-repository scenarios.

Signed-off-by: Chen Linxuan <redacted>
Signed-off-by: Junio C Hamano <redacted>
Documentation/config.adoc
config.c
t/t1305-config-include.sh
git clone https://git.99rst.org/PROJECT