Signal 13 Problems with Git Hooks
Ran into a gotcha in Git today when trying to write a post push hook. We want our designer to have a fast turn around time with clients so we're writing some hooks to merge all of the 'theme' branches he works with to get merged into a special preview branch which is then deployed to the preview site. And all this should happen after he does a 'git push.' Seems like a 'post-receive' hook is just what we want.
Except that every time we tried to create one we got these errors on a push:
error: git-shell died of signal 13
fatal: The remote end hung up unexpectedly
error: error in sideband demultiplexer
If the 'post-receive' file even existed in git_dir/hooks/ on the git repo box, we got this error. We checked permissions, gitolite docs, git docs, google, etc and no help. We finally realized that Git was piping in some information to our 'post-receive' file and since we were not consuming it, that was causing the explosion.
So, I present to you, a stub of 'post-receive' file written in Ruby:
#!/usr/bin/env ruby
STDIN.readlines.each do |line|
rev_old, rev_new, ref = line.split(" ")
# You will get in here as many times as branches were pushed
end
rev_old is the old commit hash, rev_new is the new commit hash, and ref will be something like: "refs/heads/test_branch" Useful information.
Git often passes things into it's hooks, check the git book docs to find out what.
Comments