Simplify your configurable hooks
Sometimes we want to have option to enable/disable some git hooks. We can create if
for each, but we should be DRY even in hooks. So my solution is:
#!/bin/sh
ROOT=$(git rev-parse --show-toplevel)
function hook {
value=$(git config hooks.$1)
if [ "$value" = "true" ]; then
shift 1
eval $* || exit 1
fi
}
hook rubocop rubocop -R
hook tests $ROOT/bin/rake test:all # check https://github.com/rails/rails/pull/12958
IMHO it is simply enough but powerful as well. Enjoy yourselves.
Written by Łukasz Niemier
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#