@@ -12,6 +12,7 @@ import (
12
12
"path/filepath"
13
13
"regexp"
14
14
"sort"
15
+ "strconv"
15
16
"strings"
16
17
"sync"
17
18
"time"
@@ -57,6 +58,7 @@ const (
57
58
tagsConfigKey string = "tags"
58
59
pipedConfigKey string = "piped"
59
60
excludeTagsConfigKey string = "exclude_tags"
61
+ minVersionConfigKey string = "min_version"
60
62
execMode os.FileMode = 0751
61
63
)
62
64
@@ -88,6 +90,10 @@ func RunCmdExecutor(args []string, fs afero.Fs) error {
88
90
if os .Getenv ("LEFTHOOK" ) == "0" {
89
91
return nil
90
92
}
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
+ }
91
97
if tags := os .Getenv ("LEFTHOOK_EXCLUDE" ); tags != "" {
92
98
envExcludeTags = append (envExcludeTags , strings .Split (tags , "," )[:]... )
93
99
}
@@ -503,3 +509,29 @@ func makeExecutable(path string) {
503
509
log .Fatal (err )
504
510
}
505
511
}
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