diff --git a/internal/config/config.go b/internal/config/config.go index 8ca5943..d340d65 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -3,6 +3,7 @@ package config import ( "bytes" "errors" + "fmt" "io" "os" "path/filepath" @@ -16,7 +17,10 @@ import ( "github.com/shipengqi/commitizen/internal/ui" ) -const RCFilename = ".git-czrc" +const ( + RCFilename = ".git-czrc" + ReservedDefaultName = "default" +) type Config struct { defaultTmpl *render.Template @@ -43,6 +47,7 @@ func (c *Config) initialize() error { if err != nil { return err } + exists := make(map[string]struct{}, len(tmpls)) for _, v := range tmpls { if v.Default { if c.defaultTmpl != nil { @@ -52,6 +57,14 @@ func (c *Config) initialize() error { c.defaultTmpl = v continue } + if v.Name == ReservedDefaultName { + return errors.New("template name 'default' is reserved, use 'default' as the template name, default must be true") + } + if _, ok := exists[v.Name]; ok { + return fmt.Errorf("duplicate template '%s'", v.Name) + } + + exists[v.Name] = struct{}{} c.others = append(c.others, v) } // If the user has not configured a default template, use the built-in template as the default template