Replace conflict markers with the chosen side.
(content: str, strategy: str)
| 85 | |
| 86 | |
| 87 | def _resolve_content(content: str, strategy: str) -> str: |
| 88 | """Replace conflict markers with the chosen side.""" |
| 89 | lines = content.splitlines(keepends=True) |
| 90 | result: list[str] = [] |
| 91 | state = "normal" # normal | ours | theirs |
| 92 | |
| 93 | for line in lines: |
| 94 | if line.startswith("<<<<<<<"): |
| 95 | state = "ours" |
| 96 | elif line.startswith("=======") and state == "ours": |
| 97 | state = "theirs" |
| 98 | elif line.startswith(">>>>>>>") and state == "theirs": |
| 99 | state = "normal" |
| 100 | else: |
| 101 | if state == "normal": |
| 102 | result.append(line) |
| 103 | elif state == "ours" and strategy == "ours": |
| 104 | result.append(line) |
| 105 | elif state == "theirs" and strategy == "theirs": |
| 106 | result.append(line) |
| 107 | return "".join(result) |