Mercurial API: default-push not set from repo's .hg/hgrc

332 views Asked by At

I'm using MercurialApi for pushing to a remote repo.

u = ui.ui()
repo = hg.repository(u, path)
commands.commit(u, repo, message=message)
commands.push(u, repo)

This block gives me an error:

repository default-push not found

But I have the default set in the repo's .hg/hgrc. And yet I need to pass it to the ui manually:

import configparser, codecs

config = configparser.ConfigParser()
hgrc = os.path.join(path, '.hg/hgrc')

with codecs.open(hgrc, 'r', 'utf-8') as f:
    try:
        config.read_file(f)
    except Exception as e:
        raise CommitToRepositoryException(str(e))

default_path = config.get('paths', 'default')

u = ui.ui()
u.setconfig('paths', 'default', default_path)
repo = hg.repository(u, path)
commands.commit(u, repo, message=message)
commands.push(u, repo)

So much code for something that should just work. Any idea why the ui object doesn't get set properly?

2

There are 2 answers

0
Peter Westlake On

When you get the ui, it doesn't get the local config from the repo's .hg because it doesn't have a repository yet:

u = ui.ui()

You need to get the ui from the repo, which does include its local config:

u = ui.ui()
repo = hg.repository(u, path)
commands.commit(repo.ui, repo, message=message)
commands.push(repo.ui, repo)
0
Efren On

The ui may be getting another hgrc file template where all paths including 'default-push' are set to null. When you set 'default' path , it can at least find that one and is able to push.