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
Junio C Hamano <gitster@pobox.com>
Date
Jul 3, 2026, 09:02 UTC
Message-ID
<xmqq1pdkjvi5.fsf@gitster.g>
In-Reply-To
<20260703-includeif-worktree-v6-2-a13893ad9a7f@black-desk.cn>

Chen Linxuan via B4 Relay <devnull+me.black-desk.cn@kernel.org> writes:

Show 13 quoted lines
> +`worktree`::
> +	The data that follows the keyword `worktree` and a colon is used as a
> +	glob pattern. If the working directory of the current worktree matches
> +	the pattern, the include condition is met.
> ...
> +can be set once in a global or system-level configuration file (e.g.
> +`~/.config/git/config`) and applies to all repositories at once based on
> +their worktree location.
> +
> +`worktree/i`::
> +	This is the same as `worktree` except that matching is done
> +	case-insensitively (e.g. on case-insensitive file systems)
> +
OK.  I briefly wondered if
        `worktree`::
        `worktree/i`::
                What follows the keyword `worktree` (or `worktree/i`) and a
                colon is used as a glob pattern. If the working directory of
                the current worktree matches (with `/i` the match is made
                case-insensitively) the pattern, ...

is easier for those who looks up 'worktree' to notice (without having to scroll too far to look at the other entry) that there is a case insensitive option available. As the construct used in this patch mimicks how `gitdir` and `gitdir/i` are described, however, I think such a change is better done as a separate topic, long after this patch lands and graduates to the master, to clean up both `gitdir` and `worktree` in the same commit. So let's leave it out of this topic.

Show 8 quoted lines
>  	else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
>  		return include_by_path(kvi, opts->git_dir, cond, cond_len, 1);
> +	else if (skip_prefix_mem(cond, cond_len, "worktree:", &cond, &cond_len))
> +		return include_by_path(kvi, inc->repo ? repo_get_work_tree(inc->repo) : NULL,
> +				       cond, cond_len, 0);
> +	else if (skip_prefix_mem(cond, cond_len, "worktree/i:", &cond, &cond_len))
> +		return include_by_path(kvi, inc->repo ? repo_get_work_tree(inc->repo) : NULL,
> +				       cond, cond_len, 1);
Fairly straight-forward.
Show 9 quoted lines
> +# Use a loose pattern so the "present in non-worktree cases" check works
> +# for Unix-style absolute paths and Windows paths like D:/a/git/...
> +test_expect_success 'conditional include, worktree without repository' '
> +	test_when_finished "rm -f .gitconfig config.inc" &&
> +	git config set -f .gitconfig "includeIf.worktree:**.path" config.inc &&
> +	git config set -f config.inc foo.bar baz &&
> +	git config get foo.bar &&
> +	test_must_fail nongit git config get foo.bar
> +'
This looks much easier to understand than the previous round.
Thanks.
Previous: Chen Linxuan via B4 RelayNext: Patrick Steinhardt
Message 4 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.