Trigger something in post-receive only when new tag is added

本秂侑毒 提交于 2020-08-11 01:11:07

问题


I want to do some action in GIT's post-receive hook when only new tag is pushed to the repository. How to accomplish this?

Thanks


SOLUTION (answer by Jan Krüger)

New tag has $oldrev equalled zeroes. Removed tag has $newrev equalled zeroes. For both $ref value starts with refs/tags/.

#!/bin/sh
#

read oldrev newrev ref

if [[ "0000000000000000000000000000000000000000" == $oldrev ]] && [[ $ref == refs\/tags\/* ]];
then
    echo "New tag added"
fi

回答1:


The post-receive hook receives information on stdin about all the refs (branches, tags, ...) that were updated in that operation. Each line has the following format, taken from the githooks manpage:

<old-value> SP <new-value> SP <ref-name> LF

So this would be an example of a new tag being created:

0000000000000000000000000000000000000000 0123456789abcdef0123456789abcdef01234567 refs/tags/mytag

You simply need to read from stdin and check whether a line matches this format. Basically the first "word" is all zeroes and the third word starts with refs/tags/.



来源:https://stackoverflow.com/questions/55278195/trigger-something-in-post-receive-only-when-new-tag-is-added

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!