node.js - 如何使用nodegit从分支中 pull ?

标签 node.js git nodegit

非常感谢有关 Nodegit 的一些帮助。我用它来检查分支(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.
      })
    })
  })
})

现在我想从同一个分支中提取更改,并且我有类似的内容,但是它没有使用分支中的最新更改进行更新。

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);
})

我做错了什么?

最佳答案

pull 就是获取+ merge 。

除非 merge 是起源/主到主。
或起源/分支到分支。

就您而言,nodegit merge function那么调用应该是:

return existingRepository.mergeBranches(branch, 'refs/remotes/origin/' + branch);

Jamie Counsell添加in the comments :

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 like origin/refs/heads/master instead of just master.

Calling branch.shorthand() got me "master"

关于node.js - 如何使用nodegit从分支中 pull ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49525298/

相关文章:

javascript - React dotenv 无法加载 .env 文件

node.js - react 与 Node (Multer): Image is not found by path while it exists on that path

javascript - 保持 Node 服务器运行 "watching"以便发生事情

git - 为什么自托管 gitlab 运行程序在克隆存储库并在自托管运行程序上执行作业时遇到问题

git - 添加本地存储库作为远程存储库的子目录

node.js - 使用 nodegit 切换分支/标签

webpack - NodeGit - 无法读取未定义的属性 'TYPE'

node.js - 使用ava时错误的NODE_MODULE_VERSION

node.js - mongodb 中的 $add,$subtract 聚合框架

git - 协调在 git 存储库之外所做的更改