Javascript 如何使用Node.js克隆本地Git存储库?
我正在尝试将驻留在本地驱动器上的Git存储库克隆到一个新文件夹中。到目前为止,我已经尝试了几个模块,其中似乎是最有希望的模块 我使用的获取代码是:Javascript 如何使用Node.js克隆本地Git存储库?,javascript,node.js,git,git-clone,git-fetch,Javascript,Node.js,Git,Git Clone,Git Fetch,我正在尝试将驻留在本地驱动器上的Git存储库克隆到一个新文件夹中。到目前为止,我已经尝试了几个模块,其中似乎是最有希望的模块 我使用的获取代码是: var source = '...', target = '...'; var remoteRepository = git.remote('file://' + source), localRepository = git.repo(target); var options = { onProgres
var source = '...',
target = '...';
var remoteRepository = git.remote('file://' + source),
localRepository = git.repo(target);
var options = {
onProgress: function (progress) {
console.log(progress);
}
};
localRepository.fetch(remoteRepository, options, function (err) {
if (err) { throw err; }
console.log('Done');
});
不幸的是,这不起作用,因为js git
抱怨未知的URL格式,该格式与所使用的文件://
协议有关。删除文件://
部分时也会出现相同的错误
我还尝试将git.remote
更改为git.repo
(因为它不是实际的远程设备),但随后我得到:
TypeError: Object #<Object> has no method 'discover'
TypeError:对象ා没有方法“discover”
因此,显然js-git
不支持从本地存储库获取数据(或者我不知道怎么做)
有人
- …或者知道如何使用js git解决此问题
- 或者可以提出一个可行的替代方案
感谢您的帮助:-)为什么您不能只使用child_process.exec和命令行选项?因为它将在OS X、Linux和Windows上运行,而且我无法控制目标机器,而且我不太确定最终用户是否能够正确(!)设置Git,尤其是在Windows上。