forked from Jagadeeshftw/grainlify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve_head_safe.py
More file actions
39 lines (34 loc) · 923 Bytes
/
resolve_head_safe.py
File metadata and controls
39 lines (34 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import re
filepath = "contracts/program-escrow/src/lib.rs"
with open(filepath, 'r') as f:
content = f.read()
# Replace <<<<<<< HEAD ... ======= ... >>>>>>> [branch]
# Note that we use a simpler approach: process line by line
lines = content.split('\n')
new_lines = []
in_head = False
in_remote = False
for line in lines:
if line.startswith('<<<<<<< HEAD'):
in_head = True
continue
elif line.startswith('======='):
if in_head:
in_head = False
in_remote = True
else:
new_lines.append(line)
continue
elif line.startswith('>>>>>>>'):
if in_remote:
in_remote = False
else:
new_lines.append(line)
continue
if in_remote:
# discard remote changes
pass
else:
new_lines.append(line)
with open(filepath, 'w') as f:
f.write('\n'.join(new_lines))