在Windows上使用git-remote-hg
根据这个回答 https://stackoverflow.com/a/13354944/867294,设置 git 和 mercurial 一起使用应该是相对简单的,“没有依赖或其他东西”。
不过在 Windows 上,这似乎并没有那么顺利。
我试着按照这个指南来操作:
https://github.com/msysgit/msysgit/wiki/Guide-to-git-remote-hg
在调整了 makeFile 以适应我的系统并构建了 git 后,我无法调用 git-remote-hg,因为它抱怨找不到 Python 解释器,尽管配置是正确的。
所以我手动调用了它,使用了:
C:/Python27/python.exe git-remote-hg clone C:/TestMercurialRepo
现在我遇到了以下错误:
Traceback (most recent call last):
File "git-remote-hg", line 99, in <module>
sys.exit(HgRemoteHelper().main(sys.argv))
File "d:\development\msysgit\git\git_remote_helpers\helper.py", line 196, in m
ain
repo = self.get_repo(alias, url)
File "git-remote-hg", line 33, in get_repo
if repo.capable('branchmap'):
File "c:\Python27\lib\site-packages\mercurial\repoview.py", line 205, in __get
attr__
return getattr(self._unfilteredrepo, attr)
AttributeError: 'mqrepo' object has no attribute 'capable'
我该如何解决这个问题?
如果有现成的版本,那就太好了,因为我觉得我为了让它工作做了太多事情。
2 个回答
我需要再深入调查一下,但看起来 git-remote-hg
可能需要安装特定版本的 Mercurial。特别是需要一个支持 capable
方法的 repo
对象的版本。
这看起来像是 git-remote-hg 代码中的一个错误。任何一个足够新的 Mercurial 版本都有 repoview
,而且所有类型的 repo 对象应该都支持 capable
方法。所以我猜问题出在 git-remote-hg 创建的对象上。
总之,很明显 git-remote-hg 是用 Mercurial 的 Python 代码来完成它的工作的。所以它们之间是有依赖关系的。
另外,你的回溯信息和这个代码 https://github.com/felipec/git/blob/fc/remote/hg/contrib/remote-helpers/git-remote-hg 不匹配,这让调试你的设置变得困难。
今天我在Windows上搞定了这个。简单来说,因为msysgit的版本不支持Python,所以我用了Felipe的git-remote-hg.py文件,并用py2exe把它打包成一个可执行文件。然后,我把所有的py2exe输出放到了我Git安装目录下的'libexec'文件夹里,这样就能用了。
要让它工作,你需要:
- Python 2.7
- Mercurial的Python模块(Windows安装包可以在这里找到)
- py2exe(Windows安装包可以在这里找到)
- Felipe的git-remote-hg Python脚本(可以在这里保存为原始文件)
创建一个名为setup.py的文件,内容如下:
from distutils.core import setup
import py2exe
setup(console=['git-remote-hg.py'])
把这个文件保存到你的文件系统中,然后运行以下命令:
python setup.py py2exe --include mercurial
py2exe会生成一个名为'dist'的文件夹,里面有输出文件。把这个文件夹里的内容复制到你主Git安装文件夹下的libexec\git-core文件夹里(例如,C:\Program Files(x86)\Git)。
现在,你应该可以使用Git客户端从Mercurial仓库克隆代码了。
(注意:我写这些步骤的时候有点匆忙,如果我漏掉了什么,请告诉我)。