forked from CoFH/cofh.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.py
executable file
·63 lines (47 loc) · 1.56 KB
/
checkout.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
""" Clones, fetches and checks out the repositories of all the CoFH mods in the
parent directory.
"""
import os
import sys
from subprocess import Popen, PIPE
from threading import Thread
REPOS = [
'RedstoneFlux',
'CoFHCore',
'CoFHWorld',
'ThermalFoundation',
'ThermalExpansion',
'ThermalDynamics',
'ThermalCultivation',
'ThermalInnovation',
'RedstoneArsenal',
'VanillaTools',
'VanillaSatchels'
]
print('\nFetching repositories...')
parent_path = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
def fetch(repo):
repo_path = os.path.join(parent_path, repo)
if not os.path.isdir(repo_path):
Popen(['git', 'clone', 'git@github.com:CoFH/{}.git'.format(repo)], cwd=parent_path).wait()
else:
Popen(['git', 'fetch'], cwd=repo_path).wait()
sys.stdout.write('- {}\n'.format(repo))
threads = [Thread(target=fetch, args=(repo,)) for repo in REPOS]
for t in threads:
t.start()
for t in threads:
t.join()
for repo in REPOS:
print('')
cwd = os.path.join(parent_path, repo)
current_commit_id = Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=PIPE, cwd=cwd).communicate()[0].strip().decode('utf-8')
while True:
commit_id = input('Commit ID for {} ({}): '.format(repo, current_commit_id))
if commit_id == '':
break
print('Checking out {}...'.format(commit_id))
git_checkout = Popen(['git', '-c', 'advice.detachedHead=false', 'checkout', commit_id], cwd=cwd)
git_checkout.wait()
if git_checkout.returncode == 0:
break