git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v6 2/2] config: add "worktree" and "worktree/i" includeIf conditions

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 3, 2026, 11:02 UTC
Message-ID
<akeW4yFC8uuu2o8a@pks.im>
In-Reply-To
<20260703-includeif-worktree-v6-2-a13893ad9a7f@black-desk.cn>
On Fri, Jul 03, 2026 at 11:13:18AM +0800, Chen Linxuan via B4 Relay wrote:
Show 5 quoted lines
> diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh
> index f3892578e4ff..4e840dfdb35b 100755
> --- a/t/t1305-config-include.sh
> +++ b/t/t1305-config-include.sh
> @@ -396,4 +396,132 @@ test_expect_success 'onbranch without repository but explicit nonexistent Git di
[snip]
Show 14 quoted lines
> +test_expect_success SYMLINKS 'conditional include, worktree resolves symlinks' '
> +	mkdir real-wt &&
> +	ln -s real-wt link-wt &&
> +	git init link-wt/repo &&
> +	(
> +		cd link-wt/repo &&
> +		# repo->worktree resolves symlinks, so use real path in pattern
> +		echo "[includeIf \"worktree:**/real-wt/repo\"]path=bar-link" >>.git/config &&
> +		echo "[test]wtlink=2" >.git/bar-link &&
> +		echo 2 >expect &&
> +		git config test.wtlink >actual &&
> +		test_cmp expect actual
> +	)
> +'

Okay, this covers one scenario. But with "gitdir:" we're actually able to use both the symlinked and the real location:

    test_expect_success SYMLINKS 'conditional include, worktree matching symlink' '
    	mkdir sym-real &&
    	ln -s sym-real sym-link &&
    	git init sym-link/repo &&
    	(
    		cd sym-link/repo &&
    		link_path="$(pwd)" &&
    		real_path="$(test-tool path-utils real_path "$link_path")" &&
    		cat >>.git/config <<-EOF &&
    		[includeIf "gitdir:$link_path/.git"]
    			path = gitdir-link
    		[includeIf "gitdir:$real_path/.git"]
    			path = gitdir-real
    		[includeIf "worktree:$link_path"]
    			path = worktree-link
    		[includeIf "worktree:$real_path"]
    			path = worktree-real
    		EOF
    		echo "[test]gitdirlink=1" >.git/gitdir-link &&
    		echo "[test]gitdirreal=1" >.git/gitdir-real &&
    		echo "[test]worktreelink=1" >.git/worktree-link &&
    		echo "[test]worktreereal=1" >.git/worktree-real &&
    		git config get test.gitdirlink &&
    		git config get test.gitdirreal &&
    		git config get test.worktreereal &&
    		test_must_fail git config test.worktreelink
    	)
    '

The last call to git-config(1) fails, which is inconsistent with how resolve the path for "gitdir".

Other than that I didn't have anything to add, thanks!
Patrick
Previous: Junio C HamanoNext: Chen Linxuan
Message 5 of 8 in “includeIf: add "worktree" condition for matching working tree path”
  1. 0/2 includeIf: add "worktree" condition for matching working tree pathChen Linxuan via B4 Relay, Jul 3, 2026
  2. 1/2 config: refactor include_by_gitdir() into include_by_path()Chen Linxuan via B4 Relay, Jul 3, 2026
  3. 2/2 config: add "worktree" and "worktree/i" includeIf conditionsChen Linxuan via B4 Relay, Jul 3, 2026
  4. Junio C HamanoJul 3, 2026
  5. Patrick SteinhardtJul 3, 2026
  6. Chen LinxuanJul 6, 2026
  7. Patrick SteinhardtJul 7, 2026
  8. Junio C HamanoJul 7, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.