{"thread":{"id":"65956","subject":"[PATCH v7 2/3] repository: keep a symlink-preserving copy of the worktree path","startedAt":"2026-07-09T02:42:12Z","lastAt":"2026-07-09T20:40:23Z","messageCount":7,"participants":["Chen Linxuan via B4 Relay","Patrick Steinhardt","Junio C Hamano"],"isPatch":true,"patchVersion":7,"patchTotal":3},"messages":[{"id":"547554","messageId":"20260709-includeif-worktree-v7-2-e87e705e8df6@black-desk.cn","threadId":"65956","inReplyTo":"20260709-includeif-worktree-v7-0-e87e705e8df6@black-desk.cn","subject":"[PATCH v7 2/3] repository: keep a symlink-preserving copy of the worktree path","fromName":"Chen Linxuan via B4 Relay","fromEmail":"devnull+me.black-desk.cn@kernel.org","sentAt":"2026-07-09T02:41:42Z","receivedAt":"2026-07-09T02:42:12Z","isPatch":true,"body":"From: Chen Linxuan <me@black-desk.cn>\n\nrepo_set_worktree() stores only the realpath-resolved working directory in\nrepo->worktree, which discards any symlinks the user followed to get\nthere.  A follow-up commit needs to match that path the way \"gitdir:\"\ndoes, i.e. against both the real and the symlinked spelling, which\nrequires the original spelling to still be available.\n\nAdd repo->worktree_original, plus a repo_get_work_tree_original()\naccessor, to hold that symlink-preserving spelling.  repo_set_worktree()\nderives it from the given path; for the discovered-repository case, where\nthe setup code has already chdir()d to the worktree root by the time\nset_git_work_tree(repo, \".\") runs, logical_path_from_cwd() recovers it\nfrom $PWD instead.\n\nrepo->worktree is unchanged; repo_get_work_tree_original() has no callers\nyet and is wired up in the next commit.\n\nSigned-off-by: Chen Linxuan <me@black-desk.cn>\n---\n repository.c | 26 ++++++++++++++++++\n repository.h | 10 +++++++\n setup.c      | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 3 files changed, 121 insertions(+), 1 deletion(-)\n\ndiff --git a/repository.c b/repository.c\nindex 73d80bcffdf5..a29d55a6fcd3 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -149,6 +149,11 @@ const char *repo_get_work_tree(struct repository *repo)\n \treturn repo->worktree;\n }\n \n+const char *repo_get_work_tree_original(struct repository *repo)\n+{\n+\treturn repo->worktree_original;\n+}\n+\n static void repo_set_commondir(struct repository *repo,\n \t\t\t       const char *commondir)\n {\n@@ -252,8 +257,28 @@ static int repo_init_gitdir(struct repository *repo, const char *gitdir)\n \n void repo_set_worktree(struct repository *repo, const char *path)\n {\n+\tstruct strbuf worktree = STRBUF_INIT;\n+\n+\t/*\n+\t * Resolve the canonical path first. This preserves the historical\n+\t * behaviour for unusable worktree paths (e.g. a bogus GIT_WORK_TREE):\n+\t * strbuf_realpath() dies on error before we touch the copy below.\n+\t */\n \trepo->worktree = real_pathdup(path, 1);\n \n+\t/*\n+\t * Keep a symlink-preserving copy: absolute and normalized, but not\n+\t * realpath-resolved. Normalization can only fail for inputs that\n+\t * realpath tolerates (the rest already died above); fall back to the\n+\t * physical path so callers never see a NULL.\n+\t */\n+\tstrbuf_add_absolute_path(&worktree, path);\n+\tif (strbuf_normalize_path(&worktree) < 0)\n+\t\trepo->worktree_original = xstrdup(repo->worktree);\n+\telse\n+\t\trepo->worktree_original = strbuf_detach(&worktree, NULL);\n+\tstrbuf_release(&worktree);\n+\n \ttrace2_def_repo(repo);\n }\n \n@@ -379,6 +404,7 @@ void repo_clear(struct repository *repo)\n \tFREE_AND_NULL(repo->graft_file);\n \tFREE_AND_NULL(repo->index_file);\n \tFREE_AND_NULL(repo->worktree);\n+\tFREE_AND_NULL(repo->worktree_original);\n \tFREE_AND_NULL(repo->submodule_prefix);\n \tFREE_AND_NULL(repo->ref_storage_payload);\n \ndiff --git a/repository.h b/repository.h\nindex 7d649e32e7fa..f08fbfde4a07 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -114,6 +114,15 @@ struct repository {\n \t * A NULL value indicates that there is no working directory.\n \t */\n \tchar *worktree;\n+\t/*\n+\t * Symlink-preserving spelling of the working directory: absolute and\n+\t * normalized, but NOT realpath-resolved (keeps any symlinks the user\n+\t * followed to get here). Used by includeIf \"worktree:\" so it can match\n+\t * both the real and the symlinked spelling, the way \"gitdir:\" does.\n+\t * Falls back to the same value as \"worktree\" when no logical path is\n+\t * available.\n+\t */\n+\tchar *worktree_original;\n \tbool worktree_initialized;\n \tbool worktree_config_is_bogus;\n \n@@ -221,6 +230,7 @@ const char *repo_get_object_directory(struct repository *repo);\n const char *repo_get_index_file(struct repository *repo);\n const char *repo_get_graft_file(struct repository *repo);\n const char *repo_get_work_tree(struct repository *repo);\n+const char *repo_get_work_tree_original(struct repository *repo);\n \n /*\n  * Define a custom repository layout. Any field can be NULL, which\ndiff --git a/setup.c b/setup.c\nindex 0de56a074f7c..fbbeb95f99db 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -1213,12 +1213,94 @@ static const char *setup_explicit_git_dir(struct repository *repo,\n \treturn NULL;\n }\n \n+/*\n+ * Do \"a\" and \"b\" refer to the same filesystem entry? Both must report a\n+ * nonzero (dev,ino): some filesystems return (0,0) for unrelated paths,\n+ * which would otherwise look identical.\n+ */\n+static int same_entry(const char *a, const char *b)\n+{\n+\tstruct stat sa, sb;\n+\n+\tif (stat(a, &sa) || stat(b, &sb))\n+\t\treturn 0;\n+\treturn (sa.st_dev || sa.st_ino) &&\n+\t       sa.st_dev == sb.st_dev && sa.st_ino == sb.st_ino;\n+}\n+\n+/*\n+ * Recover the symlink-preserving spelling of the worktree root.\n+ *\n+ * strbuf_add_absolute_path() already consults $PWD to keep symlinks when\n+ * resolving a relative path, so set_git_work_tree()'s other callers get a\n+ * symlink-preserving worktree path for free.  This function exists for the\n+ * discovered-repository case: setup_git_directory_gently() chdir()s to the\n+ * worktree root *before* set_git_work_tree(repo, \".\") runs, so by the time\n+ * \".\" is resolved $PWD still names the caller's original directory and no\n+ * longer agrees with the physical cwd, and strbuf_add_absolute_path()\n+ * falls back to the realpath.  We close that gap by deriving the logical\n+ * root here, from $PWD, while we still have the original physical cwd and\n+ * the root offset in hand.\n+ *\n+ * \"cwd\" is the physical current directory (getcwd), and \"root_len\" is the\n+ * length of the worktree root within it; cwd->buf[root_len..] is therefore\n+ * the part of the path below the root (empty when git ran at the root).\n+ *\n+ * $PWD, maintained by the shell, may spell that same directory through\n+ * symlinks.  If we can confirm $PWD really names cwd's directory (same\n+ * device/inode) and that the below-root suffix matches, we swap the\n+ * physical root prefix for $PWD's prefix and keep the user's symlinks.\n+ * Only symlinks in the root prefix itself are preserved: the below-root\n+ * suffix is matched byte-for-byte, so a symlink below the root is not.\n+ *\n+ * Returns the allocated logical path, or NULL when $PWD is missing, already\n+ * physical, or untrustworthy.\n+ */\n+static char *logical_path_from_cwd(struct strbuf *cwd, int root_len)\n+{\n+\tconst char *pwd = getenv(\"PWD\");\n+\tsize_t suffix_len, pwd_len;\n+\tstruct strbuf path = STRBUF_INIT;\n+\n+\tif (!pwd || !is_absolute_path(pwd) || !strcmp(pwd, cwd->buf))\n+\t\treturn NULL;\n+\t/*\n+\t * $PWD is a plain environment variable: it can be set to anything,\n+\t * or left stale after a chdir.  Only borrow its symlink-preserving\n+\t * spelling once we prove it still points at the same directory as\n+\t * the physical cwd; otherwise give up and return NULL.\n+\t */\n+\tif (!same_entry(cwd->buf, pwd))\n+\t\treturn NULL;\n+\n+\t/*\n+\t * Drop the below-root suffix from $PWD.  It must match the physical\n+\t * suffix exactly; the only spelling difference we accept is in the\n+\t * root prefix -- i.e. the symlinks we want to preserve.\n+\t */\n+\tsuffix_len = cwd->len - root_len;\n+\tpwd_len = strlen(pwd);\n+\tif (suffix_len) {\n+\t\tconst char *suffix = cwd->buf + root_len;\n+\n+\t\tif (suffix_len > pwd_len ||\n+\t\t    fspathcmp(pwd + pwd_len - suffix_len, suffix))\n+\t\t\treturn NULL;\n+\t\tpwd_len -= suffix_len;\n+\t}\n+\n+\tstrbuf_add(&path, pwd, pwd_len);\n+\treturn strbuf_detach(&path, NULL);\n+}\n+\n static const char *setup_discovered_git_dir(struct repository *repo,\n \t\t\t\t\t    const char *gitdir,\n \t\t\t\t\t    struct strbuf *cwd, int offset,\n \t\t\t\t\t    struct repository_format *repo_fmt,\n \t\t\t\t\t    int *nongit_ok)\n {\n+\tchar *worktree = NULL;\n+\n \tif (check_repository_format_gently(gitdir, repo_fmt, nongit_ok))\n \t\treturn NULL;\n \n@@ -1245,7 +1327,9 @@ static const char *setup_discovered_git_dir(struct repository *repo,\n \t}\n \n \t/* #0, #1, #5, #8, #9, #12, #13 */\n-\tset_git_work_tree(repo, \".\");\n+\tworktree = logical_path_from_cwd(cwd, offset);\n+\tset_git_work_tree(repo, worktree ? worktree : \".\");\n+\tfree(worktree);\n \tif (strcmp(gitdir, DEFAULT_GIT_DIR_ENVIRONMENT))\n \t\tset_git_dir(repo, gitdir, 0);\n \tif (offset >= cwd->len)\n\n-- \n2.53.0\n\n\n"},{"id":"547555","messageId":"20260709-includeif-worktree-v7-0-e87e705e8df6@black-desk.cn","threadId":"65956","inReplyTo":null,"subject":"[PATCH v7 0/3] includeIf: add \"worktree\" condition for matching working tree path","fromName":"Chen Linxuan via B4 Relay","fromEmail":"devnull+me.black-desk.cn@kernel.org","sentAt":"2026-07-09T02:41:40Z","receivedAt":"2026-07-09T02:42:12Z","isPatch":true,"body":"The `includeIf` mechanism already supports matching on the `.git`\ndirectory path (`gitdir`) and the currently checked out branch\n(`onbranch`).  But in multi-worktree setups the `.git` directory of a\nlinked worktree points into the main repository's `.git/worktrees/`\narea, which makes `gitdir` patterns cumbersome when one wants to\ninclude config based on the working tree's checkout path instead.\n\nIntroduce two new condition keywords:\n\n  - `worktree:<pattern>` matches the working directory of the current\n    worktree against a glob pattern.\n  - `worktree/i:<pattern>` is the case-insensitive variant.\n\nSupported pattern features: glob wildcards, `**/` and `/**`, `~`\nexpansion, `./` relative paths, and trailing-`/` prefix matching.\nThe condition never matches in a bare repository.\n\nSigned-off-by: Chen Linxuan <me@black-desk.cn>\n---\nChanges in v7:\n- Preserve the symlinked spelling of the worktree path and match\n  includeIf \"worktree:\" against it, so the condition now matches both\n  the symlinked and the real path, consistent with \"gitdir:\"\n  (Patrick Steinhardt, v6 review).\n- Split the work into a preparatory commit that stores a non-realpath\n  worktree path and a follow-up that wires it into includeIf.\n- Extend symlink test coverage to subdirectories and linked worktrees.\n- Link to v6: https://lore.kernel.org/r/20260703-includeif-worktree-v6-0-a13893ad9a7f@black-desk.cn\n\nChanges in v6:\n- Rebase onto current `master` at Git 2.55.\n- Add an in-code comment explaining why the non-repository worktree\n  tests use the loose `**.path` pattern (suggested by Junio C Hamano).\n- Link to v5: https://lore.kernel.org/r/20260525-includeif-worktree-v5-0-1efe525d025a@black-desk.cn\n\nChanges in v5:\n- Fix Windows CI failure: use `**` glob pattern instead of `/` in the\n  \"worktree without repository\" tests, since `/` as a path pattern is\n  Unix-specific and does not match Windows paths.\n  Github CI pass: https://github.com/black-desk/git/actions/runs/26380466288\n- Add a test verifying case-sensitive matching by default, with the\n  `!CASE_INSENSITIVE_FS` prerequisite (suggested by Patrick Steinhardt).\n- Link to v4: https://lore.kernel.org/r/20260513-includeif-worktree-v4-0-f8e6212d1fba@black-desk.cn\n\nChanges in v4:\n- Deduplicate the worktree pattern documentation by referencing the\n  gitdir syntax instead of repeating the full pattern description\n  (suggested by Patrick Steinhardt).\n- Add documentation comparing includeIf \"worktree:\" with\n  extensions.worktreeConfig, including a concrete use case example\n  (suggested by Phillip Wood, Junio C Hamano).\n- Add a test verifying that the worktree condition does not match\n  during early config reading (suggested by Patrick Steinhardt).\n- Add tests for the non-repository (nongit) scenario (suggested by\n  Patrick Steinhardt).\n- Add a test for the case-insensitive \"worktree/i\" variant\n- Link to v3: https://lore.kernel.org/r/20260403-includeif-worktree-v3-0-109ce5782b03@black-desk.cn\n\nChanges in v3:\n- Apply Junio's suggestion.\n- Link to v2: https://lore.kernel.org/r/20260402-includeif-worktree-v2-0-36e339b898d7@black-desk.cn\n\nChanges in v2:\n\n- Add missing signed-off-by lines.\n- Link to v1: https://lore.kernel.org/r/20260401-includeif-worktree-v1-0-906db69f2c79@black-desk.cn\n\n---\nChen Linxuan (3):\n      config: refactor include_by_gitdir() into include_by_path()\n      repository: keep a symlink-preserving copy of the worktree path\n      config: add \"worktree\" and \"worktree/i\" includeIf conditions\n\n Documentation/config.adoc |  48 +++++++++++++\n config.c                  |  25 ++++---\n repository.c              |  26 +++++++\n repository.h              |  10 +++\n setup.c                   |  86 ++++++++++++++++++++++-\n t/t1305-config-include.sh | 171 ++++++++++++++++++++++++++++++++++++++++++++++\n 6 files changed, 354 insertions(+), 12 deletions(-)\n\nRange-diff versus v6:\n\n1:  faa10baf8deb = 1:  47ee82d6a5bd config: refactor include_by_gitdir() into include_by_path()\n-:  ------------ > 2:  367d61f9b55f repository: keep a symlink-preserving copy of the worktree path\n2:  ee81d7aeee56 ! 3:  67d9c31d3817 config: add \"worktree\" and \"worktree/i\" includeIf conditions\n    @@ Commit message\n     \n         Introduce two new condition keywords:\n     \n    -      - worktree:<pattern> matches the realpath of the current worktree's\n    -        working directory (i.e. repo_get_work_tree()) against a glob\n    -        pattern.  This is the path returned by git rev-parse\n    -        --show-toplevel.\n    +      - worktree:<pattern> matches the working directory of the current\n    +        worktree (the path returned by git rev-parse --show-toplevel)\n    +        against a glob pattern.\n     \n           - worktree/i:<pattern> is the case-insensitive variant.\n     \n    -    The implementation reuses the include_by_path() helper introduced in\n    -    the previous commit, passing the worktree path in place of the\n    -    gitdir.  The condition never matches in bare repositories (where\n    -    there is no worktree) or during early config reading (where no\n    -    repository is available).\n    +    The implementation reuses the include_by_path() helper, passing\n    +    repo_get_work_tree_original() (added in the previous commit; it keeps\n    +    the symlink-preserving spelling of the worktree path) in place of the\n    +    gitdir.  As with gitdir, include_by_path() then matches both the\n    +    realpath and the original spelling, so a pattern may use either.  The\n    +    condition never matches in bare repositories (where there is no\n    +    worktree) or during early config reading (where no repository is\n    +    available).\n     \n         Add documentation describing the new conditions, including a comparison\n         with extensions.worktreeConfig.  Add tests covering bare repositories,\n    -    multiple worktrees, symlinked worktree paths, case-sensitive and\n    -    case-insensitive matching, early config reading, and non-repository\n    -    scenarios.\n    +    multiple worktrees, symlinked and subdir-of-symlinked worktree paths,\n    +    case-sensitive and case-insensitive matching, early config reading,\n    +    and non-repository scenarios.\n     \n         Signed-off-by: Chen Linxuan <me@black-desk.cn>\n     \n    @@ config.c: static int include_condition_is_true(const struct key_value_info *kvi,\n      \telse if (skip_prefix_mem(cond, cond_len, \"gitdir/i:\", &cond, &cond_len))\n      \t\treturn include_by_path(kvi, opts->git_dir, cond, cond_len, 1);\n     +\telse if (skip_prefix_mem(cond, cond_len, \"worktree:\", &cond, &cond_len))\n    -+\t\treturn include_by_path(kvi, inc->repo ? repo_get_work_tree(inc->repo) : NULL,\n    ++\t\treturn include_by_path(kvi, inc->repo ? repo_get_work_tree_original(inc->repo) : NULL,\n     +\t\t\t\t       cond, cond_len, 0);\n     +\telse if (skip_prefix_mem(cond, cond_len, \"worktree/i:\", &cond, &cond_len))\n    -+\t\treturn include_by_path(kvi, inc->repo ? repo_get_work_tree(inc->repo) : NULL,\n    ++\t\treturn include_by_path(kvi, inc->repo ? repo_get_work_tree_original(inc->repo) : NULL,\n     +\t\t\t\t       cond, cond_len, 1);\n      \telse if (skip_prefix_mem(cond, cond_len, \"onbranch:\", &cond, &cond_len))\n      \t\treturn include_by_branch(inc, cond, cond_len);\n    @@ t/t1305-config-include.sh: test_expect_success 'onbranch without repository but\n     +\ttest_must_fail git -C wt-prefix/linked config test.linkedvar\n     +'\n     +\n    -+test_expect_success SYMLINKS 'conditional include, worktree resolves symlinks' '\n    -+\tmkdir real-wt &&\n    -+\tln -s real-wt link-wt &&\n    -+\tgit init link-wt/repo &&\n    ++test_expect_success SYMLINKS 'conditional include, worktree matching symlink' '\n    ++\tmkdir sym-real &&\n    ++\tln -s sym-real sym-link &&\n    ++\tgit init sym-link/repo &&\n     +\t(\n    -+\t\tcd link-wt/repo &&\n    -+\t\t# repo->worktree resolves symlinks, so use real path in pattern\n    -+\t\techo \"[includeIf \\\"worktree:**/real-wt/repo\\\"]path=bar-link\" >>.git/config &&\n    -+\t\techo \"[test]wtlink=2\" >.git/bar-link &&\n    -+\t\techo 2 >expect &&\n    -+\t\tgit config test.wtlink >actual &&\n    -+\t\ttest_cmp expect actual\n    ++\t\tcd sym-link/repo &&\n    ++\t\tlink_path=\"$(pwd)\" &&\n    ++\t\treal_path=\"$(test-tool path-utils real_path \"$link_path\")\" &&\n    ++\t\tcat >>.git/config <<-EOF &&\n    ++\t\t[includeIf \"gitdir:$link_path/.git\"]\n    ++\t\t\tpath = gitdir-link\n    ++\t\t[includeIf \"gitdir:$real_path/.git\"]\n    ++\t\t\tpath = gitdir-real\n    ++\t\t[includeIf \"worktree:$link_path\"]\n    ++\t\t\tpath = worktree-link\n    ++\t\t[includeIf \"worktree:$real_path\"]\n    ++\t\t\tpath = worktree-real\n    ++\t\tEOF\n    ++\t\techo \"[test]gitdirlink=1\" >.git/gitdir-link &&\n    ++\t\techo \"[test]gitdirreal=1\" >.git/gitdir-real &&\n    ++\t\techo \"[test]worktreelink=1\" >.git/worktree-link &&\n    ++\t\techo \"[test]worktreereal=1\" >.git/worktree-real &&\n    ++\t\tgit config get test.gitdirlink &&\n    ++\t\tgit config get test.gitdirreal &&\n    ++\t\tgit config get test.worktreelink &&\n    ++\t\tgit config get test.worktreereal &&\n    ++\t\t# from a subdirectory, the logical worktree path is recovered by\n    ++\t\t# stripping the below-root suffix, so both spellings still match\n    ++\t\tmkdir d &&\n    ++\t\tcd d &&\n    ++\t\tgit config get test.worktreelink &&\n    ++\t\tgit config get test.worktreereal\n    ++\t)\n    ++'\n    ++\n    ++test_expect_success SYMLINKS 'conditional include, worktree matching symlink of a linked worktree' '\n    ++\tgit init wt-main &&\n    ++\t( cd wt-main && test_commit initial ) &&\n    ++\tgit -C wt-main worktree add --detach ../wt-real &&\n    ++\tln -s wt-real wt-link &&\n    ++\twt_main=\"$(cd wt-main && pwd)\" &&\n    ++\t(\n    ++\t\tcd wt-link &&\n    ++\t\tlink_path=\"$(pwd)\" &&\n    ++\t\treal_path=\"$(test-tool path-utils real_path \"$link_path\")\" &&\n    ++\t\tcat >>\"$wt_main/.git/config\" <<-EOF &&\n    ++\t\t[includeIf \"worktree:$link_path\"]\n    ++\t\t\tpath = wt-link\n    ++\t\t[includeIf \"worktree:$real_path\"]\n    ++\t\t\tpath = wt-real\n    ++\t\tEOF\n    ++\t\techo \"[test]wtlink=1\" >\"$wt_main/.git/wt-link\" &&\n    ++\t\techo \"[test]wtreal=1\" >\"$wt_main/.git/wt-real\" &&\n    ++\t\ttest \"$(git config get test.wtlink)\" = \"1\" &&\n    ++\t\ttest \"$(git config get test.wtreal)\" = \"1\"\n     +\t)\n     +'\n     +\n\n---\nbase-commit: f85a7e662054a7b0d9070e432508831afa214b47\n\n\n"},{"id":"547556","messageId":"20260709-includeif-worktree-v7-1-e87e705e8df6@black-desk.cn","threadId":"65956","inReplyTo":"20260709-includeif-worktree-v7-0-e87e705e8df6@black-desk.cn","subject":"[PATCH v7 1/3] config: refactor include_by_gitdir() into include_by_path()","fromName":"Chen Linxuan via B4 Relay","fromEmail":"devnull+me.black-desk.cn@kernel.org","sentAt":"2026-07-09T02:41:41Z","receivedAt":"2026-07-09T02:42:12Z","isPatch":true,"body":"From: Chen Linxuan <me@black-desk.cn>\n\nThe include_by_gitdir() function matches the realpath of a given\npath against a glob pattern, but its interface is tightly coupled to\nthe gitdir condition: it takes a struct config_options *opts and\nextracts opts->git_dir internally.\n\nRefactor it into a more generic include_by_path() helper that takes\na const char *path parameter directly, and update the gitdir and\ngitdir/i callers to pass opts->git_dir explicitly.  No behavior\nchange, just preparing for the addition of a new worktree condition\nthat will reuse the same path-matching logic with a different path.\n\nSigned-off-by: Chen Linxuan <me@black-desk.cn>\n---\n config.c | 19 ++++++++-----------\n 1 file changed, 8 insertions(+), 11 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 6a0de86e3ae9..00eeeea370c9 100644\n--- a/config.c\n+++ b/config.c\n@@ -235,23 +235,20 @@ static int prepare_include_condition_pattern(const struct key_value_info *kvi,\n \treturn 0;\n }\n \n-static int include_by_gitdir(const struct key_value_info *kvi,\n-\t\t\t     const struct config_options *opts,\n-\t\t\t     const char *cond, size_t cond_len, int icase)\n+static int include_by_path(const struct key_value_info *kvi,\n+\t\t\t   const char *path,\n+\t\t\t   const char *cond, size_t cond_len, int icase)\n {\n \tstruct strbuf text = STRBUF_INIT;\n \tstruct strbuf pattern = STRBUF_INIT;\n \tsize_t prefix;\n \tint ret = 0;\n-\tconst char *git_dir;\n \tint already_tried_absolute = 0;\n \n-\tif (opts->git_dir)\n-\t\tgit_dir = opts->git_dir;\n-\telse\n+\tif (!path)\n \t\tgoto done;\n \n-\tstrbuf_realpath(&text, git_dir, 1);\n+\tstrbuf_realpath(&text, path, 1);\n \tstrbuf_add(&pattern, cond, cond_len);\n \tret = prepare_include_condition_pattern(kvi, &pattern, &prefix);\n \tif (ret < 0)\n@@ -284,7 +281,7 @@ static int include_by_gitdir(const struct key_value_info *kvi,\n \t\t * which'll do the right thing\n \t\t */\n \t\tstrbuf_reset(&text);\n-\t\tstrbuf_add_absolute_path(&text, git_dir);\n+\t\tstrbuf_add_absolute_path(&text, path);\n \t\talready_tried_absolute = 1;\n \t\tgoto again;\n \t}\n@@ -400,9 +397,9 @@ static int include_condition_is_true(const struct key_value_info *kvi,\n \tconst struct config_options *opts = inc->opts;\n \n \tif (skip_prefix_mem(cond, cond_len, \"gitdir:\", &cond, &cond_len))\n-\t\treturn include_by_gitdir(kvi, opts, cond, cond_len, 0);\n+\t\treturn include_by_path(kvi, opts->git_dir, cond, cond_len, 0);\n \telse if (skip_prefix_mem(cond, cond_len, \"gitdir/i:\", &cond, &cond_len))\n-\t\treturn include_by_gitdir(kvi, opts, cond, cond_len, 1);\n+\t\treturn include_by_path(kvi, opts->git_dir, cond, cond_len, 1);\n \telse if (skip_prefix_mem(cond, cond_len, \"onbranch:\", &cond, &cond_len))\n \t\treturn include_by_branch(inc, cond, cond_len);\n \telse if (skip_prefix_mem(cond, cond_len, \"hasconfig:remote.*.url:\", &cond,\n\n-- \n2.53.0\n\n\n"},{"id":"547557","messageId":"20260709-includeif-worktree-v7-3-e87e705e8df6@black-desk.cn","threadId":"65956","inReplyTo":"20260709-includeif-worktree-v7-0-e87e705e8df6@black-desk.cn","subject":"[PATCH v7 3/3] config: add \"worktree\" and \"worktree/i\" includeIf conditions","fromName":"Chen Linxuan via B4 Relay","fromEmail":"devnull+me.black-desk.cn@kernel.org","sentAt":"2026-07-09T02:41:43Z","receivedAt":"2026-07-09T02:42:12Z","isPatch":true,"body":"From: Chen Linxuan <me@black-desk.cn>\n\nThe includeIf mechanism already supports matching on the .git\ndirectory path (gitdir) and the currently checked out branch\n(onbranch).  But in multi-worktree setups the .git directory of a\nlinked worktree points into the main repository's .git/worktrees/\narea, which makes gitdir patterns cumbersome when one wants to\ninclude config based on the working tree's checkout path instead.\n\nIntroduce two new condition keywords:\n\n  - worktree:<pattern> matches the working directory of the current\n    worktree (the path returned by git rev-parse --show-toplevel)\n    against a glob pattern.\n\n  - worktree/i:<pattern> is the case-insensitive variant.\n\nThe implementation reuses the include_by_path() helper, passing\nrepo_get_work_tree_original() (added in the previous commit; it keeps\nthe symlink-preserving spelling of the worktree path) in place of the\ngitdir.  As with gitdir, include_by_path() then matches both the\nrealpath and the original spelling, so a pattern may use either.  The\ncondition never matches in bare repositories (where there is no\nworktree) or during early config reading (where no repository is\navailable).\n\nAdd documentation describing the new conditions, including a comparison\nwith extensions.worktreeConfig.  Add tests covering bare repositories,\nmultiple worktrees, symlinked and subdir-of-symlinked worktree paths,\ncase-sensitive and case-insensitive matching, early config reading,\nand non-repository scenarios.\n\nSigned-off-by: Chen Linxuan <me@black-desk.cn>\n---\n Documentation/config.adoc |  48 +++++++++++++\n config.c                  |   6 ++\n t/t1305-config-include.sh | 171 ++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 225 insertions(+)\n\ndiff --git a/Documentation/config.adoc b/Documentation/config.adoc\nindex 15b1a4d59347..c153da986e4a 100644\n--- a/Documentation/config.adoc\n+++ b/Documentation/config.adoc\n@@ -146,6 +146,46 @@ refer to linkgit:gitignore[5] for details. For convenience:\n \tThis is the same as `gitdir` except that matching is done\n \tcase-insensitively (e.g. on case-insensitive file systems)\n \n+`worktree`::\n+\tThe data that follows the keyword `worktree` and a colon is used as a\n+\tglob pattern. If the working directory of the current worktree matches\n+\tthe pattern, the include condition is met.\n++\n+The worktree location is the path where files are checked out (as returned\n+by `git rev-parse --show-toplevel`). This is different from `gitdir`, which\n+matches the `.git` directory path. In a linked worktree, the worktree path\n+is the directory where that worktree's files are located, not the main\n+repository's `.git` directory.\n++\n+The pattern uses the same glob syntax as `gitdir` (including `~/`, `./`,\n+`**/`, and trailing-`/` prefix matching). This condition will never match\n+in a bare repository (which has no worktree).\n++\n+This is useful when you want to apply configuration based on where the\n+working tree is located on the filesystem. For example, a contributor who\n+works on the same project both personally and as an employee can use\n+different `user.name` and `user.email` values depending on which directory\n+the worktree is checked out under:\n++\n+----\n+[includeIf \"worktree:/home/user/work/\"]\n+    path = ~/.config/git/work.inc\n+[includeIf \"worktree:/home/user/personal/\"]\n+    path = ~/.config/git/personal.inc\n+----\n++\n+While `extensions.worktreeConfig` (see linkgit:git-worktree[1]) also supports\n+per-worktree configuration, it stores the config inside each repository's\n+`.git/config.worktree` file and requires running `git config --worktree`\n+inside each worktree individually. In contrast, `includeIf \"worktree:...\"`\n+can be set once in a global or system-level configuration file (e.g.\n+`~/.config/git/config`) and applies to all repositories at once based on\n+their worktree location.\n+\n+`worktree/i`::\n+\tThis is the same as `worktree` except that matching is done\n+\tcase-insensitively (e.g. on case-insensitive file systems)\n+\n `onbranch`::\n \tThe data that follows the keyword `onbranch` and a colon is taken to be a\n \tpattern with standard globbing wildcards and two additional\n@@ -244,6 +284,14 @@ Example\n [includeIf \"gitdir:~/to/group/\"]\n \tpath = /path/to/foo.inc\n \n+; include if the worktree is at /path/to/project-build\n+[includeIf \"worktree:/path/to/project-build\"]\n+\tpath = build-config.inc\n+\n+; include for all worktrees inside /path/to/group\n+[includeIf \"worktree:/path/to/group/\"]\n+\tpath = group-config.inc\n+\n ; relative paths are always relative to the including\n ; file (if the condition is true); their location is not\n ; affected by the condition\ndiff --git a/config.c b/config.c\nindex 00eeeea370c9..652711ec5e0b 100644\n--- a/config.c\n+++ b/config.c\n@@ -400,6 +400,12 @@ static int include_condition_is_true(const struct key_value_info *kvi,\n \t\treturn include_by_path(kvi, opts->git_dir, cond, cond_len, 0);\n \telse if (skip_prefix_mem(cond, cond_len, \"gitdir/i:\", &cond, &cond_len))\n \t\treturn include_by_path(kvi, opts->git_dir, cond, cond_len, 1);\n+\telse if (skip_prefix_mem(cond, cond_len, \"worktree:\", &cond, &cond_len))\n+\t\treturn include_by_path(kvi, inc->repo ? repo_get_work_tree_original(inc->repo) : NULL,\n+\t\t\t\t       cond, cond_len, 0);\n+\telse if (skip_prefix_mem(cond, cond_len, \"worktree/i:\", &cond, &cond_len))\n+\t\treturn include_by_path(kvi, inc->repo ? repo_get_work_tree_original(inc->repo) : NULL,\n+\t\t\t\t       cond, cond_len, 1);\n \telse if (skip_prefix_mem(cond, cond_len, \"onbranch:\", &cond, &cond_len))\n \t\treturn include_by_branch(inc, cond, cond_len);\n \telse if (skip_prefix_mem(cond, cond_len, \"hasconfig:remote.*.url:\", &cond,\ndiff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh\nindex f3892578e4ff..99eae656a3f7 100755\n--- a/t/t1305-config-include.sh\n+++ b/t/t1305-config-include.sh\n@@ -396,4 +396,175 @@ test_expect_success 'onbranch without repository but explicit nonexistent Git di\n \ttest_must_fail nongit git --git-dir=nonexistent config get foo.bar\n '\n \n+# worktree: conditional include tests\n+\n+test_expect_success 'conditional include, worktree bare repo' '\n+\tgit init --bare wt-bare &&\n+\t(\n+\t\tcd wt-bare &&\n+\t\techo \"[includeIf \\\"worktree:/\\\"]path=bar-bare\" >>config &&\n+\t\techo \"[test]wtbare=1\" >bar-bare &&\n+\t\ttest_must_fail git config test.wtbare\n+\t)\n+'\n+\n+test_expect_success 'conditional include, worktree multiple worktrees' '\n+\tgit init wt-multi &&\n+\t(\n+\t\tcd wt-multi &&\n+\t\ttest_commit initial &&\n+\t\tgit worktree add -b linked-branch ../wt-linked HEAD &&\n+\t\tgit worktree add -b prefix-branch ../wt-prefix/linked HEAD\n+\t) &&\n+\twt_main=\"$(cd wt-multi && pwd)\" &&\n+\twt_linked=\"$(cd wt-linked && pwd)\" &&\n+\twt_prefix_parent=\"$(cd wt-prefix && pwd)\" &&\n+\tcat >>wt-multi/.git/config <<-EOF &&\n+\t[includeIf \"worktree:$wt_main\"]\n+\t\tpath = main-config\n+\t[includeIf \"worktree:$wt_linked\"]\n+\t\tpath = linked-config\n+\t[includeIf \"worktree:$wt_prefix_parent/\"]\n+\t\tpath = prefix-config\n+\tEOF\n+\techo \"[test]mainvar=main\" >wt-multi/.git/main-config &&\n+\techo \"[test]linkedvar=linked\" >wt-multi/.git/linked-config &&\n+\techo \"[test]prefixvar=prefix\" >wt-multi/.git/prefix-config &&\n+\techo main >expect &&\n+\tgit -C wt-multi config test.mainvar >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git -C wt-multi config test.linkedvar &&\n+\ttest_must_fail git -C wt-multi config test.prefixvar &&\n+\techo linked >expect &&\n+\tgit -C wt-linked config test.linkedvar >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git -C wt-linked config test.mainvar &&\n+\ttest_must_fail git -C wt-linked config test.prefixvar &&\n+\techo prefix >expect &&\n+\tgit -C wt-prefix/linked config test.prefixvar >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git -C wt-prefix/linked config test.mainvar &&\n+\ttest_must_fail git -C wt-prefix/linked config test.linkedvar\n+'\n+\n+test_expect_success SYMLINKS 'conditional include, worktree matching symlink' '\n+\tmkdir sym-real &&\n+\tln -s sym-real sym-link &&\n+\tgit init sym-link/repo &&\n+\t(\n+\t\tcd sym-link/repo &&\n+\t\tlink_path=\"$(pwd)\" &&\n+\t\treal_path=\"$(test-tool path-utils real_path \"$link_path\")\" &&\n+\t\tcat >>.git/config <<-EOF &&\n+\t\t[includeIf \"gitdir:$link_path/.git\"]\n+\t\t\tpath = gitdir-link\n+\t\t[includeIf \"gitdir:$real_path/.git\"]\n+\t\t\tpath = gitdir-real\n+\t\t[includeIf \"worktree:$link_path\"]\n+\t\t\tpath = worktree-link\n+\t\t[includeIf \"worktree:$real_path\"]\n+\t\t\tpath = worktree-real\n+\t\tEOF\n+\t\techo \"[test]gitdirlink=1\" >.git/gitdir-link &&\n+\t\techo \"[test]gitdirreal=1\" >.git/gitdir-real &&\n+\t\techo \"[test]worktreelink=1\" >.git/worktree-link &&\n+\t\techo \"[test]worktreereal=1\" >.git/worktree-real &&\n+\t\tgit config get test.gitdirlink &&\n+\t\tgit config get test.gitdirreal &&\n+\t\tgit config get test.worktreelink &&\n+\t\tgit config get test.worktreereal &&\n+\t\t# from a subdirectory, the logical worktree path is recovered by\n+\t\t# stripping the below-root suffix, so both spellings still match\n+\t\tmkdir d &&\n+\t\tcd d &&\n+\t\tgit config get test.worktreelink &&\n+\t\tgit config get test.worktreereal\n+\t)\n+'\n+\n+test_expect_success SYMLINKS 'conditional include, worktree matching symlink of a linked worktree' '\n+\tgit init wt-main &&\n+\t( cd wt-main && test_commit initial ) &&\n+\tgit -C wt-main worktree add --detach ../wt-real &&\n+\tln -s wt-real wt-link &&\n+\twt_main=\"$(cd wt-main && pwd)\" &&\n+\t(\n+\t\tcd wt-link &&\n+\t\tlink_path=\"$(pwd)\" &&\n+\t\treal_path=\"$(test-tool path-utils real_path \"$link_path\")\" &&\n+\t\tcat >>\"$wt_main/.git/config\" <<-EOF &&\n+\t\t[includeIf \"worktree:$link_path\"]\n+\t\t\tpath = wt-link\n+\t\t[includeIf \"worktree:$real_path\"]\n+\t\t\tpath = wt-real\n+\t\tEOF\n+\t\techo \"[test]wtlink=1\" >\"$wt_main/.git/wt-link\" &&\n+\t\techo \"[test]wtreal=1\" >\"$wt_main/.git/wt-real\" &&\n+\t\ttest \"$(git config get test.wtlink)\" = \"1\" &&\n+\t\ttest \"$(git config get test.wtreal)\" = \"1\"\n+\t)\n+'\n+\n+test_expect_success !CASE_INSENSITIVE_FS 'conditional include, worktree, case sensitive' '\n+\tgit init wt-case &&\n+\t(\n+\t\tcd wt-case &&\n+\t\ttest_commit initial &&\n+\t\twt_path=\"$(pwd)\" &&\n+\t\twt_upper=$(echo \"$wt_path\" | tr a-z A-Z) &&\n+\t\techo \"[includeIf \\\"worktree:$wt_upper\\\"]path=case-inc\" >>.git/config &&\n+\t\techo \"[test]wtcase=1\" >.git/case-inc &&\n+\t\ttest_must_fail git config test.wtcase\n+\t)\n+'\n+\n+test_expect_success 'conditional include, worktree, icase' '\n+\tgit init wt-icase &&\n+\t(\n+\t\tcd wt-icase &&\n+\t\ttest_commit initial &&\n+\t\twt_path=\"$(pwd)\" &&\n+\t\twt_upper=$(echo \"$wt_path\" | tr a-z A-Z) &&\n+\t\techo \"[includeIf \\\"worktree/i:$wt_upper\\\"]path=icase-inc\" >>.git/config &&\n+\t\techo \"[test]wticase=1\" >.git/icase-inc &&\n+\t\techo 1 >expect &&\n+\t\tgit config test.wticase >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+# The \"worktree\" condition cannot match during early config reading\n+# because the repository object is not yet fully initialized and\n+# repo_get_work_tree() returns NULL.\n+test_expect_success 'conditional include, worktree does not match in early config' '\n+\tgit init wt-early &&\n+\t(\n+\t\tcd wt-early &&\n+\t\ttest_commit initial &&\n+\t\twt_path=\"$(pwd)\" &&\n+\t\techo \"[includeIf \\\"worktree:$wt_path\\\"]path=early-inc\" >>.git/config &&\n+\t\techo \"[test]wtearly=1\" >.git/early-inc &&\n+\t\ttest-tool config read_early_config test.wtearly >actual &&\n+\t\ttest_must_be_empty actual\n+\t)\n+'\n+\n+# Use a loose pattern so the \"present in non-worktree cases\" check works\n+# for Unix-style absolute paths and Windows paths like D:/a/git/...\n+test_expect_success 'conditional include, worktree without repository' '\n+\ttest_when_finished \"rm -f .gitconfig config.inc\" &&\n+\tgit config set -f .gitconfig \"includeIf.worktree:**.path\" config.inc &&\n+\tgit config set -f config.inc foo.bar baz &&\n+\tgit config get foo.bar &&\n+\ttest_must_fail nongit git config get foo.bar\n+'\n+\n+test_expect_success 'conditional include, worktree without repository but explicit nonexistent Git directory' '\n+\ttest_when_finished \"rm -f .gitconfig config.inc\" &&\n+\tgit config set -f .gitconfig \"includeIf.worktree:**.path\" config.inc &&\n+\tgit config set -f config.inc foo.bar baz &&\n+\tgit config get foo.bar &&\n+\ttest_must_fail nongit git --git-dir=nonexistent config get foo.bar\n+'\n+\n test_done\n\n-- \n2.53.0\n\n\n"},{"id":"547599","messageId":"ak9zWopOWpRVHmmS@pks.im","threadId":"65956","inReplyTo":"20260709-includeif-worktree-v7-2-e87e705e8df6@black-desk.cn","subject":"Re: [PATCH v7 2/3] repository: keep a symlink-preserving copy of the worktree path","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-09T10:09:30Z","receivedAt":"2026-07-09T10:09:39Z","isPatch":true,"body":"On Thu, Jul 09, 2026 at 10:41:42AM +0800, Chen Linxuan via B4 Relay wrote:\n> diff --git a/repository.c b/repository.c\n> index 73d80bcffdf5..a29d55a6fcd3 100644\n> --- a/repository.c\n> +++ b/repository.c\n> @@ -149,6 +149,11 @@ const char *repo_get_work_tree(struct repository *repo)\n>  \treturn repo->worktree;\n>  }\n>  \n> +const char *repo_get_work_tree_original(struct repository *repo)\n> +{\n> +\treturn repo->worktree_original;\n> +}\n\nFeels a bit heavy-handed to have such an accessor, as we could've just\nas well accessed the member directly via the structure.\n\n> diff --git a/setup.c b/setup.c\n> index 0de56a074f7c..fbbeb95f99db 100644\n> --- a/setup.c\n> +++ b/setup.c\n> @@ -1213,12 +1213,94 @@ static const char *setup_explicit_git_dir(struct repository *repo,\n>  \treturn NULL;\n>  }\n>  \n> +/*\n> + * Do \"a\" and \"b\" refer to the same filesystem entry? Both must report a\n> + * nonzero (dev,ino): some filesystems return (0,0) for unrelated paths,\n> + * which would otherwise look identical.\n> + */\n> +static int same_entry(const char *a, const char *b)\n> +{\n> +\tstruct stat sa, sb;\n> +\n> +\tif (stat(a, &sa) || stat(b, &sb))\n> +\t\treturn 0;\n> +\treturn (sa.st_dev || sa.st_ino) &&\n> +\t       sa.st_dev == sb.st_dev && sa.st_ino == sb.st_ino;\n> +}\n> +\n> +/*\n> + * Recover the symlink-preserving spelling of the worktree root.\n> + *\n> + * strbuf_add_absolute_path() already consults $PWD to keep symlinks when\n> + * resolving a relative path, so set_git_work_tree()'s other callers get a\n> + * symlink-preserving worktree path for free.  This function exists for the\n> + * discovered-repository case: setup_git_directory_gently() chdir()s to the\n> + * worktree root *before* set_git_work_tree(repo, \".\") runs, so by the time\n> + * \".\" is resolved $PWD still names the caller's original directory and no\n> + * longer agrees with the physical cwd, and strbuf_add_absolute_path()\n> + * falls back to the realpath.  We close that gap by deriving the logical\n> + * root here, from $PWD, while we still have the original physical cwd and\n> + * the root offset in hand.\n> + *\n> + * \"cwd\" is the physical current directory (getcwd), and \"root_len\" is the\n> + * length of the worktree root within it; cwd->buf[root_len..] is therefore\n> + * the part of the path below the root (empty when git ran at the root).\n> + *\n> + * $PWD, maintained by the shell, may spell that same directory through\n> + * symlinks.  If we can confirm $PWD really names cwd's directory (same\n> + * device/inode) and that the below-root suffix matches, we swap the\n> + * physical root prefix for $PWD's prefix and keep the user's symlinks.\n> + * Only symlinks in the root prefix itself are preserved: the below-root\n> + * suffix is matched byte-for-byte, so a symlink below the root is not.\n> + *\n> + * Returns the allocated logical path, or NULL when $PWD is missing, already\n> + * physical, or untrustworthy.\n> + */\n\nOof.\n\n> +static char *logical_path_from_cwd(struct strbuf *cwd, int root_len)\n> +{\n> +\tconst char *pwd = getenv(\"PWD\");\n> +\tsize_t suffix_len, pwd_len;\n> +\tstruct strbuf path = STRBUF_INIT;\n> +\n> +\tif (!pwd || !is_absolute_path(pwd) || !strcmp(pwd, cwd->buf))\n> +\t\treturn NULL;\n> +\t/*\n> +\t * $PWD is a plain environment variable: it can be set to anything,\n> +\t * or left stale after a chdir.  Only borrow its symlink-preserving\n> +\t * spelling once we prove it still points at the same directory as\n> +\t * the physical cwd; otherwise give up and return NULL.\n> +\t */\n> +\tif (!same_entry(cwd->buf, pwd))\n> +\t\treturn NULL;\n> +\n> +\t/*\n> +\t * Drop the below-root suffix from $PWD.  It must match the physical\n> +\t * suffix exactly; the only spelling difference we accept is in the\n> +\t * root prefix -- i.e. the symlinks we want to preserve.\n> +\t */\n> +\tsuffix_len = cwd->len - root_len;\n> +\tpwd_len = strlen(pwd);\n> +\tif (suffix_len) {\n> +\t\tconst char *suffix = cwd->buf + root_len;\n> +\n> +\t\tif (suffix_len > pwd_len ||\n> +\t\t    fspathcmp(pwd + pwd_len - suffix_len, suffix))\n> +\t\t\treturn NULL;\n> +\t\tpwd_len -= suffix_len;\n> +\t}\n> +\n> +\tstrbuf_add(&path, pwd, pwd_len);\n> +\treturn strbuf_detach(&path, NULL);\n> +}\n\nThis feels quite awkward to me, and I assume that these changes will\nlead to conflicts with ps/setup-split-discovery-and-setup.\n\nI wonder whether we can maybe avoid this whole mess by removing the call\nto chdir(3p) when discovering Git directories in the first place.\nInstead, we'd only chdir(3p) after we have fully discovered the Git\nrepository's paths, and that may allow us to not have to worry about\nreconstructing the logical path?\n\nIt's something that I wanted to explore after the mentioned patch series\nhas landed, but maybe it's something we should try to do as part of this\npatch series here.\n\nAlternatively, I'm less certain that this complexity is ultimately\nreally worth it now... so another alternative could be to document the\nissue and fix it at a later point in time.\n\nPatrick\n"},{"id":"547600","messageId":"ak9zcggAmy205Fz8@pks.im","threadId":"65956","inReplyTo":"20260709-includeif-worktree-v7-0-e87e705e8df6@black-desk.cn","subject":"Re: [PATCH v7 0/3] includeIf: add \"worktree\" condition for matching working tree path","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-09T10:09:54Z","receivedAt":"2026-07-09T10:10:01Z","isPatch":true,"body":"On Thu, Jul 09, 2026 at 10:41:40AM +0800, Chen Linxuan via B4 Relay wrote:\n> Changes in v7:\n> - Preserve the symlinked spelling of the worktree path and match\n>   includeIf \"worktree:\" against it, so the condition now matches both\n>   the symlinked and the real path, consistent with \"gitdir:\"\n>   (Patrick Steinhardt, v6 review).\n> - Split the work into a preparatory commit that stores a non-realpath\n>   worktree path and a follow-up that wires it into includeIf.\n> - Extend symlink test coverage to subdirectories and linked worktrees.\n> - Link to v6: https://lore.kernel.org/r/20260703-includeif-worktree-v6-0-a13893ad9a7f@black-desk.cn\n\nOne note: it would be nice if you could send newer versions of your\npatch series in reply to the old version. I see you're using the b4\nrelay, so this should be configurable via `b4.send-same-thread`.\n\nThanks!\n\nPatrick\n"},{"id":"547650","messageId":"xmqqzezzkibu.fsf@gitster.g","threadId":"65956","inReplyTo":"20260709-includeif-worktree-v7-0-e87e705e8df6@black-desk.cn","subject":"Re: [PATCH v7 0/3] includeIf: add \"worktree\" condition for matching working tree path","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-09T20:40:21Z","receivedAt":"2026-07-09T20:40:23Z","isPatch":true,"body":"Chen Linxuan via B4 Relay <devnull+me.black-desk.cn@kernel.org>\nwrites:\n\n> The `includeIf` mechanism already supports matching on the `.git`\n> directory path (`gitdir`) and the currently checked out branch\n> (`onbranch`).  But in multi-worktree setups the `.git` directory of a\n> linked worktree points into the main repository's `.git/worktrees/`\n> area, which makes `gitdir` patterns cumbersome when one wants to\n> include config based on the working tree's checkout path instead.\n\nThanks.\n\nThis seems to break t1305 when merged to 'seen', even though all of\nthem pass standalone.  I did not have time to figure out what\ninteractions with which other topic are causing the breakages.\n"}]}