我在CentOS 6.7上有一个nodegit问题。在我们的Windows开发环境中,我可以使用nodegit从远程克隆/推送/拉取。
在CentOS上,然而,我得到以下克隆错误:
响应中没有Content-Type报头
我们没有使用Apache,只是使用标准的GitLab rpm。GitLab在CentOS系统上也运行得很好——我能够成功地从Git Bash中拉和推。不幸的是,我需要通过nodegit以编程方式做到这一点,但它不起作用。
如果可能的话,我宁愿不使用CURL——nodegit对我的项目来说似乎是一个更体面的选择。
应该注意的是,我在我们的Gitlab实例上使用基本的HTTP用户名/密码进行授权,因为:- gitlab和所有编程git的东西都隐藏在服务器端,
- 这是一个概念证明,看看nodegit/gitlab解决方案是否可行。
下面是尝试克隆的函数-它在Windows上工作得很好:
function pushUserUpdatesToGit(req, res, user, myItem, localPath) {
var repo, index, oid, remote,
userCreds = {
credentials: function() {
return nodegit.Cred.userpassPlaintextNew(user.username, user.pwd);
}
},
authStuff = {
remoteCallbacks: {
credentials: userCreds.credentials,
certificateCheck: function() { return 1; }
}
};
return nodegit.Clone.clone(myItem.GitLabRepoPath, localPath, authStuff)
.then(function(theRepo) {
repo = theRepo; // save it to reference in any callback we feel like
}, function (err) {
console.log("Error cloning repo: " + err );
return handleError(res, err);
}
).then(function() {
return repo.openIndex();
}, function (err) {
return handleError(res, err);
})
// Some exciting stuff happens in here that I won't bore you all with
.catch(function(error) {
console.log("ERROR DOING GIT STUFF: " + error);
return handleError(res, error);
}).done(function() {
console.log("done with git stuff");
return res.json(200, myItem);
});
}
似乎你得到这个错误是因为你的git服务器响应不支持智能HTTP (https://git-scm.com/book/en/v2/Git-on-the-Server-Smart-HTTP)。
默认情况下,gitlab的nginx配置支持这个。您是否有机会在反向代理后面运行包含的gitlab nginx设置?
如果没有,并且您没有使用gitlab包含的nginx设置,这可能会有所帮助:https://gist.github.com/massar/9399764