#!/bin/sh

commit_regex='^Merge.+|(feat|fix|docs|style|refactor|perf|test|chore|build|merge)(\(.+\))?: .*'
TEMPLATE='# 提交格式：

# <type>: <subject>

# 格式说明：

# type 为 commit 的类型，总共有以下 10 个类型：

# feat: 添加了一个新功能
# fix: 修复了一个 bug
# docs: 注释文档发生修改
# style: 不影响代码运行的更改（空格，格式等）
# refactor: 重构代码且不引进新的功能或修复 bug
# perf: 代码优化
# test: 添加或修改测试用例
# build: 构建工具或外部依赖的更改（gradle等）
# chore: 除上述之外的修改
# revert: 撤销改动先前的
# merge: 合并分支'

if ! grep -iqE "$commit_regex" "$1"; then
    echo
    echo "`cat $1`"
    echo
    echo "提交信息格式不规范，提交失败！"
    echo
    echo "$TEMPLATE"
    echo
	exit 1
fi
