update minimax submodule
[disinclined.org.git] / _posts / 2011-02-14-git-post-receive-hook-for-live-branch.html
1 ---
2 layout: note
3 ---
4
5 git post-receive hook for live branch
6 2011/02/14 01:30AM
7 <p> It's easiest to use a git branch to manage the rollout of updates to my website. I wanted to add a message to the `git push` output when the commit is pushed live. The documentation notes that the post-recieve hook has access to the the ref-name. This script is placed in dylanstestserver.git/hooks/post-receive to do this. It took me some time to realize <i>there are no arguments</i>, the information is available on stdin. </p>
8 <pre class="brush: bash">
9 if ! [ -t 0 ]; then
10 read -a ref
11 fi
12 IFS='/' read -ra REF <<< "${ref[2]}"
13 branch="${REF[2]}"
14 if [ "live" == "$branch" ]; then
15 git --work-tree=/var/www/dylanstestserver.com/ --git-dir=.. checkout -f
16 echo 'Changes pushed live.'
17 fi
18 </pre>