Created
November 26, 2017 00:17
-
-
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
This file contains hidden or 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
[core] | |
hooksPath = ~/.config/git/hooks |
This file contains hidden or 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
<<<<<<< HEAD | |
hoge | |
======= | |
fuga | |
>>>>>>> another-branch |
This file contains hidden or 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 | |
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 |
This file contains hidden or 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
$ 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