2011-10-14 27 views
0

我在窗口中使用git,並且我想在每次push後做一些操作,所以我使用post-receive hook,但是當我試圖讓refname知道推送的分支時,我給任何東西。在post-receive鉤子中獲取refname

爲什麼? (我不能也給其他參數:oldrevnewrev

這是我的後收到的文件,電子郵件被正確發送,但沒有在這一主題的refname(它如果我把$3相同在體內)

#!/bin/sh 
# 
# An example hook script for the "post-receive" event. 
# 
# The "post-receive" script is run after receive-pack has accepted a pack 
# and the repository has been updated. It is passed arguments in through 
# stdin in the form 
# <oldrev> <newrev> <refname> 
# For example: 
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master 
# 
# see contrib/hooks/ for a sample, or uncomment the next line and 
# rename the file to "post-receive". 

#. /usr/share/doc/git-core/contrib/hooks/post-receive-email  

# send mail 
last_comment=$(git log -n 1 HEAD --format=format:%s%n%b) 
last_change=$(git log -1 --name-status) 
msmtp $(git config hooks.mailinglist) <<EOI 
Subject: [GIT] ($3) Sources update 
$last_change 
EOI 
+0

這將幫助,如果你在你的問題包括你正在使用的'後receive'掛機腳本,讓人們有機會猜測什麼是錯的。常見錯誤是'oldrev newrev refname'在標準輸入上提供,而不是作爲命令行參數提供。 –

回答

2

在腳本頂部的註釋顯示正在傳遞和如何:

It is passed arguments in through 
# stdin in the form 
# <oldrev> <newrev> <refname> 

關鍵字是stdin。這些不作爲參數傳遞給腳本。

您可以使用類似下面從標準輸入讀取:

while read oldrev newrev refname 
do 
    # Do what you want with $oldrev $newrev $refname 

done 
+0

是的,你是真的。我不經常和深入地使用bash腳本。謝謝 –

+0

在這種情況下,提交循環以相反的順序(從上次到第一次)。我們可以改變這個順序嗎?也許收集他們在陣列和排序... – milkovsky