diff --git a/main.go b/main.go index 6b6a6e4..1591371 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ var rxHeader = regexp.MustCompile(`^(\[\#[0-9]+\]\s|Release|Revert|Reapply)`) func main() { // Prepare regexp templates. rxSignOff := regexp.MustCompile(`^Signed-off-by:`) + rxEmptyLine := regexp.MustCompile(`^$`) // Open current git dir. r, err := git.PlainOpen("./") @@ -69,6 +70,13 @@ func main() { return nil } + // Do not process commits shorter than 3 lines. + if len(lines) < 3 { + fail = true + fmt.Printf("Error: commit is too short [%s]\n", id) + return nil + } + // Check commit header. header := lines[0] if !rxHeader.MatchString(header) { @@ -77,6 +85,13 @@ func main() { return nil } + // Check empty line after header. + if !rxEmptyLine.MatchString(lines[1]) { + fail = true + fmt.Printf("Error: second line must be empty '%s' [%s]\n", lines[1], id) + return nil + } + // Check commit sign-off. if !rxSignOff.MatchString(lines[len(lines)-1]) { fail = true