Mercurial API:默认推送未从存储库的 .hg/hgrc 设置。



我正在使用MercurialApi来推送到远程回购。

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

这个区块给我一个错误:

repository default-push not found

但我在repo的.hg/hgrc中设置了默认值。但我需要手动将其传递给ui:

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)

太多的代码应该只是工作。知道为什么ui对象没有正确设置吗?

当您获得ui时,它不会从repo's.hg中获得本地配置,因为它还没有存储库:

u = ui.ui()

您需要从repo中获取ui,其中包含其本地配置:

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

用户界面可能正在获取另一个hgrc文件模板,其中包括"default push"在内的所有路径都设置为null。当你设置"默认"路径时,它至少可以找到那个路径并能够推送。

最新更新