git pre receive hook 来检查提交消息

l a*_*a s 7 git bash shell githooks

我正在尝试编写一个预接收挂钩来使用 bash/shell 检查提交消息的模式。

如果任何提交有问题,我想拒绝整个推送。如何检索提交消息?

ffl*_*ing 4

git 文档中有一个包含解释的完整示例,涵盖了这一点。 链接到示例

粗略地翻译一下 ruby​​ 示例,我们有:

#!/bin/bash

set -eo pipefail

refname="$0"
oldrev="$1"
newrev="$2"

echo "Enforcing Policies..."

# Iterate over all the commits
for commit in $(git rev-list 538c33..d14fc7); do
  git cat-file commit "${commit}" | sed '1,/^$/d' | your-validator
done
Run Code Online (Sandbox Code Playgroud)