Created
April 29, 2018 12:41
-
-
Save Tonius/7c4050f066bc2267509ce4e037f0dd29 to your computer and use it in GitHub Desktop.
Script for fetching and checking out a bunch of Git repositories at a time (used for CoFH/cofh.github.io)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from subprocess import Popen, PIPE | |
from threading import Thread | |
REPOS = [ | |
'RedstoneFlux', | |
'CoFHCore', | |
'CoFHWorld', | |
'ThermalFoundation', | |
'ThermalExpansion', | |
'ThermalDynamics', | |
'ThermalCultivation', | |
'ThermalInnovation', | |
'RedstoneArsenal' | |
] | |
print('\nFetching repositories...') | |
def fetch(repo): | |
Popen(['git', 'fetch'], cwd=os.path.join(os.getcwd(), repo)).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(os.getcwd(), repo) | |
current_commit_id = Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=PIPE, cwd=cwd).communicate()[0].strip() | |
while True: | |
commit_id = raw_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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment