Skip to content

Instantly share code, notes, and snippets.

@infotexture
Last active January 4, 2016 14:39
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 infotexture/8635931 to your computer and use it in GitHub Desktop.
Save infotexture/8635931 to your computer and use it in GitHub Desktop.
Sample Git `pre-commit` hook to build DITA output before committting and reject the changes if build fails
#!/bin/sh
#
# Get the absolute path of the `.git/hooks` directory
export GIT_HOOKS=`cd "\`dirname "\\\`readlink "$0" || echo $0\\\`"\`" && pwd`
# Set the absolute path of the build directory
export BUILD_FILES="$GIT_HOOKS/../../build-files/"
# Set the absolute path of the DITA home directory
export DITA_HOME="$BUILD_FILES/../bin/dita-ot/"
# Set the absolute path of the DITA home directory again (weird, but necessary)
export DITA_DIR="$BUILD_FILES/../bin/dita-ot/"
# Execute the build script in the shell that is provided by the DITA start script
echo "$BUILD_FILES/build_html.sh" | "$DITA_HOME/startcmd.sh"
# Display OS X system notification via <https://github.com/alloy/terminal-notifier>
echo 'HTML build succeeded. Committing…' | /usr/local/bin/terminal-notifier -sound default
# Exit with status of last command
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment