Skip to content

Instantly share code, notes, and snippets.

@hanks
Created October 28, 2014 07:19
Show Gist options
  • Save hanks/8c7a790530aca11ed333 to your computer and use it in GitHub Desktop.
Save hanks/8c7a790530aca11ed333 to your computer and use it in GitHub Desktop.
git pre commit hook to check unsolved conflicts
#!/bin/sh
echo
count=0
echo "Scanning...Conflict Files List:"
for f in `git diff HEAD --name-only --diff-filter=M`; do
if [ -f $f ]; then
if grep -Fxq "<<<<<<<" $f; then
echo " $(tput setaf 1)$f$(tput sgr0)"
((count += 1))
fi
fi
done
echo
echo "Summary:"
if [ $count != 0 ]; then
echo " $(tput setaf 1)$count$(tput sgr0) files conflict, need to solve them first!!"
exit 1;
else
echo " $(tput setaf 2)No Conflicts, Start to commit!$(tput sgr0)"
echo
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment