Only check merge conflicts on conflict commits

This commit is contained in:
Anthony Sottile 2015-03-20 16:15:09 -07:00
parent 34444ba2c7
commit 635fa7dd9d
3 changed files with 73 additions and 17 deletions

View file

@ -1,6 +1,7 @@
from __future__ import print_function
import argparse
import os.path
import sys
CONFLICT_PATTERNS = [
@ -11,11 +12,21 @@ CONFLICT_PATTERNS = [
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: