-
Notifications
You must be signed in to change notification settings - Fork 1
/
git_interface.py
44 lines (37 loc) · 1.54 KB
/
git_interface.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
39
40
41
42
43
44
import os
# operates on master branch
# TODO: error handling, merge conflict handling
class Repository:
def __init__(self, path, remote_1, remote_2):
self.__path = path
self.__remote_1 = remote_1
self.__remote_2 = remote_2
def pull(self, remote_index):
remote = ""
if remote_index == 1:
remote = self.__remote_1
elif remote_index == 2:
remote = self.__remote_2
command = """cd {} \n git checkout master \n git pull {} master \n""".format(self.__path,
remote)
os.system(command)
def push(self, remote_index):
remote = ""
if remote_index == 1:
remote = self.__remote_1
elif remote_index == 2:
remote = self.__remote_2
command = """cd {} \n git checkout master \n git push {} master \n""".format(self.__path, remote)
os.system(command)
def commit(self, message):
command = """cd {} \n git stage --all \n git commit -m "{}" \n""".format(self.__path, message)
os.system(command)
def apply(self, patch_path, revert=False):
if not revert:
command = """cd {} \n git apply {} \n""".format(self.__path, patch_path)
else:
command = """cd {} \n git apply -R {} \n""".format(self.__path, patch_path)
os.system(command)
def stash(self):
command = """cd {} \n git stash --all \n""".format(self.__path)
os.system(command)