Skip to content

Commit fe957f0

Browse files
authored
fix(config): duplicate template names (#35)
* fix(config): duplicate template names * chore(lint): lint codes * fix(config): map cap
1 parent d4e525b commit fe957f0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/config/config.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
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

2125
type 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

Comments
 (0)