Skip to content

Instantly share code, notes, and snippets.

@ryanjm
Forked from c00kiemon5ter/post-commit
Created May 7, 2012 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanjm/2628759 to your computer and use it in GitHub Desktop.
Save ryanjm/2628759 to your computer and use it in GitHub Desktop.
a hook to deploy static generated sites
#!/usr/bin/env bash
# executables prefix
_prefix="/usr/local/bin"
# git executable
_git="$_prefix/git"
# site generation executable
_generate="$_prefix/jekyll"
# options for the generator
_opts=(--no-safe --no-server --no-auto)
# branch from which to generate site
_origbranch="temp"
# branch holding the generated site
_destbranch="master"
# directory holding the generated site -- should be outside this repo
_site="$("/usr/bin/mktemp" -d /tmp/_site.XXXXXXXXX)"
# the current branch
_currbranch="$($_git branch | /usr/bin/grep "^*" | /usr/bin/cut -d' ' -f2)"
if [[ $_currbranch == $_origbranch ]]; then # we should generate the site
# go to root dir of the repo
cd "$("$_git" rev-parse --show-toplevel)"
# generate the site
"$_generate" ${_opts[@]} . "$_site"
# switch to branch the site will be stored
"$_git" checkout "$_destbranch"
# overwrite existing files
builtin shopt -s dotglob
/bin/cp -rf "$_site"/* .
builtin shopt -u dotglob
# add any new files
"$_git" add .
# commit all changes with a default message
"$_git" commit -a -m "updated site @ $(date +"%F %T")"
# cleanup
/bin/rm -rfv "$_site"
# return
"$_git" checkout "$_origbranch"
fi
@ryanjm
Copy link
Author

ryanjm commented May 7, 2012

chmod u+x .git/hooks/post-commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment