From ce7dcd7439ba7ff381de7e1d0d2e7bc43fd9363f Mon Sep 17 00:00:00 2001 From: Marlon Kranz Date: Mon, 26 Oct 2026 01:58:06 +0100 Subject: [PATCH] matugen: keep user templates when config.toml has no [config] table (#3921) --- core/internal/matugen/matugen.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/internal/matugen/matugen.go b/core/internal/matugen/matugen.go index 762724a36..bbb4d2ea9 100644 --- a/core/internal/matugen/matugen.go +++ b/core/internal/matugen/matugen.go @@ -665,7 +665,7 @@ func userConfigSection(opts *Options) string { if err != nil { return "[config]\n\n" } - section := extractTOMLSection(string(data), "[config]", "[templates]") + section := extractTOMLSection(string(data), "[config]", "\n[templates") if section == "" { return "[config]\n\n" } @@ -741,7 +741,7 @@ output_path = '%s' if opts.RunUserTemplates { if data, err := os.ReadFile(userConfigPath); err == nil { - templatesSection := extractTOMLSection(string(data), "[templates]", "") + templatesSection := extractTOMLSection("\n"+string(data), "\n[templates", "\n[config]") if templatesSection != "" { cfgFile.WriteString(templatesSection) cfgFile.WriteString("\n") @@ -1211,11 +1211,7 @@ func writeDryRunConfig(opts *Options) (string, error) { } defer cfgFile.Close() - section := userConfigSection(opts) - if idx := strings.Index(section, "\n[templates"); idx != -1 { - section = section[:idx+1] - } - cfgFile.WriteString(section) + cfgFile.WriteString(userConfigSection(opts)) cfgFile.WriteString("[templates]\n") return cfgFile.Name(), nil }