nodegit(Node.js的libgit2):如何推拉?
我试着用手推或拉 这个软件包很受欢迎,而且一切都正常,但我似乎找不到这些基本的方法。我错过了什么nodegit(Node.js的libgit2):如何推拉?,node.js,git,Node.js,Git,我试着用手推或拉 这个软件包很受欢迎,而且一切都正常,但我似乎找不到这些基本的方法。我错过了什么 还有其他软件包吗?github网站上提供的示例 对于fetch: 对于拉动: : 尝试此方法获取和拉取: /** * Fetch from remote * fileName: pull.js * * @param {string} repositoryPath - Path to local git repository * @param {string} remoteName - R
还有其他软件包吗?github网站上提供的示例 对于
fetch
:
对于拉动
:
:
尝试此方法获取和拉取:
/**
* Fetch from remote
* fileName: pull.js
*
* @param {string} repositoryPath - Path to local git repository
* @param {string} remoteName - Remote name
* @param {string} branch - Branch to fetch
*/
var Git = require('nodegit');
var open = Git.Repository.open;
module.exports = function (repositoryPath, remoteName, branch, cb) {
var repository;
var remoteBranch = remoteName + '/' + branch;
open(repositoryPath)
.then(function (_repository) {
repository = _repository;
return repository.fetch(remoteName);
}, cb)
.then(function () {
return repository.mergeBranches(branch, remoteBranch);
}, cb)
.then(function (oid) {
cb(null, oid);
}, cb);
};
/**
* Pushes to a remote
*
* @param {string} repositoryPath - Path to local git repository
* @param {string} remoteName - Remote name
* @param {string} branch - Branch to push
* @param {doneCallback} cb
*/
var Git = require('nodegit');
var open = Git.Repository.open;
module.exports = function (repositoryPath, remoteName, branch, cb) {
var repository, remoteResult;
open(repositoryPath)
.then(function (_repository) {
repository = _repository;
return repository.getRemote(remoteName);
}, cb)
.then(function (_remoteResult) {
remoteResult = _remoteResult;
return repository.getBranch(branch);
}, cb)
.then(function (ref) {
return remoteResult.push([ref.toString()], new Git.PushOptions());
}, cb)
.then(function (number) {
cb(null, number);
}, cb);
};
然后你可以用这种方式:
var pull = require('./pull.js');
var remoteRef = 'origin';
pull(repositoryPath, remoteRef, ourBranch, function(errFetch, oid) {
if (errFetch) {
return errFetch;
}
console.log(oid);
});
然后尝试推送:
/**
* Fetch from remote
* fileName: pull.js
*
* @param {string} repositoryPath - Path to local git repository
* @param {string} remoteName - Remote name
* @param {string} branch - Branch to fetch
*/
var Git = require('nodegit');
var open = Git.Repository.open;
module.exports = function (repositoryPath, remoteName, branch, cb) {
var repository;
var remoteBranch = remoteName + '/' + branch;
open(repositoryPath)
.then(function (_repository) {
repository = _repository;
return repository.fetch(remoteName);
}, cb)
.then(function () {
return repository.mergeBranches(branch, remoteBranch);
}, cb)
.then(function (oid) {
cb(null, oid);
}, cb);
};
/**
* Pushes to a remote
*
* @param {string} repositoryPath - Path to local git repository
* @param {string} remoteName - Remote name
* @param {string} branch - Branch to push
* @param {doneCallback} cb
*/
var Git = require('nodegit');
var open = Git.Repository.open;
module.exports = function (repositoryPath, remoteName, branch, cb) {
var repository, remoteResult;
open(repositoryPath)
.then(function (_repository) {
repository = _repository;
return repository.getRemote(remoteName);
}, cb)
.then(function (_remoteResult) {
remoteResult = _remoteResult;
return repository.getBranch(branch);
}, cb)
.then(function (ref) {
return remoteResult.push([ref.toString()], new Git.PushOptions());
}, cb)
.then(function (number) {
cb(null, number);
}, cb);
};