Skip to content

Instantly share code, notes, and snippets.

@andyhasit
Created August 23, 2023 11:59
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 andyhasit/b5d40a07230940badd76c810eda23bee to your computer and use it in GitHub Desktop.
Save andyhasit/b5d40a07230940badd76c810eda23bee to your computer and use it in GitHub Desktop.
#!/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