Skip to content

Commit

Permalink
fix(config): duplicate template names (#35)
Browse files Browse the repository at this point in the history
* fix(config): duplicate template names

* chore(lint): lint codes

* fix(config): map cap
  • Loading branch information
shipengqi authored Mar 16, 2024
1 parent d4e525b commit fe957f0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit fe957f0

Please sign in to comment.