-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit.py
38 lines (31 loc) · 941 Bytes
/
commit.py
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
import os
import subprocess
PATH = "/home/paki/work/mipsia_master/art"
EXAMPLE = "git fetch https://android.googlesource.com/platform/art refs/changes/65/171665/3 && git cherry-pick FETCH_HEAD"
ABORT_COMMAND = 'git cherry-pick --abort'
UNDO_COMMAND = 'git reset --hard aosp/master'
def work():
if try_cherry_pick(EXAMPLE):
print('OKAY')
else:
print('NOT OKAY')
def try_cherry_pick(command):
""" Try a cherry-pick for a commit. Use the specified command passed from
the fetcher. If the cherry-pick fails, abort the cherry-pick.
"""
result = subprocess.call(command, shell=True)
if result != 0:
subprocess.call(ABORT_COMMAND, shell=True)
return False
else:
return True
def main():
# TODO: use contextmanager.
old_path = os.getcwd()
try:
os.chdir(PATH)
work()
finally:
os.chdir(old_path)
if __name__ == '__main__':
main()