Git 预推钩
**** git push
在检查远程状态后,但在推送任何内容之前调用 pre-push 脚本。如果此脚本以非零状态退出,则不会推送任何内容。
使用以下参数调用此挂钩:
$1 -- Name of the remote to which the push is being done (Ex: origin)
$2 -- URL to which the push is being done (Ex: https://<host>:<port>/<username>/<project_name>.git)
有关正在推送的提交的信息作为行提供给表单中的标准输入:
<local_ref> <local_sha1> <remote_ref> <remote_sha1>
样本值:
local_ref = refs/heads/master
local_sha1 = 68a07ee4f6af8271dc40caae6cc23f283122ed11
remote_ref = refs/heads/master
remote_sha1 = efd4d512f34b11e3cf5c12433bbedd4b1532716f
下面的示例预推脚本是从默认的 pre-push.sample 中获取的,当使用 git init
初始化新的存储库时会自动创建
# This sample shows how to prevent push of commits where the log message starts
# with "WIP" (work in progress).
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" = $z40 ]
then
# Handle delete
:
else
if [ "$remote_sha" = $z40 ]
then
# New branch, examine all commits
range="$local_sha"
else
# Update to existing branch, examine new commits
range="$remote_sha..$local_sha"
fi
# Check for WIP commit
commit=`git rev-list -n 1 --grep '^WIP' "$range"`
if [ -n "$commit" ]
then
echo >&2 "Found WIP commit in $local_ref, not pushing"
exit 1
fi
fi
done
exit 0