[PATCH 2 of 2] Adds an option to update <repo>/.hg/hgrc when cloning to a remote repo

Sean Meiners sean.meiners at linspire.com
Fri Jun 30 19:58:54 CDT 2006


# HG changeset patch
# User Sean Meiners <sean.meiners at linspire.com>
# Node ID 8722ac6571a680d023c26ef6571ed8eeb566ce4e
# Parent  917d84809ce13d4f1ac0d9b20e58c1bc6fdef248
Adds an option to update <repo>/.hg/hgrc when cloning to a remote repo.

Adds an option to set the <repo>/.hg/hgrc to point at the newly created
remote repository when cloning from a local to remote repo. This was done
with the intention of making it easier for those of us who like to work in
a more centralized model (even if only for backup purposes). The result
being that if you pass the '--update-hgrc' flag to clone you will be able
to push and pull from the remote repo without having to manually edit the
hgrc file. For those who create lots of branches, this is a big win.

diff -r 917d84809ce1 -r 8722ac6571a6 mercurial/commands.py
--- a/mercurial/commands.py	Fri Jun 30 17:58:06 2006 -0700
+++ b/mercurial/commands.py	Fri Jun 30 17:58:06 2006 -0700
@@ -1012,6 +1012,36 @@ def clone(ui, source, dest=None, **opts)
         if not opts['noupdate']:
             doupdate(dest_repo.ui, dest_repo)
 
+    elif src_repo.local():
+        if opts['update_hgrc']:
+            inPaths = False
+            defaultFound = False
+            groupRE = re.compile(r'^\s*\[([^\]]+)\].*')
+            defaultRE = re.compile(r'^\s*default\s*=.*')
+            lines = []
+            f = src_repo.opener("hgrc", "r", text=True)
+            for line in f:
+                match = groupRE.match(line)
+                if match:
+                    if match.group(1) == 'paths':
+                        inPaths = True
+                    else:
+                        if inPaths and not defaultFound:
+                            lines.append( 'default = %s\n' % dest )
+                        inPaths = False
+                elif inPaths:
+                    if defaultRE.match(line):
+                        lines.append( 'default = %s\n' % dest )
+                        defaultFound = True
+                        continue
+                lines.append(line)
+            f.close()
+
+            f = src_repo.opener("hgrc", "w", text=True)
+            for line in lines:
+                f.write(line)
+            f.close()
+ 
     if d:
         d.close()
 
@@ -2937,6 +2967,7 @@ table = {
            _('a changeset you would like to have after cloning')),
           ('', 'pull', None, _('use pull protocol to copy metadata')),
           ('e', 'ssh', '', _('specify ssh command to use')),
+          ('u', 'update-hgrc', None, _('update local hgrc file to point to the remote repo')),
           ('', 'remotecmd', '',
            _('specify hg command to run on the remote side'))],
          _('hg clone [OPTION]... SOURCE [DEST]')),


More information about the Mercurial mailing list