Thread (5 messages) 5 messages, 3 authors, 2d ago

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

From: Junio C Hamano <hidden>
Date: 2026-07-03 09:03:02

Chen Linxuan via B4 Relay [off-list ref]
writes:
+`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.
 	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.
+# 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help