Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in tag prefix trimming #12

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [0.26.0] - 15-11-2022
Fixed bug in tag prefix trimming.

## [0.24.0] - 29-09-2022
Disable strict host checking using the global flag `--disable-strict-host-check` or `-d`.
This is only intended to be used on CI where known_hosts is not cached.
Expand Down
16 changes: 9 additions & 7 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ package git
import (
"errors"
"fmt"
"net"
"os"
"regexp"
"sort"
"strings"

"github.com/Masterminds/semver/v3"
gogit "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"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/transport/ssh"
log "github.com/sirupsen/logrus"
"github.com/sky-uk/vergo/release"
cryptossh "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"net"
"os"
"regexp"
"sort"
"strings"

"github.com/sky-uk/vergo/release"
)

type SortDirection string
Expand Down Expand Up @@ -248,7 +250,7 @@ func refsWithPrefix(repo *gogit.Repository, prefix string) ([]SemverRef, error)
err = tagRefs.ForEach(func(t *plumbing.Reference) error {
tag := t.Name().String()
if re.MatchString(tag) {
versionString := strings.TrimLeft(tag, tagPrefix)
versionString := strings.TrimPrefix(tag, tagPrefix)
if version, err := semver.NewVersion(versionString); err == nil {
versions = append(versions, SemverRef{Version: version, Ref: t})
} else {
Expand Down
16 changes: 9 additions & 7 deletions git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ package git_test
import (
"errors"
"fmt"
"math"
"testing"
"time"

"github.com/Masterminds/semver/v3"
"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/stretchr/testify/assert"
"github.com/thoas/go-funk"
"go.uber.org/atomic"

"github.com/sky-uk/vergo/bump"
. "github.com/sky-uk/vergo/git"
. "github.com/sky-uk/vergo/internal-test"
"github.com/sky-uk/vergo/release"
"github.com/stretchr/testify/assert"
"github.com/thoas/go-funk"
"go.uber.org/atomic"
"math"
"testing"
"time"
)

var (
Expand Down Expand Up @@ -234,7 +236,7 @@ func TestFindLatestTagSameCommitWithPrefix(t *testing.T) {
for patch := 1; patch < 5; patch++ {
versionSuffix := fmt.Sprintf("%d.%d.%d", major, minor, patch)
t.Run(versionSuffix, func(t *testing.T) {
tagPrefix1 := "app" + postfix
tagPrefix1 := "app1" + postfix
version1 := fmt.Sprintf("%d.%d.%d", major, minor, patch)
tag1 := fmt.Sprintf("%s%s", tagPrefix1, version1)
ref1 := r.CreateTag(tag1, r.Head().Hash())
Expand Down