{"thread":{"id":"65205","subject":"[PATCH] editorconfig: fix style not applying to subdirs anymore","startedAt":"2026-03-11T07:09:25Z","lastAt":"2026-03-11T17:32:55Z","messageCount":3,"participants":["Patrick Steinhardt","Phillip Wood","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"538559","messageId":"20260311-b4-pks-editorconfig-fix-subdirs-v1-1-4938193ccd31@pks.im","threadId":"65205","inReplyTo":null,"subject":"[PATCH] editorconfig: fix style not applying to subdirs anymore","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-03-11T07:09:18Z","receivedAt":"2026-03-11T07:09:25Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In 046e1117d5 (templates: add .gitattributes entry for sample hooks,\n2026-02-13) we have added another pattern to our EditorConfig that sets\nthe style for our hook templates. As our templates are located in\n\"templates/hooks/\", we explicitly specify that subdirectory as part of\nthe globbing pattern.\n\nThis change causes files in other subdirectories, like for example\n\"builtin/add.c\", to not be configured properly anymore. This seems to\nstem from a subtlety in the EditorConfig specification [1]:\n\n  If the glob contains a path separator (a / not inside square\n  brackets), then the glob is relative to the directory level of the\n  particular .editorconfig file itself. Otherwise the pattern may also\n  match at any level below the .editorconfig level.\n\nWhat's interesting is that the _whole_ expression is considered to be\nthe glob. So when the expression used is for example \"{*.c,foo/*.h}\",\nthen it will be considered a single glob, and because it contains a path\nseparator we will now anchor \"*.c\" matches to the same directory as the\n\".editorconfig\" file.\n\nFix this issue by splitting out the configuration for hook templates\ninto a separate section. It leads to a tiny bit of duplication, but the\nalternative would be something like the following (note the \"{,**/}\"):\n\n  [{{,**/}*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,{,**/}Makefile,templates/hooks/*.sample}]\n  indent_style = tab\n  tab_width = 8\n\nThis starts to become somewhat hard to read, so the duplication feels\nlike the better tradeoff.\n\n[1]: https://spec.editorconfig.org/#glob-expressions\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\nHi,\n\nthis fixes a small regression in our EditorConfig introduced in\n046e1117d5 (templates: add .gitattributes entry for sample hooks,\n2026-02-13). Thanks!\n\nPatrick\n---\n .editorconfig | 6 +++++-\n 1 file changed, 5 insertions(+), 1 deletion(-)\n\ndiff --git a/.editorconfig b/.editorconfig\nindex 6e4eaa8e95..82e121a417 100644\n--- a/.editorconfig\n+++ b/.editorconfig\n@@ -4,7 +4,11 @@ insert_final_newline = true\n \n # The settings for C (*.c and *.h) files are mirrored in .clang-format.  Keep\n # them in sync.\n-[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile,templates/hooks/*.sample}]\n+[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile}]\n+indent_style = tab\n+tab_width = 8\n+\n+[templates/hooks/*.sample]\n indent_style = tab\n tab_width = 8\n \n\n---\nbase-commit: 7f19e4e1b6a3ad259e2ed66033e01e03b8b74c5e\nchange-id: 20260311-b4-pks-editorconfig-fix-subdirs-981e6db389ec\n\n"},{"id":"538606","messageId":"1eb3b78c-5833-4fa9-83f6-237d4a3e78d3@gmail.com","threadId":"65205","inReplyTo":"20260311-b4-pks-editorconfig-fix-subdirs-v1-1-4938193ccd31@pks.im","subject":"Re: [PATCH] editorconfig: fix style not applying to subdirs anymore","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-03-11T14:16:53Z","receivedAt":"2026-03-11T14:16:57Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"\n\nOn 11/03/2026 07:09, Patrick Steinhardt wrote:\n> In 046e1117d5 (templates: add .gitattributes entry for sample hooks,\n> 2026-02-13) we have added another pattern to our EditorConfig that sets\n> the style for our hook templates. As our templates are located in\n> \"templates/hooks/\", we explicitly specify that subdirectory as part of\n> the globbing pattern.\n> \n> This change causes files in other subdirectories, like for example\n> \"builtin/add.c\", to not be configured properly anymore. This seems to\n> stem from a subtlety in the EditorConfig specification [1]:\n> \n>    If the glob contains a path separator (a / not inside square\n>    brackets), then the glob is relative to the directory level of the\n>    particular .editorconfig file itself. Otherwise the pattern may also\n>    match at any level below the .editorconfig level.\n> \n> What's interesting is that the _whole_ expression is considered to be\n> the glob.\n\nOuch, I'd missed that, thanks for fixing it\n\n> So when the expression used is for example \"{*.c,foo/*.h}\",\n> then it will be considered a single glob, and because it contains a path\n> separator we will now anchor \"*.c\" matches to the same directory as the\n> \".editorconfig\" file.\n> \n> Fix this issue by splitting out the configuration for hook templates\n> into a separate section. It leads to a tiny bit of duplication, but the\n> alternative would be something like the following (note the \"{,**/}\"):\n> \n>    [{{,**/}*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,{,**/}Makefile,templates/hooks/*.sample}]\n>    indent_style = tab\n>    tab_width = 8\n> \n> This starts to become somewhat hard to read, so the duplication feels\n> like the better tradeoff.\n\nAgreed\n\nThanks\n\nPhillip\n\n> [1]: https://spec.editorconfig.org/#glob-expressions\n> \n> Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> ---\n> Hi,\n> \n> this fixes a small regression in our EditorConfig introduced in\n> 046e1117d5 (templates: add .gitattributes entry for sample hooks,\n> 2026-02-13). Thanks!\n> \n> Patrick\n> ---\n>   .editorconfig | 6 +++++-\n>   1 file changed, 5 insertions(+), 1 deletion(-)\n> \n> diff --git a/.editorconfig b/.editorconfig\n> index 6e4eaa8e95..82e121a417 100644\n> --- a/.editorconfig\n> +++ b/.editorconfig\n> @@ -4,7 +4,11 @@ insert_final_newline = true\n>   \n>   # The settings for C (*.c and *.h) files are mirrored in .clang-format.  Keep\n>   # them in sync.\n> -[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile,templates/hooks/*.sample}]\n> +[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile}]\n> +indent_style = tab\n> +tab_width = 8\n> +\n> +[templates/hooks/*.sample]\n>   indent_style = tab\n>   tab_width = 8\n>   \n> \n> ---\n> base-commit: 7f19e4e1b6a3ad259e2ed66033e01e03b8b74c5e\n> change-id: 20260311-b4-pks-editorconfig-fix-subdirs-981e6db389ec\n> \n> \n\n"},{"id":"538632","messageId":"xmqq1phqqnjv.fsf@gitster.g","threadId":"65205","inReplyTo":"1eb3b78c-5833-4fa9-83f6-237d4a3e78d3@gmail.com","subject":"Re: [PATCH] editorconfig: fix style not applying to subdirs anymore","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-03-11T17:32:52Z","receivedAt":"2026-03-11T17:32:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> On 11/03/2026 07:09, Patrick Steinhardt wrote:\n>...\n>>    If the glob contains a path separator (a / not inside square\n>>    brackets), then the glob is relative to the directory level of the\n>>    particular .editorconfig file itself. Otherwise the pattern may also\n>>    match at any level below the .editorconfig level.\n>> \n>> What's interesting is that the _whole_ expression is considered to be\n>> the glob.\n>\n> Ouch, I'd missed that, thanks for fixing it\n> ...\n>>    [{{,**/}*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,{,**/}Makefile,templates/hooks/*.sample}]\n>>    indent_style = tab\n>>    tab_width = 8\n>> \n>> This starts to become somewhat hard to read, so the duplication feels\n>> like the better tradeoff.\n>\n> Agreed\n\nThanks, both.\n"}]}