Skip to content

Commit

Permalink
fix: getTag return incorrect tag, if we have more than 1 tag for 1 co…
Browse files Browse the repository at this point in the history
…mmit (#1164)

* fix strategy of getting latest tag

* add git -c "versionsort.suffix=-"

* fix test

* fix tests

* add more details about change
  • Loading branch information
andriisoldatenko authored and caarlos0 committed Oct 7, 2019
1 parent 39d07c3 commit 2403a40
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/pipe/git/git.go
Expand Up @@ -74,7 +74,7 @@ func getGitInfo() (context.GitInfo, error) {
return context.GitInfo{}, errors.Wrap(err, "couldn't get remote URL")
}
tag, err := getTag()
if err != nil {
if err != nil || tag == "" {
return context.GitInfo{
Commit: full,
FullCommit: full,
Expand Down Expand Up @@ -135,7 +135,12 @@ func getFullCommit() (string, error) {
}

func getTag() (string, error) {
return git.Clean(git.Run("describe", "--tags", "--abbrev=0"))
// Even when version sort is used in git-tag[1], tagnames with the same base version
// but different suffixes are still sorted lexicographically, resulting e.g. in prerelease tags
// appearing after the main release (e.g. "1.0-rc1" after "1.0").
// This variable can be specified to determine the sorting order of tags with different suffixes.
// https://git-scm.com/docs/git-config/2.19.2#git-config-versionsortsuffix
return git.Clean(git.Run("-c", "versionsort.suffix=-", "tag", "-l", "--sort=-v:refname"))
}

func getURL() (string, error) {
Expand Down

0 comments on commit 2403a40

Please sign in to comment.