Mercurial > hg-stable
changeset 1205:4003ea658693
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".
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Sun, 04 Sep 2005 15:47:59 -0700 |
parents | b0f6053df539 |
children | 6512d352d6c1 |
files | mercurial/commands.py |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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)