问题描述
当仅将新标签推入存储库时,我想在GIT的post-receive
钩子中执行一些操作.如何做到这一点?
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?
谢谢
解决方案(JanKrüger的回答)
新标签的$oldrev
等于零.删除的标记的$newrev
等于零.对于这两个$ref
,值均以refs/tags/
开头.
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
推荐答案
post-receive
挂钩接收stdin上有关在该操作中更新的所有ref(分支,标签等)的信息.每行具有以下格式,摘自 githooks
联机帮助页:
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
您只需要阅读stdin并检查行是否与此格式匹配.基本上,第一个单词"全为零,第三个单词以refs/tags/
开头.
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/
.
这篇关于仅在添加新标签后才在接收后触发某些内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!