Created
November 28, 2022 14:05
-
-
Save jonas-johansson/58899378b894ae69bff247385e1591be to your computer and use it in GitHub Desktop.
Git pre-commit hook that checks if there are any conflict markers present in any file.
This file contains 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/sh | |
# Check to see if there are any conflict markers still present in a file. If so, exit 1 to prevent commit. | |
CONFLICT_MARKERS='<<<<<<<|=======|>>>>>>>' | |
CHECK=$(git diff --staged | grep "^+" | grep -Ei "$CONFLICT_MARKERS" -c) | |
if [ "$CHECK" -gt 0 ] | |
then | |
echo "ERROR: Conflict markers are still present in a file. Talk to a developer. Detected by a custom .git/hooks/pre-commit file." | |
git diff --name-only -G"$CONFLICT_MARKERS" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment