Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 110 lines (95 sloc) 3.44 KB
#!/usr/bin/env python
# Update a git repo so that it uses ssh for the pushurl
# but http for pulling, so you don't need a password to pull.
# Unfortunately git uses lots of different syntaxes for the same thing.
# Examples:
# pushurl = ssh://
# url = git://
# OR
# pushurl =
# url =
# OR
# pushurl =
# url =
# Provide the repo name; the lines are in reponame/.git/config
# Share and enjoy under the GPL v2 or later.
import sys, os
import re
def repopull(repoloc):
configfile = os.path.join(repoloc, ".git", "config")
if not os.path.exists(configfile):
print configfile, "doesn't exist"
fp = open(configfile)
pushurl = None
urlline = None
for line in fp:
# print "Line:", line,
if re.match('^\s*pushurl\s*=\s*(\S*)\s$', line):
print repoloc, "already has a pushurl! Bailing."
m = re.match('^(\s*)url\s*=\s*(\S*)\s$', line)
if m:
if pushurl:
print "More than one url = line in %s! Bailing." % repoloc
whitespace =
pushurl =
urlline = line
if not pushurl or not urlline:
print "Couldn't find a url = line in", repoloc
# Now we have a single url = line, and there was no pushurl = line.
# pushurl is just the original url (presumably the push one).
# Parse it. The two syntaxes I know are:
# url = ssh://
# url = [git@]
print "Found push url:", pushurl
if pushurl.startswith("http"):
print "url is not a push url.", pushurl
if pushurl.startswith("ssh://"):
# The only example I have of this is gimp/gnome,
# where ssh://
# maps to git://
# Hope this is standard?
print "Using gnome syntax for", repoloc
parts = pushurl[6:].split('/')
pullurl = 'git://' + '/'.join(parts)
# Hope it's github syntax, [git@]
# map to
if ':' not in pushurl:
print "Can't parse", pushurl
host, path = pushurl.split(':')
if '@' in host:
host = host.split('@')[1]
pullurl = 'https://%s/%s' % (host, path)
print "pushurl:", pushurl
print "pullurl:", pullurl
# Supposedly we have all we need now.
configbak = configfile + ".bak"
os.rename(configfile, configbak)
fp = open(configbak)
ofp = open(configfile, "w")
for line in fp:
if line != urlline:
# It is the url line. Preserve the initial whitespace:
ofp.write(whitespace + "# " + line[len(whitespace):])
ofp.write(whitespace + "url = " + pullurl + '\n')
ofp.write(whitespace + "pushurl = " + pushurl + '\n')
print "Wrote", configfile
# pushurl=$( egrep '^\s*url\s*=' $configfile | sed -e 's/^\s*url\s*=\s*//' )
# This should be something like
if __name__ == '__main__':
for repo in sys.argv[1:]: