@@ -3,6 +3,7 @@ package config
3
3
import (
4
4
"bytes"
5
5
"errors"
6
+ "fmt"
6
7
"io"
7
8
"os"
8
9
"path/filepath"
@@ -16,7 +17,10 @@ import (
16
17
"github.com/shipengqi/commitizen/internal/ui"
17
18
)
18
19
19
- const RCFilename = ".git-czrc"
20
+ const (
21
+ RCFilename = ".git-czrc"
22
+ ReservedDefaultName = "default"
23
+ )
20
24
21
25
type Config struct {
22
26
defaultTmpl * render.Template
@@ -43,6 +47,7 @@ func (c *Config) initialize() error {
43
47
if err != nil {
44
48
return err
45
49
}
50
+ exists := make (map [string ]struct {}, len (tmpls ))
46
51
for _ , v := range tmpls {
47
52
if v .Default {
48
53
if c .defaultTmpl != nil {
@@ -52,6 +57,14 @@ func (c *Config) initialize() error {
52
57
c .defaultTmpl = v
53
58
continue
54
59
}
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 {}{}
55
68
c .others = append (c .others , v )
56
69
}
57
70
// If the user has not configured a default template, use the built-in template as the default template
0 commit comments