开发者

Want git post receive hook to make new commit and push

开发者 https://www.devze.com 2023-03-04 05:04 出处:网络
I would like my post-receive hook to be responsible for updating a version file in the repo itself, under certain conditions. So, suppose I have a file version.txt in my repository,

I would like my post-receive hook to be responsible for updating a version file in the repo itself, under certain conditions. So, suppose I have a file version.txt in my repository, I would like the post receive hook to update a version string inside version.txt.

That would mean another push 开发者_高级运维to the repo. Is this possible?

Thanks!


You can have a working directory of your repo on your server. In the post-receive, git pull on the working directory, update the version.txt as needed and commit and push. This will trigger the post-receive one more time, so be careful about how you are doing your conditional update, otherwise it will go into a cycle.

#!/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


I would rather not try to make any further commit/push, but use a filter driver in order, on checkout/update to be able to generate the right content for that version.txt file (i.e. with the right version string inside)

Want git post receive hook to make new commit and push

The smudge script, if it is able to recognized the content of a version.txt file (i.e. it won't have the name/path of said file as parameter), would replace a template section of that file with the right information.

0

精彩评论

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