想要git post receive hook来进行新的提交和推送

时间:2011-05-09 16:09:37

标签: git push git-post-receive

我希望我的post-receive hook负责更新repo中的版本文件 在某些条件下。所以,假设我的存储库中有一个文件version.txt, 我希望post receive hook能够更新version.txt中的版本字符串。

这意味着再次推动回购。这可能吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

我宁愿不尝试进行任何进一步的提交/推送,但在结帐/更新时按顺序使用filter driver,以便能够为该version.txt文件生成正确的内容(即正确的版本字符串)

enter image description here

smudge脚本,如果能够识别version.txt文件的内容(即won't have the name/path of said file as parameter),则会用正确的信息替换该文件的模板部分。

答案 1 :(得分:2)

您可以在服务器上拥有repo的工作目录。在post-receive,git pull on工作目录,根据需要更新version.txt并提交并推送。这将再次触发后接收,因此请小心如何进行条件更新,否则它将进入一个周期。

#!/bin/sh
unset GIT_DIR
cd /path/to/repo.wd
git pull
echo "new content" > version.txt
git add version.txt
git commit -m "updating version.txt"
git push origin master