Skip to content

Commit a767625

Browse files
committed
fix: add default value for broken or missing config attribute
cause: if cfg.json exists, but some attributes missing, then those attributes will become ZERO VALUE, e.g. 0, false. which make it behave abnormal. solve: add default value
1 parent 85910f4 commit a767625

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
MERGE_PREFIX = `Merge `
10+
MERGE_PREFIX = `Merge `
1111
HEADER_PATTERN = `^((fixup! |squash! )?(\w+)(?:\(([^\)\s]+)\))?: (.+))(?:\n|$)`
1212
CONFIG_FILE_NAME = "commit-msg.cfg.json"
1313
HOOK_DIR = "./.git/hooks/"
@@ -81,8 +81,9 @@ func loadConfig(path string) *GlobalConfig {
8181
return nil
8282
}
8383
defer f.Close()
84+
8485
dec := json.NewDecoder(f)
85-
var cfg GlobalConfig
86+
cfg := GlobalConfig{"en", false, 80}
8687
if err := dec.Decode(&cfg); err != nil {
8788
return nil
8889
}

0 commit comments

Comments
 (0)