{"thread":{"id":"56096","subject":"[Patch 0/3] includeIf series for worktrees","startedAt":"2021-07-12T22:32:03Z","lastAt":"2021-07-14T17:30:54Z","messageCount":9,"participants":["randall.becker@nexbridge.ca","Johannes Schindelin","Junio C Hamano","Randall S. Becker"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"429844","messageId":"20210712223139.24409-1-randall.becker@nexbridge.ca","threadId":"56096","inReplyTo":null,"subject":"[Patch 0/3] includeIf series for worktrees","fromName":"","fromEmail":"randall.becker@nexbridge.ca","sentAt":"2021-07-12T22:31:36Z","receivedAt":"2021-07-12T22:32:03Z","isPatch":true,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"From: \"Randall S. Becker\" <rsbecker@nexbridge.com>\n\nAdd support for includeIf with a worktree: prefix. This permits\nconditional includes that are specific to individual worktrees.\nThe set of patches differ slightly from gitdir: as worktrees to not\nhave .git/ directories, so matching repo/ is somewhat problematic -\nsuggestings on dealing with that case are more than welcome.\n\nAlso added worktree test condition to verify that onbranch: works\nin a worktree scenario as different from the main repository.\n\nRandall S. Becker (3):\n  config.c: add conditional include based on worktree.\n  Documentation/config.txt: add worktree includeIf conditionals.\n  t1305: add tests for includeIf:worktree.\n\n Documentation/config.txt  | 11 +++++-\n config.c                  | 63 ++++++++++++++++++++++++++++++\n t/t1305-config-include.sh | 81 +++++++++++++++++++++++++++++++++++++++\n 3 files changed, 154 insertions(+), 1 deletion(-)\n\n-- \n2.32.0\n\n"},{"id":"429845","messageId":"20210712223139.24409-2-randall.becker@nexbridge.ca","threadId":"56096","inReplyTo":"20210712223139.24409-1-randall.becker@nexbridge.ca","subject":"[Patch 1/3] config.c: add conditional include based on worktree.","fromName":"","fromEmail":"randall.becker@nexbridge.ca","sentAt":"2021-07-12T22:31:37Z","receivedAt":"2021-07-12T22:32:05Z","isPatch":true,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"From: \"Randall S. Becker\" <rsbecker@nexbridge.com>\n\nThis enhancement extends the [includeIf] semantics to include conditional\ninclusion based on whether the conditional is within a specific worktree\nor case-insensitive worktree. The [includeIf \"worktree:path\"] and\n[includeIf \"worktree/i:path\"] and analogous to the gitdir: and gitdir/i:\nconditions, respectively.\n\nSigned-off-by: Randall S. Becker <rsbecker@nexbridge.com>\n---\n config.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 63 insertions(+)\n\ndiff --git a/config.c b/config.c\nindex f9c400ad30..e2b2364579 100644\n--- a/config.c\n+++ b/config.c\n@@ -272,6 +272,64 @@ static int include_by_gitdir(const struct config_options *opts,\n \treturn ret;\n }\n \n+static int include_by_worktree(const struct config_options *opts,\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+\tint ret = 0, prefix;\n+\tconst char *worktree;\n+\tint already_tried_absolute = 0;\n+\n+\tif (the_repository->worktree)\n+\t\tworktree = the_repository->worktree;\n+\telse\n+\t\tgoto done;\n+\n+\tstrbuf_realpath(&text, worktree, 1);\n+\tstrbuf_add(&pattern, cond, cond_len);\n+\tprefix = prepare_include_condition_pattern(&pattern);\n+\n+again:\n+\tif (prefix < 0)\n+\t\tgoto done;\n+\n+\tif (prefix > 0) {\n+\t\t/*\n+\t\t * perform literal matching on the prefix part so that\n+\t\t * any wildcard character in it can't create side effects.\n+\t\t */\n+\t\tif (text.len < prefix)\n+\t\t\tgoto done;\n+\t\tif (!icase && strncmp(pattern.buf, text.buf, prefix))\n+\t\t\tgoto done;\n+\t\tif (icase && strncasecmp(pattern.buf, text.buf, prefix))\n+\t\t\tgoto done;\n+\t}\n+\n+\tret = !wildmatch(pattern.buf + prefix, text.buf + prefix,\n+\t\t\t WM_PATHNAME | (icase ? WM_CASEFOLD : 0));\n+\n+\tif (!ret && !already_tried_absolute) {\n+\t\t/*\n+\t\t * We've tried e.g. matching worktree:~/work, but if\n+\t\t * ~/work is a symlink to /mnt/storage/work\n+\t\t * strbuf_realpath() will expand it, so the rule won't\n+\t\t * match. Let's match against a\n+\t\t * strbuf_add_absolute_path() version of the path,\n+\t\t * which'll do the right thing\n+\t\t */\n+\t\tstrbuf_reset(&text);\n+\t\tstrbuf_add_absolute_path(&text, worktree);\n+\t\talready_tried_absolute = 1;\n+\t\tgoto again;\n+\t}\n+done:\n+\tstrbuf_release(&pattern);\n+\tstrbuf_release(&text);\n+\treturn ret;\n+}\n+\n static int include_by_branch(const char *cond, size_t cond_len)\n {\n \tint flags;\n@@ -300,6 +358,11 @@ static int include_condition_is_true(const struct config_options *opts,\n \t\treturn include_by_gitdir(opts, cond, cond_len, 0);\n \telse if (skip_prefix_mem(cond, cond_len, \"gitdir/i:\", &cond, &cond_len))\n \t\treturn include_by_gitdir(opts, cond, cond_len, 1);\n+\telse if (skip_prefix_mem(cond, cond_len, \"worktree:\", &cond, &cond_len))\n+\t\treturn include_by_worktree(opts, cond, cond_len, 0);\n+\telse if (skip_prefix_mem(cond, cond_len, \"worktree/i:\", &cond,\n+\t\t\t\t &cond_len))\n+\t\treturn include_by_worktree(opts, cond, cond_len, 1);\n \telse if (skip_prefix_mem(cond, cond_len, \"onbranch:\", &cond, &cond_len))\n \t\treturn include_by_branch(cond, cond_len);\n \n-- \n2.32.0\n\n"},{"id":"429846","messageId":"20210712223139.24409-3-randall.becker@nexbridge.ca","threadId":"56096","inReplyTo":"20210712223139.24409-1-randall.becker@nexbridge.ca","subject":"[Patch 2/3] Documentation/config.txt: add worktree includeIf conditionals.","fromName":"","fromEmail":"randall.becker@nexbridge.ca","sentAt":"2021-07-12T22:31:38Z","receivedAt":"2021-07-12T22:32:06Z","isPatch":true,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"From: \"Randall S. Becker\" <rsbecker@nexbridge.com>\n\nDocumentation of the worktree and worktree/i conditionals is add based on\ngitdir rules except that the trailing / form of the path is not supported.\n\nSigned-off-by: Randall S. Becker <rsbecker@nexbridge.com>\n---\n Documentation/config.txt | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex bf82766a6a..7e951937ae 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -143,7 +143,16 @@ refer to linkgit:gitignore[5] for details. For convenience:\n \n `gitdir/i`::\n \tThis is the same as `gitdir` except that matching is done\n-\tcase-insensitively (e.g. on case-insensitive file systems)\n+\tcase-insensitively (e.g. on case-insensitive file systems).\n+\n+`worktree`::\n+\tThis is similar to `gitdir` except that matching is done with\n+\tthe path of a worktree instead of the main repository. Unlike\n+\t`gitdir`, the trailing / form of the worktree path is not supported.\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:` is taken to be a\n-- \n2.32.0\n\n"},{"id":"429847","messageId":"20210712223139.24409-4-randall.becker@nexbridge.ca","threadId":"56096","inReplyTo":"20210712223139.24409-1-randall.becker@nexbridge.ca","subject":"[Patch 3/3] t1305: add tests for includeIf:worktree.","fromName":"","fromEmail":"randall.becker@nexbridge.ca","sentAt":"2021-07-12T22:31:39Z","receivedAt":"2021-07-12T22:32:07Z","isPatch":true,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"From: \"Randall S. Becker\" <rsbecker@nexbridge.com>\n\nThe tests are a subset of those for gitdir:, taking into account that\nthe worktree: form does not support the trailing / at this time in\npattern matches. Some resets of the .git/config file are done to restrict\nthe set of includeIf paths being evaluated that conflict with prior\nsubtests.\n\nSigned-off-by: Randall S. Becker <rsbecker@nexbridge.com>\n---\n t/t1305-config-include.sh | 81 +++++++++++++++++++++++++++++++++++++++\n 1 file changed, 81 insertions(+)\n\ndiff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh\nindex ccbb116c01..fe1ad106c3 100755\n--- a/t/t1305-config-include.sh\n+++ b/t/t1305-config-include.sh\n@@ -309,6 +309,69 @@ test_expect_success SYMLINKS 'conditional include, gitdir matching symlink, icas\n \t)\n '\n \n+test_expect_success 'conditional worktree include, unanchored' '\n+\t(\n+\t\tcd foo &&\n+\t\t# Must add a commit for worktree add\n+\t\tgit commit --allow-empty --allow-empty-message &&\n+\t\tsed -i \"/includeIf/,\\$d\" .git/config &&\n+\t\tgit worktree add ../foo.wt &&\n+\t\techo \"[includeIf \\\"worktree:foo.wt\\\"]path=bar\" >>.git/config &&\n+\t\techo \"[test]one=1\" >.git/bar &&\n+\t\tcd ../foo.wt &&\n+\t\techo 1 >expect &&\n+\t\tgit config test.one >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'conditional worktree include, $HOME expansion' '\n+\t(\n+\t\tcd foo &&\n+\t\techo \"[includeIf \\\"worktree:~/foo.wt\\\"]path=bar2\" >>.git/config &&\n+\t\techo \"[test]two=2\" >.git/bar2 &&\n+\t\tcd ../foo.wt &&\n+\t\techo 2 >expect &&\n+\t\tgit config test.two >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'conditional worktree include, full pattern' '\n+\t(\n+\t\tcd foo &&\n+\t\techo \"[includeIf \\\"worktree:**/foo.wt\\\"]path=bar3\" >>.git/config &&\n+\t\techo \"[test]three=3\" >.git/bar3 &&\n+\t\tcd ../foo.wt &&\n+\t\techo 3 >expect &&\n+\t\tgit config test.three >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'conditional worktree include, relative path' '\n+\techo \"[includeIf \\\"worktree:./foo.wt\\\"]path=bar4\" >>.gitconfig &&\n+\techo \"[test]four=4\" >bar4 &&\n+\t(\n+\t\tcd foo.wt &&\n+\t\techo 4 >expect &&\n+\t\tgit config test.four >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'conditional worktree include, both unanchored, icase' '\n+\t(\n+\t\tcd foo &&\n+\t\techo \"[includeIf \\\"worktree/i:FOO.WT\\\"]path=bar5\" >>.git/config &&\n+\t\techo \"[test]five=5\" >.git/bar5 &&\n+\t\tcd ../foo.wt &&\n+\t\techo 5 >expect &&\n+\t\tgit config test.five >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_expect_success 'conditional include, onbranch' '\n \techo \"[includeIf \\\"onbranch:foo-branch\\\"]path=bar9\" >>.git/config &&\n \techo \"[test]nine=9\" >.git/bar9 &&\n@@ -348,6 +411,24 @@ test_expect_success 'conditional include, onbranch, implicit /** for /' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'conditional worktree include, onbranch' '\n+\t(\n+\t\tcd foo &&\n+\t\tsed -i \"/includeIf/,\\$d\" .git/config &&\n+\t\techo \"[includeIf \\\"onbranch:foo.wt2\\\"]path=bar12\" >>.git/config &&\n+\t\techo \"[test]twelve=12\" >.git/bar12\n+\t) &&\n+\t(\n+\t\tcd foo.wt &&\n+\t\tgit checkout -b main &&\n+\t\ttest_must_fail git config test.twelve &&\n+\t\tgit checkout -b foo.wt2 &&\n+\t\techo 12 >expect &&\n+\t\tgit config test.twelve >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_expect_success 'include cycles are detected' '\n \tgit init --bare cycle &&\n \tgit -C cycle config include.path cycle &&\n-- \n2.32.0\n\n"},{"id":"429892","messageId":"nycvar.QRO.7.76.6.2107131502360.76@tvgsbejvaqbjf.bet","threadId":"56096","inReplyTo":"20210712223139.24409-2-randall.becker@nexbridge.ca","subject":"Re: [Patch 1/3] config.c: add conditional include based on worktree.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2021-07-13T13:03:21Z","receivedAt":"2021-07-13T13:03:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Randall,\n\nOn Mon, 12 Jul 2021, randall.becker@nexbridge.ca wrote:\n\n> @@ -300,6 +358,11 @@ static int include_condition_is_true(const struct config_options *opts,\n>  \t\treturn include_by_gitdir(opts, cond, cond_len, 0);\n>  \telse if (skip_prefix_mem(cond, cond_len, \"gitdir/i:\", &cond, &cond_len))\n>  \t\treturn include_by_gitdir(opts, cond, cond_len, 1);\n> +\telse if (skip_prefix_mem(cond, cond_len, \"worktree:\", &cond, &cond_len))\n> +\t\treturn include_by_worktree(opts, cond, cond_len, 0);\n> +\telse if (skip_prefix_mem(cond, cond_len, \"worktree/i:\", &cond,\n> +\t\t\t\t &cond_len))\n> +\t\treturn include_by_worktree(opts, cond, cond_len, 1);\n\nThank you for not forgetting the `/i` case.\n\nCiao,\nDscho\n\n>  \telse if (skip_prefix_mem(cond, cond_len, \"onbranch:\", &cond, &cond_len))\n>  \t\treturn include_by_branch(cond, cond_len);\n>\n> --\n> 2.32.0\n>\n>\n"},{"id":"429977","messageId":"xmqqr1g1zow4.fsf@gitster.g","threadId":"56096","inReplyTo":"20210712223139.24409-3-randall.becker@nexbridge.ca","subject":"Re: [Patch 2/3] Documentation/config.txt: add worktree includeIf conditionals.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-07-14T01:04:59Z","receivedAt":"2021-07-14T01:05:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"randall.becker@nexbridge.ca writes:\n\n> From: \"Randall S. Becker\" <rsbecker@nexbridge.com>\n>\n> Documentation of the worktree and worktree/i conditionals is add based on\n> gitdir rules except that the trailing / form of the path is not supported.\n>\n> Signed-off-by: Randall S. Becker <rsbecker@nexbridge.com>\n> ---\n>  Documentation/config.txt | 11 ++++++++++-\n>  1 file changed, 10 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index bf82766a6a..7e951937ae 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -143,7 +143,16 @@ refer to linkgit:gitignore[5] for details. For convenience:\n>  \n>  `gitdir/i`::\n>  \tThis is the same as `gitdir` except that matching is done\n> -\tcase-insensitively (e.g. on case-insensitive file systems)\n> +\tcase-insensitively (e.g. on case-insensitive file systems).\n> +\n> +`worktree`::\n> +\tThis is similar to `gitdir` except that matching is done with\n> +\tthe path of a worktree instead of the main repository. Unlike\n> +\t`gitdir`, the trailing / form of the worktree path is not supported.\n\nIt is not immediately obvious what \"the trailing / form\" means.\n\nDoes it refer to the 4th item in the 4-bullet list in the\ndescription just above the patch context (I am trying to make a\nguess here)?\n\nThe problem I perceive in this description is that there is no\nphrase \"trailing\" in the vicinity of what readers have read so far;\nreaders who are not exactly familiar with the system may need a bit\nmore assurance that they guessed correctly.\n\n    Unlike `gitdir`, `**` will not be automatically added to a\n    pattern that ends with `/`\n\nwould be easier to give that assurance, albeit more verbosely.\n\nAssuming that I guessed correctly, is this a deliberate design\ndecision not to \"automatically add ** after a pattern that ends with\na slash\", and if so why?  I would have thought that \"in the\nworktrees that I create inside /var/tmp/, please enable these\nconfiguration variables\" would be a fairly natural thing to ask, and\nI do not immediately see a reason why we want to apply different\nsyntax rules between \"gitdir\" and \"worktree\".\n\nThanks.\n"},{"id":"430055","messageId":"006b01d778b6$b74b8600$25e29200$@nexbridge.com","threadId":"56096","inReplyTo":"xmqqr1g1zow4.fsf@gitster.g","subject":"RE: [Patch 2/3] Documentation/config.txt: add worktree includeIf conditionals.","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2021-07-14T13:46:52Z","receivedAt":"2021-07-14T13:47:04Z","isPatch":true,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On July 13, 2021 9:05 PM. Junio C Hamano wrote:\n>randall.becker@nexbridge.ca writes:\n>\n>> From: \"Randall S. Becker\" <rsbecker@nexbridge.com>\n>>\n>> Documentation of the worktree and worktree/i conditionals is add based\n>> on gitdir rules except that the trailing / form of the path is not supported.\n>>\n>> Signed-off-by: Randall S. Becker <rsbecker@nexbridge.com>\n>> ---\n>>  Documentation/config.txt | 11 ++++++++++-\n>>  1 file changed, 10 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/Documentation/config.txt b/Documentation/config.txt index\n>> bf82766a6a..7e951937ae 100644\n>> --- a/Documentation/config.txt\n>> +++ b/Documentation/config.txt\n>> @@ -143,7 +143,16 @@ refer to linkgit:gitignore[5] for details. For convenience:\n>>\n>>  `gitdir/i`::\n>>  \tThis is the same as `gitdir` except that matching is done\n>> -\tcase-insensitively (e.g. on case-insensitive file systems)\n>> +\tcase-insensitively (e.g. on case-insensitive file systems).\n>> +\n>> +`worktree`::\n>> +\tThis is similar to `gitdir` except that matching is done with\n>> +\tthe path of a worktree instead of the main repository. Unlike\n>> +\t`gitdir`, the trailing / form of the worktree path is not supported.\n>\n>It is not immediately obvious what \"the trailing / form\" means.\n>\n>Does it refer to the 4th item in the 4-bullet list in the description just above the patch context (I am trying to make a guess\nhere)?\n>\n>The problem I perceive in this description is that there is no phrase \"trailing\" in the vicinity of what readers have read so far;\nreaders who\n>are not exactly familiar with the system may need a bit more assurance that they guessed correctly.\n>\n>    Unlike `gitdir`, `**` will not be automatically added to a\n>    pattern that ends with `/`\n>\n>would be easier to give that assurance, albeit more verbosely.\n>\n>Assuming that I guessed correctly, is this a deliberate design decision not to \"automatically add ** after a pattern that ends with\na slash\",\n>and if so why?  I would have thought that \"in the worktrees that I create inside /var/tmp/, please enable these configuration\nvariables\"\n>would be a fairly natural thing to ask, and I do not immediately see a reason why we want to apply different syntax rules between\n\"gitdir\"\n>and \"worktree\".\n\nThe reason for this comes down to what is in *the_repository. Essentially, the_repository->gitdir always has a /path/to/.git\ndirectory with full qualification. the_repository->worktree does not have /.git added for obvious reasons, so the /path/to is bare\nof the trailing /. This causes a trailing pattern /to/path/** match to fail. I could copy the value into a working buffer but that\nseemed a bit clunky. So using the available information, the syntax rules need to be different between the two, unless the value of\nworktree is augmented. I was unsure which way the team wanted to go on this.\n\n"},{"id":"430078","messageId":"xmqqczrkyg77.fsf@gitster.g","threadId":"56096","inReplyTo":"006b01d778b6$b74b8600$25e29200$@nexbridge.com","subject":"Re: [Patch 2/3] Documentation/config.txt: add worktree includeIf conditionals.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-07-14T17:10:20Z","receivedAt":"2021-07-14T17:10:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Randall S. Becker\" <rsbecker@nexbridge.com> writes:\n\n>>Assuming that I guessed correctly, is this a deliberate design\n>>decision not to \"automatically add ** after a pattern that ends\n>>with a slash\", and if so why?  I would have thought that \"in the\n>>worktrees that I create inside /var/tmp/, please enable these\n>>configuration variables\" would be a fairly natural thing to ask,\n>>and I do not immediately see a reason why we want to apply\n>>different syntax rules between \"gitdir\" and \"worktree\".\n\n> The reason for this comes down to what is in\n>*the_repository.\n\nSorry, but I still do not understand.\n\n> Essentially, the_repository->gitdir always has a /path/to/.git\n> directory with full qualification.\n\nYes.\n\n> the_repository->worktree does not have /.git added\n> for obvious reasons, so the /path/to is bare of the trailing\n>/.\n\nIt may be the case, but /path/to/.git does not have trailing slash,\neither, so I do not see the relevance.\n\nWhen you say [includeIf \"gitdir:/path/\"], the \"behave as if ** is\nadded after the slash at the end\" rule kicks in, and the pattern\n\"/path/**\" is used to see if it matches \"/path/to/.git\" and it does,\nright?  When you say [includeIf \"worktree:/path/\"], wouldn't the\nresulting \"/path/**\" match \"/path/to\"?\n\nBy the way, I think [PATCH 1/3] should turn the body of\ninclude_by_gitdir() to a common helper function that\n\n - accepts a path to a directory and a pattern\n - turns it into a relpath\n - prepares the pattern with prepare_include_condition_pattern()\n - do the match include_by_gitdir() does.\n\nand make include_by_gitdir() a very thin wrapper that passes\nopts->git_dir to that common helper.  Then you do not have to copy\nthe entire function to create your new include_by_worktree(); it can\nbe another very thin wrapper that passes the_repository->worktree\ninstead of opts->git_dir to the common helper, as there is no other\ndifference in these two functions.\n\nThanks.\n"},{"id":"430089","messageId":"001101d778d5$fd6c7670$f8456350$@nexbridge.com","threadId":"56096","inReplyTo":"xmqqczrkyg77.fsf@gitster.g","subject":"RE: [Patch 2/3] Documentation/config.txt: add worktree includeIf conditionals.","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2021-07-14T17:30:44Z","receivedAt":"2021-07-14T17:30:54Z","isPatch":true,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On July 14, 2021 1:10 PM, Junio C Hamano\n>\"Randall S. Becker\" <rsbecker@nexbridge.com> writes:\n>\n>>>Assuming that I guessed correctly, is this a deliberate design\n>>>decision not to \"automatically add ** after a pattern that ends with a\n>>>slash\", and if so why?  I would have thought that \"in the worktrees\n>>>that I create inside /var/tmp/, please enable these configuration\n>>>variables\" would be a fairly natural thing to ask, and I do not\n>>>immediately see a reason why we want to apply different syntax rules\n>>>between \"gitdir\" and \"worktree\".\n>\n>> The reason for this comes down to what is in *the_repository.\n>\n>Sorry, but I still do not understand.\n>\n>> Essentially, the_repository->gitdir always has a /path/to/.git\n>> directory with full qualification.\n>\n>Yes.\n>\n>> the_repository->worktree does not have /.git added  for obvious\n>>reasons, so the /path/to is bare of the trailing /.\n>\n>It may be the case, but /path/to/.git does not have trailing slash, either, so I do not see the relevance.\n>\n>When you say [includeIf \"gitdir:/path/\"], the \"behave as if ** is added after the slash at the end\" rule kicks in, and the pattern\n\"/path/**\" is\n>used to see if it matches \"/path/to/.git\" and it does, right?  When you say [includeIf \"worktree:/path/\"], wouldn't the resulting\n\"/path/**\"\n>match \"/path/to\"?\n\nI think I over-complicated the first test case and got myself into a mess. Will fix that.\n\n>By the way, I think [PATCH 1/3] should turn the body of\n>include_by_gitdir() to a common helper function that\n>\n> - accepts a path to a directory and a pattern\n> - turns it into a relpath\n> - prepares the pattern with prepare_include_condition_pattern()\n> - do the match include_by_gitdir() does.\n>\n>and make include_by_gitdir() a very thin wrapper that passes\n>opts->git_dir to that common helper.  Then you do not have to copy\n>the entire function to create your new include_by_worktree(); it can be another very thin wrapper that passes\nthe_repository->worktree\n>instead of opts->git_dir to the common helper, as there is no other difference in these two functions.\n\nThat sounds like a plan. Will go for it in V2.\n\n-Randall\n\n"}]}