Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want git post receive hook to make new commit and push

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!

like image 596
Jacko Avatar asked May 09 '11 16:05

Jacko


1 Answers

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
like image 113
manojlds Avatar answered Oct 03 '22 10:10

manojlds