From 6dd48c2458a39f060fcfb250baa0aa952328f03b Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sat, 21 Jan 2023 23:29:44 -0300 Subject: [PATCH] feat: support empty overwrite for tag.filter and tag.pattern issue: #84 --- cmd/git-sv/config.go | 6 ++++-- cmd/git-sv/handlers.go | 2 +- sv/config.go | 14 +++++++------- sv/git.go | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/git-sv/config.go b/cmd/git-sv/config.go index ceb9458..755b7c7 100644 --- a/cmd/git-sv/config.go +++ b/cmd/git-sv/config.go @@ -69,6 +69,8 @@ func readConfig(filepath string) (Config, error) { func defaultConfig() Config { skipDetached := false + pattern := "%d.%d.%d" + filter := "" return Config{ Version: "1.1", Versioning: sv.VersioningConfig{ @@ -78,8 +80,8 @@ func defaultConfig() Config { IgnoreUnknown: false, }, Tag: sv.TagConfig{ - Pattern: "%d.%d.%d", - Filter: "", + Pattern: &pattern, + Filter: &filter, }, ReleaseNotes: sv.ReleaseNotesConfig{ Sections: []sv.ReleaseNotesSectionConfig{ diff --git a/cmd/git-sv/handlers.go b/cmd/git-sv/handlers.go index 9f99266..ec67bb1 100644 --- a/cmd/git-sv/handlers.go +++ b/cmd/git-sv/handlers.go @@ -209,7 +209,7 @@ func getTags(git sv.Git, tag string) (string, sv.GitTag, error) { index := find(tag, tags) if index < 0 { - return "", sv.GitTag{}, fmt.Errorf("tag: %s not found", tag) + return "", sv.GitTag{}, fmt.Errorf("tag: %s not found, check tag filter", tag) } previousTag := "" diff --git a/sv/config.go b/sv/config.go index 264755b..5d76634 100644 --- a/sv/config.go +++ b/sv/config.go @@ -4,11 +4,11 @@ package sv // CommitMessageConfig config a commit message. type CommitMessageConfig struct { - Types []string `yaml:"types,flow"` - HeaderSelector string `yaml:"header-selector"` - Scope CommitMessageScopeConfig `yaml:"scope"` - Footer map[string]CommitMessageFooterConfig `yaml:"footer"` - Issue CommitMessageIssueConfig `yaml:"issue"` + Types []string `yaml:"types,flow"` + HeaderSelector string `yaml:"header-selector"` + Scope CommitMessageScopeConfig `yaml:"scope"` + Footer map[string]CommitMessageFooterConfig `yaml:"footer"` + Issue CommitMessageIssueConfig `yaml:"issue"` } // IssueFooterConfig config for issue. @@ -62,8 +62,8 @@ type VersioningConfig struct { // TagConfig tag preferences. type TagConfig struct { - Pattern string `yaml:"pattern"` - Filter string `yaml:"filter"` + Pattern *string `yaml:"pattern"` + Filter *string `yaml:"filter"` } // ==== Release Notes ==== diff --git a/sv/git.go b/sv/git.go index f282be1..5926004 100644 --- a/sv/git.go +++ b/sv/git.go @@ -83,7 +83,7 @@ func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl { // LastTag get last tag, if no tag found, return empty. func (g GitImpl) LastTag() string { - cmd := exec.Command("git", "for-each-ref", "refs/tags/"+g.tagCfg.Filter, "--sort", "-creatordate", "--format", "%(refname:short)", "--count", "1") + cmd := exec.Command("git", "for-each-ref", "refs/tags/"+*g.tagCfg.Filter, "--sort", "-creatordate", "--format", "%(refname:short)", "--count", "1") out, err := cmd.CombinedOutput() if err != nil { return "" @@ -131,7 +131,7 @@ func (g GitImpl) Commit(header, body, footer string) error { // Tag create a git tag. func (g GitImpl) Tag(version semver.Version) (string, error) { - tag := fmt.Sprintf(g.tagCfg.Pattern, version.Major(), version.Minor(), version.Patch()) + tag := fmt.Sprintf(*g.tagCfg.Pattern, version.Major(), version.Minor(), version.Patch()) tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch()) tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg) @@ -148,7 +148,7 @@ func (g GitImpl) Tag(version semver.Version) (string, error) { // Tags list repository tags. func (g GitImpl) Tags() ([]GitTag, error) { - cmd := exec.Command("git", "for-each-ref", "--sort", "creatordate", "--format", "%(creatordate:iso8601)#%(refname:short)", "refs/tags/"+g.tagCfg.Filter) + cmd := exec.Command("git", "for-each-ref", "--sort", "creatordate", "--format", "%(creatordate:iso8601)#%(refname:short)", "refs/tags/"+*g.tagCfg.Filter) out, err := cmd.CombinedOutput() if err != nil { return nil, combinedOutputErr(err, out)