[英]How do I pull from a branch with nodegit?
Would appreciate some help with nodegit.希望对 nodegit 有所帮助。 I got it to checkout a branch (
branch-development-modular-alpha-2.0.0
) with:我得到它来检查一个分支(
branch-development-modular-alpha-2.0.0
):
var cloneRepo = nodegit
.Clone(cloneURL, repoPath, cloneOptions)
.then(function (repo) {
repo.getBranch('refs/remotes/origin/' + branch).then(function(reference) {
repo.checkoutRef(reference);
// Go through repo's submodules
nodegit.Submodule.foreach(repo, function (submodule) {
var submoduleName = submodule.name();
var submoduleURL = submodule.url();
var submodulePath = repoPath + "/" + submodule.path();
// Clone the submodule
nodegit
.Clone(submoduleURL, submodulePath, cloneOptions)
.then(function (repo) {
// TODO: DO SOMETHING.
})
})
})
})
Now I'd like to pull the changes from the same branch and I have something like this however it's not updating with the latest changes from the branch.现在我想从同一个分支中提取更改,我有类似的东西,但是它没有更新分支的最新更改。
nodegit
.Repository
.open(path.resolve(__dirname, repoPath))
.then(function (repo) {
existingRepository = repo;
return existingRepository.fetchAll(cloneOptions.fetchOpts);
})
.then(function () {
return existingRepository.mergeBranches('master', 'refs/remotes/origin/' + branch);
})
.catch(function(error) {
console.log(error);
})
What am I doing wrong?我究竟做错了什么?
A pull would be a fetch + merge. 拉将是获取+合并。
Except the merge would be origin/master to master. 除非合并是原始/母版对母版。
Or origin/branch to branch. 或起源/分支到分支。
In your case, the nodegit merge
function call should then be: 在您的情况下, nodegit
merge
函数调用应为:
return existingRepository.mergeBranches(branch, 'refs/remotes/origin/' + branch);
As Jamie Counsell adds in the comments : 正如Jamie Counsell 在评论中添加的那样 :
I ran into that error too.
我也遇到了这个错误。
It ends up it was because I was retrieving the branch name using
nodegit
as well, which gave something likeorigin/refs/heads/master
instead of justmaster
.最终结果是因为我也使用
nodegit
检索了分支名称,它给出了诸如origin/refs/heads/master
而不仅仅是master
。Calling
branch.shorthand()
got me "master
"调用
branch.shorthand()
让我“master
”了
Below is thepull example in nodegit repo:下面是 nodegit repo 中的pull 示例:
var nodegit = require("../");
var path = require("path");
var repoDir = "../../test";
var repository;
// Open a repository that needs to be fetched and fast-forwarded
nodegit.Repository.open(path.resolve(__dirname, repoDir))
.then(function(repo) {
repository = repo;
return repository.fetchAll({
callbacks: {
credentials: function(url, userName) {
return nodegit.Cred.sshKeyFromAgent(userName);
},
certificateCheck: function() {
return 0;
}
}
});
})
// Now that we're finished fetching, go ahead and merge our local branch
// with the new one
.then(function() {
return repository.mergeBranches("master", "origin/master");
})
.done(function() {
console.log("Done!");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.