X-Git-Url: https://disinclined.org/git/?a=blobdiff_plain;f=_posts%2F2011-02-14-git-post-receive-hook-for-live-branch.html;fp=_posts%2F2011-02-14-git-post-receive-hook-for-live-branch.html;h=beb63abc0c3f0ec3d6489caf6edcfe3ab606535b;hb=4fdb6152f6035dec5d3b46b23cb7f7f15072ef4b;hp=0000000000000000000000000000000000000000;hpb=7d05bc31df7579040af812d878a8553309a94799;p=disinclined.org.git diff --git a/_posts/2011-02-14-git-post-receive-hook-for-live-branch.html b/_posts/2011-02-14-git-post-receive-hook-for-live-branch.html new file mode 100644 index 0000000..beb63ab --- /dev/null +++ b/_posts/2011-02-14-git-post-receive-hook-for-live-branch.html @@ -0,0 +1,18 @@ +--- +layout: note +--- + +git post-receive hook for live branch +2011/02/14 01:30AM +

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 there are no arguments, the information is available on stdin.

+
+if ! [ -t 0 ]; then
+  read -a ref
+fi
+IFS='/' read -ra REF <<< "${ref[2]}"
+branch="${REF[2]}"
+if [ "live" == "$branch" ]; then 
+  git --work-tree=/var/www/dylanstestserver.com/ --git-dir=.. checkout -f
+  echo 'Changes pushed live.'
+fi
+