[PATCH] .editorconfig: separate tree-wide glob patterns
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Mar 15, 2026, 21:23 UTC
- Message-ID
- <518d71de9cdd71d0fc259740cf0da075bcf79746.1773609807.git.me@ttaylorr.com>
In 046e1117d5d (templates: add .gitattributes entry for sample hooks, 2026-02-13), we added a sub-directory specific pattern to our .editorconfig's main section. Prior to 046e1117d5d, all glob patterns within that section applied to files at any level in the tree (e.g., the `*.c` rule matched both "pack-objects.c" and "builtin/pack-objects.c").
Ordinarily, we would expect that the change in 046e1117d5d would not have an effect outside of applying our settings to `templates/hooks/*.sample` in addition to the existing globs, that is not the case.
The EditorConfig specification has a quirk[1] which changes the behavior of globbed patterns when the section contains patterns which contain path separators. Namely:
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. [...]While it seems like this should apply only within a particular glob (e.g., in a section covering `{*.foo,bar/*.baz}` all `*.foo` files (at any level of the tree) should match, but `*.baz` files match only when they are within directory `bar`), it seems to apply to *all* globs within that section's filter.
In practice, this means that a file like "builtin/pack-objects.c" would have matched the rules in our main section until commit 046e1117d5d was applied, but no longer afterwords.
(It's possible that this isn't what the specification intends and that instead I'm observing implementation-specific quirks. I first saw this in vim-editorconfig, which is quite popular, so perhaps this is part of the de-facto specification.)
To ensure that these rules are applied in a pre-046e1117d5d fashion, split this section in two: one for patterns that don't contain path separators and another for ones that do. This restores the pre-046e1117d5d behavior where, e.g., our `*.c` rule matches C files at any level within the tree.
Add a brief note above this rule in an attempt to prevent similar changes in the future.
[1]: https://spec.editorconfig.org/#glob-expressions
Signed-off-by: Taylor Blau <me@ttaylorr.com> --- .editorconfig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/.editorconfig b/.editorconfig index 6e4eaa8e955..d06f5c6100b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,14 @@ 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}] +# +# Only list glob patterns intended to match throughout the entire tree. Create +# new rules for files in specific sub-directories (as below), if needed. +[{*.{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: dc6ecd5354dca88d51b6d6562777fc8fc10d77e1
-- 2.53.0.308.g50d063e335a