From 48a7528cddf989f5655c6b7d839eca619761c12e Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Sun, 16 Jul 2023 20:16:41 +0200
Subject: [PATCH] fix: read log

---
 commandline.go |  3 ++-
 git.go         | 18 +++++++++++++++++-
 version.go     |  4 ++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/commandline.go b/commandline.go
index f9041ef..4232934 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 6671e8a..961bf63 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 14ae279..2ba2597 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
-- 
GitLab