Skip to content

Instantly share code, notes, and snippets.

@atton
Created November 26, 2017 00:17
Show Gist options
  • Save atton/8b49e8f2f6a961957b04af31d8afd589 to your computer and use it in GitHub Desktop.
Save atton/8b49e8f2f6a961957b04af31d8afd589 to your computer and use it in GitHub Desktop.
Show warning message if you have merge lines using git-hooks(pre-commit). Details: https://attonblog.blogspot.jp/2017/11/git-pre-commit-hook.html
[core]
hooksPath = ~/.config/git/hooks
<<<<<<< HEAD
hoge
=======
fuga
>>>>>>> another-branch
#!/bin/sh
FORBIDDEN='(<<<<<<<|=======|>>>>>>>)'
GREP_COLOR='4;5;37;41'
cd $PWD
git diff --cached --name-only | xargs -L1 grep --color --with-filename -n -E $FORBIDDEN
if [[ $? -eq 0 ]]; then
echo "Merge lines was detected.\nPlease fix files, or run 'git commit --no-verify' to skip this check."
exit 1
fi
$ git commit -m 'perfect merge'
e:1:<<<<<<< HEAD
e:3:=======
e:5:>>>>>>> o
Merge lines was detected.
Please fix files, or run 'git commit --no-verify' to skip this check.
$ git status
On branch master
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: hoge.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment