# resolve.py FILE CHOICES (CHOICES: string of o/t per conflict hunk, in order) import re, sys from pathlib import Path path, choices = sys.argv[1], sys.argv[2] text = Path(path).read_text() pat = re.compile(r"^<<<<<<< [^\n]*\n(.*?)^=======\n(.*?)^>>>>>>> [^\n]*\n", re.S | re.M) hunks = pat.findall(text) assert len(hunks) == len(choices), (len(hunks), choices) it = iter(choices) Path(path).write_text(pat.sub(lambda m: m.group(1) if next(it) == "o" else m.group(2), text))