@@ -3,6 +3,7 @@ package config
33import (
44 "bytes"
55 "errors"
6+ "fmt"
67 "io"
78 "os"
89 "path/filepath"
@@ -16,7 +17,10 @@ import (
1617 "github.com/shipengqi/commitizen/internal/ui"
1718)
1819
19- const RCFilename = ".git-czrc"
20+ const (
21+ RCFilename = ".git-czrc"
22+ ReservedDefaultName = "default"
23+ )
2024
2125type Config struct {
2226 defaultTmpl * render.Template
@@ -43,6 +47,7 @@ func (c *Config) initialize() error {
4347 if err != nil {
4448 return err
4549 }
50+ exists := make (map [string ]struct {}, len (tmpls ))
4651 for _ , v := range tmpls {
4752 if v .Default {
4853 if c .defaultTmpl != nil {
@@ -52,6 +57,14 @@ func (c *Config) initialize() error {
5257 c .defaultTmpl = v
5358 continue
5459 }
60+ if v .Name == ReservedDefaultName {
61+ return errors .New ("template name 'default' is reserved, use 'default' as the template name, default must be true" )
62+ }
63+ if _ , ok := exists [v .Name ]; ok {
64+ return fmt .Errorf ("duplicate template '%s'" , v .Name )
65+ }
66+
67+ exists [v .Name ] = struct {}{}
5568 c .others = append (c .others , v )
5669 }
5770 // If the user has not configured a default template, use the built-in template as the default template
0 commit comments