changeset 452:7d6bd51f0323

python/setup_repo.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 16:51:24 -0700
parents 96859ac4d23f
children be91c9fb3147
files python/setup_repo.py
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/python/setup_repo.py	Sat Aug 10 16:25:57 2013 -0700
+++ b/python/setup_repo.py	Sat Aug 10 16:51:24 2013 -0700
@@ -42,7 +42,7 @@
         print >> f, HGRC % { 'host': host, 'repo': repo, 'name': name}
 
 
-def setup_remote(local_repo, remote_url, push='ssh', remote_path=None):
+def setup_remote(local_repo, remote_url, push='ssh', remote_path=None, name=None):
     """
     setup a remote repository for local_repo
     - remote_url : public (pull) URL for remote repository
@@ -52,6 +52,17 @@
 
     # parse remote URL
     host, netloc, path, query, anchor = urlparse.urlsplit(remote_url)
+    path = path.rstrip('/')
+
+    # derive name
+    if name is None:
+        if '/' in path:
+            prefix, name = path.rsplit('/', 1)
+        else:
+            name = path
+    assert name
+
+    # get remote path, if specified
     if remote_path:
 
         # split off remote host and path
@@ -63,7 +74,7 @@
         remote_path = path
 
     # setup remote repository
-    remote_dir = '%s/%s' % (path, name)
+    remote_dir = '~/%s/%s' % (path.lstrip('/'), name)
     command = ['ssh', host, "mkdir -p %s && cd %s && hg init" % (remote_dir, remote_dir)]
     print command
     #    call(command)
@@ -105,7 +116,7 @@
     if options.remote_url:
 
         # setup remote repository
-        setup_remote(directory, options.remote_url, remote_path=options.remote_path)
+        setup_remote(directory, options.remote_url, name=name, remote_path=options.remote_path)
 
         # push changes
         call(['hg', 'push', '-R', directory])