-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit_sync
executable file
·53 lines (47 loc) · 1.55 KB
/
git_sync
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
45
46
47
48
49
50
51
52
#!/usr/bin/env python
import os
import sys
try:
from colorama import Fore, Back, Style
except:
class Fore:
BLUE = ""
RED = ""
RESET = ""
def system(cmd):
print(Fore.BLUE + cmd + Fore.RESET)
ret = os.system(cmd)
if ((ret >> 8) & 0xff):
print(Fore.RED + "Command {0} failed".format(cmd) + Fore.RESET)
sys.exit(1)
system("git pull --ff-only")
#currently have two levels deep of submodules, if you add more, add another line below
system("git submodule update --init --recursive")
system("git submodule update --init --recursive")
system("git submodule status --recursive")
def sync_submodules():
modules = open('.gitmodules')
lines = modules.readlines()
modules.close()
i = 0
while i < len(lines):
if "[submodule " in lines[i]:
path = lines[i+1].split("=")[1].strip()
url = lines[i+2].split("=")[1].strip()
branch = "master"
i += 2
if i < len(lines)-1:
if "branch = " in lines[i+1]:
i += 1
branch = lines[i].split("=")[1].strip()
print(Fore.BLUE + "Syncing {0} to {1}".format(path, branch) + Fore.RESET)
current_path = os.getcwd()
os.chdir(path)
system("git fetch")
system("git checkout {0}".format(branch))
system("git merge origin/{0} --ff-only".format(branch))
if os.path.exists(".gitmodules"):
sync_submodules()
os.chdir(current_path)
i += 1
sync_submodules()