diff --git a/README.md b/README.md index ed53215..ecb9e1d 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,15 @@ $ make && ./_output/$(GOOS)/$(GOARCH)/bin/commitizen init ## Configuration -You can set configuration file that `.czrc` at repository root or home directory. The configuration file that located in repository root have a priority over the one in home directory. The format is the same as the following: +You can set configuration file that `.czrc` at repository root, home directory, or the `$XDG_CONFIG_HOME/commitizen` directory. + +commitizen uses the following precedence order. Each item takes precedence over the item below it: + +- per-project config file (`/path/to/my/project/.czrc`) +- per-user config file (`~/.czrc`) +- `$XDG_CONFIG_HOME` config file (`$XDG_CONFIG_HOME/commitizen/.czrc`) + +The format is the same as the following: ```yaml name: default @@ -394,4 +402,4 @@ items: format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{{.}}{{end}}{{with .footer}}\n\n{{.}}{{end}}"` ``` -![multiple-templates](https://github.com/shipengqi/illustrations/blob/e0d588dd70551344f0394cbf6671b15ae22e7635/commitizen/multiple-templates.png?raw=true) \ No newline at end of file +![multiple-templates](https://github.com/shipengqi/illustrations/blob/e0d588dd70551344f0394cbf6671b15ae22e7635/commitizen/multiple-templates.png?raw=true) diff --git a/go.mod b/go.mod index 3ca00c4..360f4da 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23 require ( github.com/charmbracelet/huh v0.6.0 github.com/mitchellh/mapstructure v1.5.0 - github.com/onsi/ginkgo/v2 v2.21.0 + github.com/onsi/ginkgo/v2 v2.22.0 github.com/onsi/gomega v1.35.1 github.com/shipengqi/component-base v0.2.11 github.com/shipengqi/golib v0.2.18 diff --git a/go.sum b/go.sum index 950dce0..474d74d 100644 --- a/go.sum +++ b/go.sum @@ -76,8 +76,8 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg= github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ= -github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM= -github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= +github.com/onsi/ginkgo/v2 v2.22.0 h1:Yed107/8DjTr0lKCNt7Dn8yQ6ybuDRQoMGrNFKzMfHg= +github.com/onsi/ginkgo/v2 v2.22.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4= github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/internal/config/config.go b/internal/config/config.go index f939ea0..354ac2f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -35,13 +35,26 @@ func New() *Config { func (c *Config) initialize() error { var fpath string + // Check if the configuration file is local to the repo. if fsutil.IsExists(RCFilename) { fpath = RCFilename } else { + // Check if the configuration file is in the user's home directory. home := sysutil.HomeDir() p := filepath.Join(home, RCFilename) if fsutil.IsExists(p) { fpath = p + } else { + // Check if the configuration file is in the configured + // XDG_CONFIG_HOME directory. + xdgConfigHome, found := os.LookupEnv("XDG_CONFIG_HOME") + if !found { + xdgConfigHome = sysutil.HomeDir() + } + xdgConfigPath := filepath.Join(xdgConfigHome, "commitizen", RCFilename) + if fsutil.IsExists(xdgConfigPath) { + fpath = xdgConfigPath + } } }