diff --git a/commandline.go b/commandline.go index f9041efa10cc97c4775016dcaeea167f8b8f956b..4232934c695840ba32e814cf1a51048c6f9c5640 100644 --- a/commandline.go +++ b/commandline.go @@ -96,7 +96,8 @@ func executeCommand() { case FixCommit: command = "patch" case OtherCommit: - fmt.Println("No changes found") + fmt.Println("No notable changes found.") + fmt.Println("If you want to force a version\nincrease, use the major, minor\nor patch command.") os.Exit(0) } diff --git a/git.go b/git.go index 6671e8a37b9703fab03bfbb39062a0524d332ef4..961bf639b7e958f7d7304d2064f87f21a05aa9d7 100644 --- a/git.go +++ b/git.go @@ -7,6 +7,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" + "github.com/go-git/go-git/v5/plumbing/storer" ) type CommitType int @@ -83,28 +84,43 @@ func getLatestTagCommit(r *git.Repository) (*object.Commit, error) { } func getCommitTypeSinceTag(r *git.Repository, tagCommit *object.Commit) (CommitType, error) { - cIter, err := r.Log(&git.LogOptions{From: tagCommit.Hash}) + cIter, err := r.Log(&git.LogOptions{}) if err != nil { return OtherCommit, fmt.Errorf("failed to get commit log: %v", err) } var commitType CommitType + found := false err = cIter.ForEach(func(commit *object.Commit) error { + if commit.Hash == tagCommit.Hash { + found = true + return storer.ErrStop // stop iteration + } + if strings.HasPrefix(commit.Message, "feat:") { commitType = FeatCommit + found = true + return storer.ErrStop // stop iteration } else if strings.HasPrefix(commit.Message, "fix:") { commitType = FixCommit } else if containsBreakingChangeFooter(commit.Message) { commitType = BreakingCommit + found = true + return storer.ErrStop // stop iteration } else { commitType = OtherCommit } + return nil }) if err != nil { return OtherCommit, fmt.Errorf("failed to iterate over commit log: %v", err) } + if !found { + return OtherCommit, fmt.Errorf("tag commit not found in commit log") + } + return commitType, nil } diff --git a/version.go b/version.go index 14ae2794c41aab19306a97970e79a099192db437..2ba259736a9b0cde3fcf33d6f8a1207c0f7f3465 100644 --- a/version.go +++ b/version.go @@ -212,6 +212,10 @@ func getVersion() (*semver.Version, error) { } func writeVersionToJson(version string) error { + if content == nil { + return fmt.Errorf("content is nil") + } + result, err := sjson.Set(string(content), arguments.Selector, version) if err != nil { return err