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