Skip to content

Commit 25a9185

Browse files
committed
fix: pre release string resets
1 parent 83c5ef6 commit 25a9185

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

.commitlog.release

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.0.0-beta.0
1+
v2.0.1

commands/release.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ func Release(c *cli.Context) (err error) {
1818
fileDir := c.String("path")
1919
filePath := path.Join(fileDir, ".commitlog.release")
2020

21+
if !(c.Bool("init") || c.Bool("major") || c.Bool("minor") || c.Bool("patch") || c.Bool("pre")) {
22+
err = fmt.Errorf("[commitlog] need at least one increment flag to move ahead")
23+
return
24+
}
25+
2126
if c.Bool("init") {
2227
_, err = os.Stat(filePath)
2328
if os.IsNotExist(err) {
@@ -54,15 +59,15 @@ func Release(c *cli.Context) (err error) {
5459
}
5560

5661
if c.Bool("major") {
57-
releaserOpts = append(releaserOpts, pkg.WithMajorIncrement(), pkg.WithMinorReset(), pkg.WithPatchReset())
62+
releaserOpts = append(releaserOpts, pkg.WithClearPrerelease(), pkg.WithMajorIncrement(), pkg.WithMinorReset(), pkg.WithPatchReset())
5863
}
5964

6065
if c.Bool("minor") {
61-
releaserOpts = append(releaserOpts, pkg.WithMinorIncrement(), pkg.WithPatchReset())
66+
releaserOpts = append(releaserOpts, pkg.WithClearPrerelease(), pkg.WithMinorIncrement(), pkg.WithPatchReset())
6267
}
6368

6469
if c.Bool("patch") {
65-
releaserOpts = append(releaserOpts, pkg.WithPatchIncrement())
70+
releaserOpts = append(releaserOpts, pkg.WithClearPrerelease(), pkg.WithPatchIncrement())
6671
}
6772

6873
if c.Bool("pre") {

main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func main() {
8181
Flags: []cli.Flag{
8282
&cli.BoolFlag{
8383
Name: "init",
84+
Value: false,
8485
Usage: "initialise commitlog release",
8586
},
8687
&cli.StringFlag{
@@ -91,7 +92,8 @@ func main() {
9192
"(note: do not use `--commit` or `--push` if the file isn't in the root)",
9293
},
9394
&cli.BoolFlag{
94-
Name: "pre",
95+
Name: "pre",
96+
Value: false,
9597
Usage: "create a pre-release version. will default to patch increment unless" +
9698
"specified and not already a pre-release",
9799
},
@@ -102,14 +104,17 @@ func main() {
102104
},
103105
&cli.BoolFlag{
104106
Name: "major",
107+
Value: false,
105108
Usage: "create a major version",
106109
},
107110
&cli.BoolFlag{
108111
Name: "minor",
112+
Value: false,
109113
Usage: "create a minor version",
110114
},
111115
&cli.BoolFlag{
112116
Name: "patch",
117+
Value: false,
113118
Usage: "create a patch version",
114119
},
115120
&cli.BoolFlag{

pkg/releaser.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ func WithPrereleaseReset() ReleaserMod {
172172
preParts := strings.Split(r.v.preString, ".")
173173
// reset something like `beta.1` to `beta.0`
174174
preParts[1] = strconv.Itoa(0)
175-
r.next.preString = strings.Join(preParts[:], ".")
175+
nextPreString := strings.Join(preParts[:], ".")
176+
nextPreString = strings.TrimPrefix(nextPreString, "-")
177+
r.next.preString = nextPreString
176178
}
177179
}
178180

0 commit comments

Comments
 (0)