# HG changeset patch # User Bryan O'Sullivan # Date 1125874079 25200 # Node ID 4003ea6586934cb217db164e3e100d938f271e67 # Parent b0f6053df539edf339b7fd22c33bec128d5feedf Write out hgrc properly. Previously, we simply appended to the hgrc file, which meant that it ended up containing multiple "paths" sections. Now, we only modify "paths.default". diff -r b0f6053df539 -r 4003ea658693 mercurial/commands.py --- a/mercurial/commands.py Sun Sep 04 15:12:20 2005 -0700 +++ b/mercurial/commands.py Sun Sep 04 15:47:59 2005 -0700 @@ -10,7 +10,7 @@ demandload(globals(), "os re sys signal shutil imp") demandload(globals(), "fancyopts ui hg util lock revlog") demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") -demandload(globals(), "errno socket version struct atexit sets") +demandload(globals(), "ConfigParser errno socket version struct atexit sets") class UnknownCommand(Exception): """Exception raised if command is not in the command table.""" @@ -622,9 +622,16 @@ repo = hg.repository(ui, dest, create=1) repo.pull(other) - f = repo.opener("hgrc", "a") - f.write("\n[paths]\n") - f.write("default = %s\n" % abspath) + cfg = ConfigParser.SafeConfigParser() + try: + fp = repo.opener('hgrc', 'r') + os.unlink(fp.name) + cfg.readfp(fp) + except IOError, inst: + if inst.errno != errno.ENOENT: raise + if not cfg.has_section('paths'): cfg.add_section('paths') + cfg.set('paths', 'default', abspath) + cfg.write(repo.opener('hgrc', 'w')) if not opts['noupdate']: update(ui, repo)