hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 3e4fbbaae44cb0e0e59d60ca9385757c356b942b
parent 99e5fc63c2d3536d53aca40296a9fe280ce91a4e
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Mon, 26 Dec 2016 14:03:50 +0100

helpers: Add patch version

Fixes #2832

Diffstat:
Mhelpers/hugo.go | 24++++++++++++++++++------
Mhelpers/hugo_test.go | 10+++++++---
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/helpers/hugo.go b/helpers/hugo.go
@@ -19,7 +19,13 @@ import (
 
 // HugoVersionNumber represents the current build version.
 // This should be the only one
-const HugoVersionNumber = 0.19
+const (
+	// Major and minor version.
+	HugoVersionNumber = 0.19
+
+	// Increment this for bug releases
+	HugoPatchVersion = 0
+)
 
 // HugoVersionSuffix is the suffix used in the Hugo version string.
 // It will be blank for release versions.
@@ -29,23 +35,29 @@ const HugoVersionSuffix = "-DEV" // use this when not doing a release
 // HugoVersion returns the current Hugo version. It will include
 // a suffix, typically '-DEV', if it's development version.
 func HugoVersion() string {
-	return hugoVersion(HugoVersionNumber, HugoVersionSuffix)
+	return hugoVersion(HugoVersionNumber, HugoPatchVersion, HugoVersionSuffix)
 }
 
 // HugoReleaseVersion is same as HugoVersion, but no suffix.
 func HugoReleaseVersion() string {
-	return hugoVersionNoSuffix(HugoVersionNumber)
+	return hugoVersionNoSuffix(HugoVersionNumber, HugoPatchVersion)
 }
 
 // NextHugoReleaseVersion returns the next Hugo release version.
 func NextHugoReleaseVersion() string {
-	return hugoVersionNoSuffix(HugoVersionNumber + 0.01)
+	return hugoVersionNoSuffix(HugoVersionNumber+0.01, 0)
 }
 
-func hugoVersion(version float32, suffix string) string {
+func hugoVersion(version float32, patchVersion int, suffix string) string {
+	if patchVersion > 0 {
+		return fmt.Sprintf("%.2g.%d%s", version, patchVersion, suffix)
+	}
 	return fmt.Sprintf("%.2g%s", version, suffix)
 }
 
-func hugoVersionNoSuffix(version float32) string {
+func hugoVersionNoSuffix(version float32, patchVersion int) string {
+	if patchVersion > 0 {
+		return fmt.Sprintf("%.2g.%d", version, patchVersion)
+	}
 	return fmt.Sprintf("%.2g", version)
 }
diff --git a/helpers/hugo_test.go b/helpers/hugo_test.go
@@ -14,11 +14,15 @@
 package helpers
 
 import (
-	"github.com/stretchr/testify/assert"
 	"testing"
+
+	"github.com/stretchr/testify/assert"
 )
 
 func TestHugoVersion(t *testing.T) {
-	assert.Equal(t, "0.15-DEV", hugoVersion(0.15, "-DEV"))
-	assert.Equal(t, "0.17", hugoVersionNoSuffix(0.16+0.01))
+	assert.Equal(t, "0.15-DEV", hugoVersion(0.15, 0, "-DEV"))
+	assert.Equal(t, "0.17", hugoVersionNoSuffix(0.16+0.01, 0))
+
+	assert.Equal(t, "0.15.2-DEV", hugoVersion(0.15, 2, "-DEV"))
+	assert.Equal(t, "0.17.3", hugoVersionNoSuffix(0.16+0.01, 3))
 }