Skip to content

Commit af087b0

Browse files
author
A.A.Abroskin
committed
Add min_version option
1 parent 93ec8a5 commit af087b0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

cmd/run.go

+32
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"path/filepath"
1313
"regexp"
1414
"sort"
15+
"strconv"
1516
"strings"
1617
"sync"
1718
"time"
@@ -57,6 +58,7 @@ const (
5758
tagsConfigKey string = "tags"
5859
pipedConfigKey string = "piped"
5960
excludeTagsConfigKey string = "exclude_tags"
61+
minVersionConfigKey string = "min_version"
6062
execMode os.FileMode = 0751
6163
)
6264

@@ -88,6 +90,10 @@ func RunCmdExecutor(args []string, fs afero.Fs) error {
8890
if os.Getenv("LEFTHOOK") == "0" {
8991
return nil
9092
}
93+
if !isVersionOk() {
94+
log.Println(au.Brown("Config error! Current Lefhook version lower than config version or 'min_version' incorrect, check format: '0.6.0'"))
95+
return errors.New("Current Lefhook version lower than config version or 'min_version' incorrect")
96+
}
9197
if tags := os.Getenv("LEFTHOOK_EXCLUDE"); tags != "" {
9298
envExcludeTags = append(envExcludeTags, strings.Split(tags, ",")[:]...)
9399
}
@@ -503,3 +509,29 @@ func makeExecutable(path string) {
503509
log.Fatal(err)
504510
}
505511
}
512+
513+
func isVersionOk() bool {
514+
if !viper.IsSet(minVersionConfigKey) {
515+
return true
516+
}
517+
518+
configVersion := viper.GetString(minVersionConfigKey)
519+
520+
configVersionSplited := strings.Split(configVersion, ".")
521+
if len(configVersionSplited) != 3 {
522+
VerbosePrint("Config min_version option have incorrect format")
523+
return false
524+
}
525+
526+
currentVersionSplited := strings.Split(version, ".")
527+
528+
for i, value := range currentVersionSplited {
529+
currentNum, _ := strconv.ParseInt(value, 0, 64)
530+
configNum, _ := strconv.ParseInt(configVersionSplited[i], 0, 64)
531+
if currentNum < configNum {
532+
return false
533+
}
534+
}
535+
536+
return true
537+
}

0 commit comments

Comments
 (0)