Skip to content

Instantly share code, notes, and snippets.

@arvinsim
Created March 3, 2015 05:41
Show Gist options
  • Save arvinsim/8549793fc461416d11a8 to your computer and use it in GitHub Desktop.
Save arvinsim/8549793fc461416d11a8 to your computer and use it in GitHub Desktop.
A hacky script to get the remote origins of the git repositories of in the current directory
import os
import subprocess
import re
currentdir = os.getcwd()
filename = currentdir + "/git_submodule_commands.sh"
pattern = re.compile("(?P<push_url>Push\s+URL):\s+(?P<url>https.*)")
# Check if file exists. If it does, delete it.
if os.path.isfile(filename):
os.remove(filename)
f = open(filename, 'a')
for dirname in os.listdir(currentdir):
if os.path.isdir(dirname):
print "in " + dirname + "..."
os.chdir(currentdir + "/" + dirname)
output = subprocess.check_output(["git", "remote", "show", "origin"])
result = pattern.search(output)
if result is not None:
g = result.groupdict()
f.write(g['url'] + '\n')
os.chdir(currentdir)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment