Skip to content

Commit 0b3a780

Browse files
authored
feat: assume an initial version of 0.0.0 if no initial version is found (#43)
* feat: initial version for #29 * Couple more fixes * refactor: fixing merge conflict
1 parent 283525f commit 0b3a780

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

internal/git/git.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ func DescribeTag(tagMode string, pattern string) (string, error) {
5555
}
5656

5757
func Changelog(tag string) (string, error) {
58-
return gitLog(fmt.Sprintf("tags/%s..HEAD", tag))
58+
if tag == "" {
59+
return gitLog("HEAD")
60+
} else {
61+
return gitLog(fmt.Sprintf("tags/%s..HEAD", tag))
62+
}
5963
}
6064

6165
func run(args ...string) (string, error) {

main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func main() {
4141
tag, err := git.DescribeTag(*tagMode, *pattern)
4242
app.FatalIfError(err, "failed to get current tag for repo")
4343

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

4747
if !*metadata {
4848
current = unsetMetadata(current)
@@ -75,6 +75,18 @@ func main() {
7575
fmt.Println(getVersion(tag, *prefix, result.String(), *suffix, *stripPrefix))
7676
}
7777

78+
func getCurrentVersion(tag string) (*semver.Version, error) {
79+
var current *semver.Version
80+
var err error
81+
if tag == "" {
82+
current, err = semver.NewVersion(strings.TrimPrefix("0.0.0", *prefix))
83+
} else {
84+
current, err = semver.NewVersion(strings.TrimPrefix(tag, *prefix))
85+
}
86+
return current, err
87+
88+
}
89+
7890
func getVersion(tag, prefix, result, suffix string, stripPrefix bool) string {
7991
if stripPrefix {
8092
prefix = ""

0 commit comments

Comments
 (0)