Volume XXII, number 280Wednesday, October 7, 2026Latest message 1 hour ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

patch.editorconfig: separate tree-wide glob patterns

2 messages between Mar 15, 2026 and Mar 16, 2026, from Taylor Blau.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Taylor BlauMar 15, 2026, 21:23 UTC on lore

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(-)
Show changes to .editorconfig +8 −1
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
Taylor BlauMar 16, 2026, 00:09 UTC in reply to Taylor Blau on lore

Re: [PATCH] .editorconfig: separate tree-wide glob patterns

On Sun, Mar 15, 2026 at 05:23:31PM -0400, Taylor Blau wrote:
> ---
>  .editorconfig | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

Heh, serves me right for trying to send something to the list after vacation without being fully caught up ;-). Patrick already took care of this in his series [1].

Our approach is ever so slightly different, but the end result is the same. His patch is further along, so let's drop this one in favor of his.

Sorry for the noise :-).

Thanks, Taylor

[1]: https://lore.kernel.org/git/20260311-b4-pks-editorconfig-fix-subdirs-v1-1-4938193ccd31@pks.im/

Back to recent threads