开发者

Get the refname in post-receive hooks

I use git under window and I want do some operation after each push, so I use post-receive hook but when I try to get the refname to know the branch that is pushed I give anything.

Why? (I can't give also the other parameters: oldrev and newrev)

This is my post-receive file, the email are send correctly but there isn't the refname in the subject (it's the same if i put $3 in the body)

#!/bin/sh
#
# An example hook script for the "post-recei开发者_如何转开发ve" 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


The comments at the top of your script shows what is being passed and how:

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

keyword being stdin. These are not passed as arguments to the script.

You can read from the stdin using something like below:

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

done
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜