Only check merge conflicts on conflict commits
diff --git a/pre_commit_hooks/check_merge_conflict.py b/pre_commit_hooks/check_merge_conflict.py
index ac405b2..5e274a3 100644
--- a/pre_commit_hooks/check_merge_conflict.py
+++ b/pre_commit_hooks/check_merge_conflict.py
@@ -1,6 +1,7 @@
from __future__ import print_function
import argparse
+import os.path
import sys
CONFLICT_PATTERNS = [
@@ -11,11 +12,21 @@
WARNING_MSG = 'Merge conflict string "{0}" found in {1}:{2}'
+def is_in_merge_conflict():
+ return (
+ os.path.exists(os.path.join('.git', 'MERGE_MSG')) and
+ os.path.exists(os.path.join('.git', 'MERGE_HEAD'))
+ )
+
+
def detect_merge_conflict(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*')
args = parser.parse_args(argv)
+ if not is_in_merge_conflict():
+ return 0
+
retcode = 0
for filename in args.filenames:
with open(filename) as inputfile: