Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git post接收钩子,用于抓取提交消息并发回URL_Git_Githooks - Fatal编程技术网

git post接收钩子,用于抓取提交消息并发回URL

git post接收钩子,用于抓取提交消息并发回URL,git,githooks,Git,Githooks,我们正在使用一个票务系统,我希望在开发人员将其更改推送到服务器时自动更新该系统。为了更新它,我只需要提供一个特定的URL,并将提交消息作为GET变量。然后被调用的页面将记录此更改。我知道我的方法是使用,但我对Bash和Perl都不熟悉,所以这很有挑战性 我想做到这一点: 开发者推送到服务器 post-receivehook运行并检查哪些不同的提交是新的(因为一次推送中可能有多个提交) 它循环遍历它们,对于每个提交,它将打开一个包含提交消息(curl)的URLhttp://server.com/

我们正在使用一个票务系统,我希望在开发人员将其更改推送到服务器时自动更新该系统。为了更新它,我只需要提供一个特定的URL,并将提交消息作为GET变量。然后被调用的页面将记录此更改。我知道我的方法是使用,但我对Bash和Perl都不熟悉,所以这很有挑战性

我想做到这一点:

  • 开发者推送到服务器
  • post-receive
    hook运行并检查哪些不同的提交是新的(因为一次推送中可能有多个提交)
  • 它循环遍历它们,对于每个提交,它将打开一个包含提交消息(
    curl)的URLhttp://server.com/logthis.asp?msg=Here_goes_the_commit_message
    ,类似的内容)

就这样。虽然我已经证实了与这种想法相关的东西,但没有一个能做到这一点。这怎么可能呢

主要的PITA是隔离新修订的正确列表,我从/usr/share/doc/git/contrib/hooks/post-receive-email(show\u-new\u-revisions)中借用了新修订


仔细的如果在同一推送中创建一个修订并将其合并到另一个分支中,则上述代码将跳过该修订。
while read oval nval ref ; do
    if expr "$ref" : "^refs/heads/"; then
        if expr "$oval" : '0*$' >/dev/null
        then
            revspec=$nval
        else
            revspec=$oval..$nval
        fi
        other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
            grep -F -v $ref)

        # You may want to collect the revisions to sort out
        # duplicates before the transmission to the bugtracker,
        # but not sorting is easier ;-)
        for revision in `git rev-parse --not $other_branches | git rev-list --stdin $revspec`; do
                    # I don't know if you need to url-escape the content
                    # Also you may want to transmit the data in a POST request,
            wget "http://server.com/logthis.asp?msg=$(git log $revision~1..$revision)"
        done
    fi
done