]> git.ipfire.org Git - thirdparty/git.git/commit
config: add "worktree" and "worktree/i" includeIf conditions
authorChen Linxuan <me@black-desk.cn>
Mon, 25 May 2026 03:20:09 +0000 (11:20 +0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 May 2026 12:19:43 +0000 (21:19 +0900)
commit8ab3dff1f1fb800fdc82c20f2526b8a55b4d37b5
tree18e6bd6342b7f0105f63db9608b0b2914d10dd49
parent0d208eafd1731ce535235e7dbd3bcf7ba44b6836
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-sensitive and
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