diff --git a/cmd/git-sv/config.go b/cmd/git-sv/config.go index a7ed36f..d95381b 100644 --- a/cmd/git-sv/config.go +++ b/cmd/git-sv/config.go @@ -52,7 +52,7 @@ func combinedOutputErr(err error, out []byte) error { return fmt.Errorf("%v - %s", err, msg[0]) } -func loadConfig(filepath string) (Config, error) { +func readConfig(filepath string) (Config, error) { content, rerr := ioutil.ReadFile(filepath) if rerr != nil { return Config{}, rerr diff --git a/cmd/git-sv/main.go b/cmd/git-sv/main.go index f446991..6ebfade 100644 --- a/cmd/git-sv/main.go +++ b/cmd/git-sv/main.go @@ -10,7 +10,7 @@ import ( ) // Version for git-sv. -var Version = "" +var Version = "source" const ( configFilename = "config.yml" @@ -20,32 +20,7 @@ const ( func main() { log.SetFlags(0) - envCfg := loadEnvConfig() - - cfg := defaultConfig() - - if envCfg.Home != "" { - if homeCfg, err := loadConfig(filepath.Join(envCfg.Home, configFilename)); err == nil { - if merr := merge(&cfg, homeCfg); merr != nil { - log.Fatal("failed to merge user config, error: ", merr) - } - } - } - - repoPath, rerr := getRepoPath() - if rerr != nil { - log.Fatal("failed to get repository path, error: ", rerr) - } - - if repoCfg, err := loadConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil { - if merr := merge(&cfg, repoCfg); merr != nil { - log.Fatal("failed to merge repo config, error: ", merr) - } - if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten - cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers - } - } - + cfg := loadCfg() messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches) git := sv.NewGit(messageProcessor, cfg.Tag) semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage) @@ -168,3 +143,33 @@ func main() { log.Fatal("failed to run cli, error: ", apperr) } } + +func loadCfg() Config { + envCfg := loadEnvConfig() + + cfg := defaultConfig() + + if envCfg.Home != "" { + if homeCfg, err := readConfig(filepath.Join(envCfg.Home, configFilename)); err == nil { + if merr := merge(&cfg, homeCfg); merr != nil { + log.Fatal("failed to merge user config, error: ", merr) + } + } + } + + repoPath, rerr := getRepoPath() + if rerr != nil { + log.Fatal("failed to get repository path, error: ", rerr) + } + + if repoCfg, err := readConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil { + if merr := merge(&cfg, repoCfg); merr != nil { + log.Fatal("failed to merge repo config, error: ", merr) + } + if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten + cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers + } + } + + return cfg +}