2014-09-02 155 views
3
打开仓库

我试图用nodegit开辟一个Git仓库用下面的代码:麻烦与NodeGit

var git = require('nodegit'); 

git.Repo(repoPath, function(error, repository) { 
    if (error) throw error; 
} 

这给了我下面的错误,不管是什么我分配repoPath变量:

git.Repo(repoPath, function(error, repository) { 
    ^
Error: git_repository is required. 

我试图路径本地文件夹中,我试图路径本地文件夹,包括.git文件夹,我曾尝试使用URL远程回购。没什么。

任何人都可以帮忙吗?

我正在使用
node v0.10.24
nodegit v0.1.4。
混帐1.9.0.msysgit.0
赢得8.1专业版64位

回答

5

您需要使用open方法打开库。

git = require('nodegit') 
git.Repo.open('some-path', function(err, repo) { 
    console.log(repo.path()) 
} 

由于git在本地工作,使用远程路径将不起作用。如果你想克隆,有一个clone方法可用,它也将调用一个函数一旦克隆已执行,如

git = require('nodegit') 
git.Repo.clone('git://some-host/path', 'local-path', null, function(err, repo) { 
    console.log(repo.path()) 
} 
+0

好极了!我从网站(http://www.nodegit.org/)复制粘贴示例。看起来像自述文件中的示例有点不同。我会尝试遵循这一点。谢谢。 – Vegar 2014-09-02 10:07:12