I have decided to deploy my Jekyll blog on my own server. Of course, every time I push the blog to the server, I want it to
- Build the blog using
jekyll
- Push it to another branch, so I can version-control the output.
- Deploy it to my web server.
I decided to use Python, as it gave me a little more protection against a dodgy environment when compared to Bash and I could readily use Regular Expressions.
You can watch my progress on my Github account.
The Hook
Git kindly provides a number of githooks
. The one we wish to use today is the
post-receive
hook. The following quote is from the githooks
man page.
This hook is invoked by git-receive-pack on the remote repository, which happens when a git push is done on a local repository. Just before starting to update refs on the remote repository, the pre-receive hook is invoked. Its exit status determines the success or failure of the update.
This hook executes once for the receive operation. It takes no arguments, but for each ref to be updated it receives on standard input a line of the format:
SP SP LF where is the old object name stored in the ref, is the new object name to be stored in the ref and is the full name of the ref. When creating a new ref, is 40 0. If the hook exits with non-zero status, none of the refs will be updated. If the hook exits with zero, updating of individual refs can still be prevented by the update hook.
Both standard output and standard error output are forwarded to git send-pack on the other end, so you can simply echo messages for the user.
As you can see, git
provides us with some helpful data on the stdin
.