Skip to content

Commit

Permalink
Add fallback to standard cloning when github archive returns error 500
Browse files Browse the repository at this point in the history
  • Loading branch information
yvaucher committed Mar 9, 2017
1 parent 81e463e commit 9479f73
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions travis/git_submodule_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
os.system('git submodule init')

for sub in Repo('.').submodules:
if sub.path not in private_repos:
print "Getting submodule %s" % sub.path
use_archive = sub.path not in private_repos
if use_archive:
url = sub.url
if url.startswith('[email protected]:'):
url = url.replace('[email protected]:', 'https://github.com/')
Expand All @@ -31,11 +33,24 @@
url = url[:-4]
archive_url = "%s/archive/%s.zip" % (url, sub.hexsha)
urlretrieve(archive_url, ZIP_PATH)
with zipfile.ZipFile(ZIP_PATH) as zf:
zf.extractall(DL_DIR)
os.remove(ZIP_PATH)
os.removedirs(sub.path)
submodule_dir = os.listdir(DL_DIR)[0]
shutil.move(os.path.join(DL_DIR, submodule_dir), sub.path)
else:
try:
with zipfile.ZipFile(ZIP_PATH) as zf:
zf.extractall(DL_DIR)
except zf.BadZipfile:
# fall back to standard download
use_archive = False
with open(ZIP_PATH) as f:
print ("Getting archive failed with error %s. Falling back to "
"git clone." % f.read())
os.remove(ZIP_PATH)
except Exception as e:
use_archive = False
print ("Getting archive failed with error %s. Falling back to "
"git clone." % e.message)
else:
os.remove(ZIP_PATH)
os.removedirs(sub.path)
submodule_dir = os.listdir(DL_DIR)[0]
shutil.move(os.path.join(DL_DIR, submodule_dir), sub.path)
if not use_archive:
os.system('git submodule update %s' % sub.path)

0 comments on commit 9479f73

Please sign in to comment.