From 5b51fab30f3be2b14b2aceecb3b570f76437b986 Mon Sep 17 00:00:00 2001 From: Simon Prochazka Date: Sat, 19 Oct 2019 20:29:26 +0200 Subject: [PATCH] fix: add all commits if previous tag is not available - in new repositories previous tag is not available, this will allow for iterating all unreleased commits --- cmd/publish.go | 8 +++++++- go.mod | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/publish.go b/cmd/publish.go index 5ccdf24..60136e1 100644 --- a/cmd/publish.go +++ b/cmd/publish.go @@ -5,11 +5,12 @@ import ( "fmt" "strings" - "github.com/commitsar-app/git/pkg" + history "github.com/commitsar-app/git/pkg" "github.com/commitsar-app/release-notary/internal/releaser" "github.com/commitsar-app/release-notary/internal/text" "github.com/spf13/cobra" "github.com/spf13/viper" + "gopkg.in/src-d/go-git.v4/plumbing" ) func init() { @@ -44,6 +45,11 @@ var publishCmd = &cobra.Command{ return err } + // If previous tag is not available, provide empty hash so that all commits are iterated. + if err == history.ErrPrevTagNotAvailable { + lastTag = plumbing.Hash{} + } + commits, err := repo.CommitsBetween(currentCommit.Hash, lastTag) if err != nil { diff --git a/go.mod b/go.mod index 41e79b7..09f2776 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,5 @@ require ( github.com/spf13/cobra v0.0.5 github.com/spf13/viper v1.4.0 github.com/stretchr/testify v1.4.0 + gopkg.in/src-d/go-git.v4 v4.13.1 )