Skip to content

Commit

Permalink
feat: assume an initial version of 0.0.0 if no initial version is fou…
Browse files Browse the repository at this point in the history
…nd (#43)

* feat: initial version for #29

* Couple more fixes

* refactor: fixing merge conflict
  • Loading branch information
drewstinnett authored Nov 17, 2021
1 parent 283525f commit 0b3a780
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func DescribeTag(tagMode string, pattern string) (string, error) {
}

func Changelog(tag string) (string, error) {
return gitLog(fmt.Sprintf("tags/%s..HEAD", tag))
if tag == "" {
return gitLog("HEAD")
} else {
return gitLog(fmt.Sprintf("tags/%s..HEAD", tag))
}
}

func run(args ...string) (string, error) {
Expand Down
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func main() {
tag, err := git.DescribeTag(*tagMode, *pattern)
app.FatalIfError(err, "failed to get current tag for repo")

current, err := semver.NewVersion(strings.TrimPrefix(tag, *prefix))
app.FatalIfError(err, "version %s is not semantic", tag)
current, err := getCurrentVersion(tag)
app.FatalIfError(err, "could not get current version from tag: '%s'", tag)

if !*metadata {
current = unsetMetadata(current)
Expand Down Expand Up @@ -75,6 +75,18 @@ func main() {
fmt.Println(getVersion(tag, *prefix, result.String(), *suffix, *stripPrefix))
}

func getCurrentVersion(tag string) (*semver.Version, error) {
var current *semver.Version
var err error
if tag == "" {
current, err = semver.NewVersion(strings.TrimPrefix("0.0.0", *prefix))
} else {
current, err = semver.NewVersion(strings.TrimPrefix(tag, *prefix))
}
return current, err

}

func getVersion(tag, prefix, result, suffix string, stripPrefix bool) string {
if stripPrefix {
prefix = ""
Expand Down

0 comments on commit 0b3a780

Please sign in to comment.