Skip to content

Instantly share code, notes, and snippets.

@Bartuz
Forked from proapi/gitconfig
Last active August 29, 2015 14:06
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 Bartuz/175a8aaf7c78833ae1df to your computer and use it in GitHub Desktop.
Save Bartuz/175a8aaf7c78833ae1df to your computer and use it in GitHub Desktop.
1. Enable git templates:
git config --global init.templatedir '~/.git-templates'
This tells git to copy everything in ~/.git-templates to your per-project .git/ directory when you run git init
2. Create a directory to hold the global hooks:
mkdir -p ~/.git-templates/hooks
3. Write your hooks in ~/.git-templates/hooks
4. Make sure the hook is executable.
chmod a+x ~/.git-templates/hooks/pre-push
5. Re-initialize git in each existing repo you'd like to use this in:
git init
NOTE if you already have a hook defined in your local git repo, this will not overwrite it.
1. Copy your script to /path/to/your/project/.git/hooks
2. Remember to keep the name of hook consistent(eg. pre-commit, pre-push, post-commit) - no file extension
3. Remember to chmod a+x on a hook to be executable
#!/bin/bash
#
# Check for debugging statements before pushing your code.
#
# List of function names to search for in regex format
FUNCTIONS="binding\.pry|console\.log|dupa"
# If any functions are found as executable, prevent the push.
EXITONFAIL=true
echo "Running the check against debugger functions in your code..."
CMD="grep -Enr --exclude=\*.{png,jpg,jpeg,gif} --exclude-dir={.git,tmp,log,public} \"$FUNCTIONS\""
echo "$CMD"
if [[ -n "$CMD" ]]; then
echo "Debugging functions were found in your code!"
eval "$CMD"
if [[ $EXITONFAIL == true ]]; then
echo "Changes were not pushed."
exit 1;
else
echo "You may want to clean these up. Changes were pushed anyway."
exit 0;
fi
else
echo "No debugging functions were found. Nice job, Ace!";
exit 0;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment