在post-receive钩子中获取refname

时间:2011-10-14 12:03:46

标签: windows git githooks

我在窗口下使用git并且我希望在每次推送后执行一些操作,所以我使用post-receive hook但是当我尝试让refname知道推送的分支时,我给出任何东西。

为什么呢? (我也不能给出其他参数:oldrevnewrev

这是我的收件后文件,电子邮件发送正确,但主题中没有引用名称(如果我将$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

1 个答案:

答案 0 :(得分:2)

脚本顶部的注释显示了传递内容以及如何:

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

关键字为stdin。这些不作为参数传递给脚本。

您可以使用以下内容从stdin读取:

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

done