Git hook to update various web folders based on branch pushed to remote server

落爺英雄遲暮 提交于 2019-12-06 04:47:57
VonC

Should you push to a non-bare repo (which isn't a recommended technique, but can work with this post-update hook), you can complete that hook, knowing that:

git symbolic-ref HEAD
# or
git rev-parse HEAD

Give you the name of the current branch, while $ref represents the branch being pushed.
You can then update three different working tree, each one already set on the right branch.

Perhaps I'm missing something, but if this is in a post-update hook then you get the names of the refs that are being updated as parameters to the hook. e.g. if my push updates master and experimental in a repository, then post-update is invoked with:

 post-update refs/heads/master refs/heads/experimental

... and you can access them with $1 as $2 usual in your hook script.

Incidentally, the githooks documentation points out that you might want to consider using the post-receive hook instead, which instead gets information on standard input - however, it also gives you the old and new values of the ref as well as the ref name, which might be useful.

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