Instantly share code, notes, and snippets.

Embed
What would you like to do?
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