當GIT中接收一推,所述post-receive
鉤被調用和傳遞關於以後被輸送的每個參考文獻的標準輸入數據,在<old-sha> <new-sha> <ref-name>
行,像這樣:
e1f5c274e296f1c5148161f9d4e5eb43a6743e54 1eea3f51cf926c3710f8fa4a06f503041c4597f0 refs/heads/master
當分支被刪除時,<new-sha>
項全部爲零,就像這樣:
6b239c481453c7fc2513b02e8aa0cd9c1ffa25cb 0000000000000000000000000000000000000000 refs/heads/foo
所以,你可以使用邏輯諸如調整post-receive
鉤來檢測它(並阻止這個分支從觸發部署):
#!/bin/sh -
while read OLDSHA NEWSHA REF ; do
if [ "$NEWSHA" = "0000000000000000000000000000000000000000" ]; then
# This ref has been deleted! Respond appropriately.
fi
done
請記住,單次推送也可以包含更新多個分支!您可能需要累積應部署的一組分支,該分支以適當的前綴開始並且具有非零值NEWSHA
。
這是缺少的部分,非常感謝! –