Last active
March 28, 2018 14:45
-
-
Save oojewale/a35f74a20e5173d1dd3de5dc57c1cc96 to your computer and use it in GitHub Desktop.
Prevent commit if merge conflict markers or debuggers are in your changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This pre-commit hook checks that there are no merge conflict markers | |
# or debuggers in your code before committing. | |
# | |
# To use this script copy it to .git/hooks/pre-commit and make it executable. | |
# Work out what to diff against, HEAD will work for any established repository. | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# hash for an empty tree object for all git repos | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
diffstr=`git diff --cached $against | grep -E '<<<<<<< HEAD|>>>>>>>|=======|debugger|binding.pry'` | |
if [[ -n "$diffstr" ]] ; then | |
echo "|-------------------------------------------------------------|" | |
echo "| You have left some merge conflict markers or |" | |
echo "| debuggers in your changes. |" | |
echo "| E.g '<<<<<<< HEAD' OR '>>>>>>>' OR '=======' OR |" | |
echo "| 'debugger' OR 'binding.pry' |" | |
echo "| You can't commit until this has been resolved. |" | |
echo "| Resolve the conflict(s), remove the marker(s). |" | |
echo "| Add the files to git and commit again. |" | |
echo "|-------------------------------------------------------------|" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment