Skip to content

Instantly share code, notes, and snippets.

@foreverbell
Created August 17, 2014 05:27
Show Gist options
  • Select an option

  • Save foreverbell/2506f0eb1645226cc2c8 to your computer and use it in GitHub Desktop.

Select an option

Save foreverbell/2506f0eb1645226cc2c8 to your computer and use it in GitHub Desktop.
Recover git submodules from .gitmodules
#!/usr/bin/env python
# encoding: utf-8
import ConfigParser
import sys
import StringIO
data = StringIO.StringIO('\n'.join(line.strip() for line in open(".gitmodules", "r")))
config = ConfigParser.SafeConfigParser()
config.readfp(data)
sections = config.sections()
with open("init-modules.sh", "w") as f :
f.write("#!/bin/sh\n")
for s in sections :
path = config.get(s, "path")
url = config.get(s, "url")
f.write("git submodule add %s %s\n" % (url, path))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment