Created
August 23, 2023 11:59
-
-
Save andyhasit/b5d40a07230940badd76c810eda23bee to your computer and use it in GitHub Desktop.
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/bash | |
# pre-commit script to prevent merge markers from being committed. | |
# Adapted from here: | |
# https://jondowdle.com/2015/02/block-merge-conflicts-in-commits/ | |
# | |
# This simply searches the files that you are about to commit for seven <, >, or | |
# = at the beginning of a line, followed by a space or the end of the line. | |
changed=$(git diff --cached --name-only --diff-filter=ACM) | |
if [[ -z "$changed" ]]; then | |
exit 0 | |
fi | |
echo $changed | xargs egrep '^[><=]{7}( |$)' -H -I --line-number | |
# If the egrep command has any hits - echo a warning and exit with non-zero status. | |
if [ $? == 0 ]; then | |
echo "WARNING: You have merge markers in the above files. Fix them before committing." | |
echo " If these markers are intentional, you can force the commit with the --no-verify argument." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment