threads / patch / 65205

patcheditorconfig: fix style not applying to subdirs anymore

Subject: [PATCH] editorconfig: fix style not applying to subdirs anymore

## tl;dr

3 messages between Mar 11, 2026 and Mar 11, 2026. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Patrick Steinhardt· Mar 11, 2026, 07:09 UTC · lore

In 046e1117d5 (templates: add .gitattributes entry for sample hooks, 2026-02-13) we have added another pattern to our EditorConfig that sets the style for our hook templates. As our templates are located in "templates/hooks/", we explicitly specify that subdirectory as part of the globbing pattern.

This change causes files in other subdirectories, like for example "builtin/add.c", to not be configured properly anymore. This seems to stem from a subtlety in the EditorConfig specification [1]:

  If the glob contains a path separator (a / not inside square
  brackets), then the glob is relative to the directory level of the
  particular .editorconfig file itself. Otherwise the pattern may also
  match at any level below the .editorconfig level.

What's interesting is that the _whole_ expression is considered to be the glob. So when the expression used is for example "{*.c,foo/*.h}", then it will be considered a single glob, and because it contains a path separator we will now anchor "*.c" matches to the same directory as the ".editorconfig" file.

Fix this issue by splitting out the configuration for hook templates into a separate section. It leads to a tiny bit of duplication, but the alternative would be something like the following (note the "{,**/}"):

  [{{,**/}*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,{,**/}Makefile,templates/hooks/*.sample}]
  indent_style = tab
  tab_width = 8

This starts to become somewhat hard to read, so the duplication feels like the better tradeoff.

[1]: https://spec.editorconfig.org/#glob-expressions
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Hi,

this fixes a small regression in our EditorConfig introduced in 046e1117d5 (templates: add .gitattributes entry for sample hooks, 2026-02-13). Thanks!

Patrick
---
 .editorconfig | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Show changes to .editorconfig +5 −1
diff --git a/.editorconfig b/.editorconfig
index 6e4eaa8e95..82e121a417 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -4,7 +4,11 @@ insert_final_newline = true
 
 # The settings for C (*.c and *.h) files are mirrored in .clang-format.  Keep
 # them in sync.
-[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile,templates/hooks/*.sample}]
+[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile}]
+indent_style = tab
+tab_width = 8
+
+[templates/hooks/*.sample]
 indent_style = tab
 tab_width = 8
 

---
base-commit: 7f19e4e1b6a3ad259e2ed66033e01e03b8b74c5e
change-id: 20260311-b4-pks-editorconfig-fix-subdirs-981e6db389ec
Phillip Wood· Mar 11, 2026, 14:16 UTC · re: Patrick Steinhardt · lore

Re: [PATCH] editorconfig: fix style not applying to subdirs anymore

On 11/03/2026 07:09, Patrick Steinhardt wrote:
Show 17 quoted lines
> In 046e1117d5 (templates: add .gitattributes entry for sample hooks,
> 2026-02-13) we have added another pattern to our EditorConfig that sets
> the style for our hook templates. As our templates are located in
> "templates/hooks/", we explicitly specify that subdirectory as part of
> the globbing pattern.
> 
> This change causes files in other subdirectories, like for example
> "builtin/add.c", to not be configured properly anymore. This seems to
> stem from a subtlety in the EditorConfig specification [1]:
> 
>    If the glob contains a path separator (a / not inside square
>    brackets), then the glob is relative to the directory level of the
>    particular .editorconfig file itself. Otherwise the pattern may also
>    match at any level below the .editorconfig level.
> 
> What's interesting is that the _whole_ expression is considered to be
> the glob.
Ouch, I'd missed that, thanks for fixing it
Show 15 quoted lines
> So when the expression used is for example "{*.c,foo/*.h}",
> then it will be considered a single glob, and because it contains a path
> separator we will now anchor "*.c" matches to the same directory as the
> ".editorconfig" file.
> 
> Fix this issue by splitting out the configuration for hook templates
> into a separate section. It leads to a tiny bit of duplication, but the
> alternative would be something like the following (note the "{,**/}"):
> 
>    [{{,**/}*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,{,**/}Makefile,templates/hooks/*.sample}]
>    indent_style = tab
>    tab_width = 8
> 
> This starts to become somewhat hard to read, so the duplication feels
> like the better tradeoff.
Agreed
Thanks
Phillip
Show 38 quoted lines
> [1]: https://spec.editorconfig.org/#glob-expressions
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> Hi,
> 
> this fixes a small regression in our EditorConfig introduced in
> 046e1117d5 (templates: add .gitattributes entry for sample hooks,
> 2026-02-13). Thanks!
> 
> Patrick
> ---
>   .editorconfig | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/.editorconfig b/.editorconfig
> index 6e4eaa8e95..82e121a417 100644
> --- a/.editorconfig
> +++ b/.editorconfig
> @@ -4,7 +4,11 @@ insert_final_newline = true
>   
>   # The settings for C (*.c and *.h) files are mirrored in .clang-format.  Keep
>   # them in sync.
> -[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile,templates/hooks/*.sample}]
> +[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile}]
> +indent_style = tab
> +tab_width = 8
> +
> +[templates/hooks/*.sample]
>   indent_style = tab
>   tab_width = 8
>   
> 
> ---
> base-commit: 7f19e4e1b6a3ad259e2ed66033e01e03b8b74c5e
> change-id: 20260311-b4-pks-editorconfig-fix-subdirs-981e6db389ec
> 
> 
Junio C Hamano· Mar 11, 2026, 17:32 UTC · re: Phillip Wood · lore

Re: [PATCH] editorconfig: fix style not applying to subdirs anymore

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 20 quoted lines
> On 11/03/2026 07:09, Patrick Steinhardt wrote:
>...
>>    If the glob contains a path separator (a / not inside square
>>    brackets), then the glob is relative to the directory level of the
>>    particular .editorconfig file itself. Otherwise the pattern may also
>>    match at any level below the .editorconfig level.
>> 
>> What's interesting is that the _whole_ expression is considered to be
>> the glob.
>
> Ouch, I'd missed that, thanks for fixing it
> ...
>>    [{{,**/}*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,{,**/}Makefile,templates/hooks/*.sample}]
>>    indent_style = tab
>>    tab_width = 8
>> 
>> This starts to become somewhat hard to read, so the duplication feels
>> like the better tradeoff.
>
> Agreed
Thanks, both.

← back to recent threads