From 804d988002d6598399c997c62c902bd87a3e38ca Mon Sep 17 00:00:00 2001 From: LofiSu Date: Mon, 9 Feb 2026 13:46:18 +0800 Subject: [PATCH] chore: add pre-commit hook to reject *@bytedance.com author/committer email Co-authored-by: Cursor --- .githooks/pre-commit | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..f18ee5b --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,29 @@ +#!/bin/sh +# Reject commit if author or committer email is *@bytedance.com + +config_email="$(git config user.email)" +author_email="${GIT_AUTHOR_EMAIL:-$config_email}" +committer_email="${GIT_COMMITTER_EMAIL:-$config_email}" + +check() { + case "$1" in + *@bytedance.com) return 0;; # matched = bad + *) return 1;; + esac +} + +err=0 +if check "$author_email"; then + echo "pre-commit: 拒绝提交:作者邮箱不能为 *@bytedance.com (当前: $author_email)" + err=1 +fi +if check "$committer_email"; then + echo "pre-commit: 拒绝提交:提交者邮箱不能为 *@bytedance.com (当前: $committer_email)" + err=1 +fi + +if [ $err -eq 1 ]; then + echo "请使用: git config user.email \"lofisuchat@gmail.com\"" + exit 1 +fi +exit 0