Skip to content

Instantly share code, notes, and snippets.

@unRob
Last active September 7, 2016 05:23
Show Gist options
  • Save unRob/f74e6f0bd224d30033370854b515ddef to your computer and use it in GitHub Desktop.
Save unRob/f74e6f0bd224d30033370854b515ddef to your computer and use it in GitHub Desktop.
pre-commit do something on patterns
#!/bin/bash
# mkdir -p bin/hooks
# curl -v -L https://gist.github.com/unRob/f74e6f0bd224d30033370854b515ddef/raw/install-hooks.sh > bin/install-hooks
# chmod +x bin/install-hooks
# curl -v -L https://gist.github.com/unRob/f74e6f0bd224d30033370854b515ddef/raw/pre-commit.sh > bin/hooks/pre-commit
# chmod +x bin/hooks
# bin/install-hooks
# echo "Remember to delete unused hooks (or to suggest a good way to do so automatically)"
# exit on error
set -e
APP_ROOT=`git rev-parse --show-toplevel`
HOOKS=${APP_ROOT}/bin/hooks/*
for file in $HOOKS; do
ln -sfv "$file" "$APP_ROOT/.git/hooks/"
done
#!/bin/bash
# curl -v -L https://gist.github.com/unRob/f74e6f0bd224d30033370854b515ddef/raw/pre-commit.sh > .git/hooks/pre-commit
# echo "Let's look at what we've just downloaded off a stranger on the internets!" && cat .git/hooks/pre-commit
# chmod +x .git/hooks/pre-commit
# exit on error
set -e
staged() {
[ `git diff --name-only --cached | grep -E "$1"` ]
}
# Use regular expressions to query staged files
if ( staged "(models|api)/.+\.js$" ) || ( staged ".ejs$" ) || ( staged "config/spec.yaml" )
then
echo "Generating documentation..."
npm run docs
git add docs/
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment