Skip to content

Commit 8a1b789

Browse files
pks-tgitster
authored andcommitted
editorconfig: fix style not applying to subdirs anymore
In 046e111 (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> Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7f19e4e commit 8a1b789

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

.editorconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ insert_final_newline = true
44

55
# The settings for C (*.c and *.h) files are mirrored in .clang-format. Keep
66
# them in sync.
7-
[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile,templates/hooks/*.sample}]
7+
[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile}]
8+
indent_style = tab
9+
tab_width = 8
10+
11+
[templates/hooks/*.sample]
812
indent_style = tab
913
tab_width = 8
1014

0 commit comments

Comments
 (0)