Skip to content

Commit 85910f4

Browse files
committed
refactor: use HasPrefix instead of regexp to check Merge message
to reduce complexity and error
1 parent bca646d commit 85910f4

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

commit-msg.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,7 @@ func validateMsg(msg string) {
110110
logAndExit(EmptyMessage)
111111
}
112112

113-
isMerge, err := regexp.MatchString(MERGE_PATTERN, msg)
114-
if err != nil {
115-
log.Println(err)
116-
logAndExit(UndefindedError)
117-
}
118-
119-
if isMerge {
113+
if strings.HasPrefix(msg, MERGE_PREFIX) {
120114
logAndExit(Merge)
121115
}
122116

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
MERGE_PATTERN = `^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/"

0 commit comments

Comments
 (0)