Skip to content

Instantly share code, notes, and snippets.

@simon-weber
Forked from c00kiemon5ter/post-commit
Created June 5, 2013 19:58
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 simon-weber/5716811 to your computer and use it in GitHub Desktop.
Save simon-weber/5716811 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# executables prefix
_prefix="/usr/bin"
# git executable
_git="$_prefix/git"
# branch from which to generate site
_origbranch="source"
# branch holding the generated site
_destbranch="master"
# directory holding the generated site -- should be outside this repo
_site="$("/bin/mktemp" -d /tmp/_site.XXXXXXXXX)"
# the current branch
_currbranch="$(/bin/grep "^*" < <("$_git" branch) | /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
jekyll build --destination "$_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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment