0
我试图把文件在存储库中,但得到错误{远程起源已经存在错误号-4}如何推送使用nodegit?
基本任务打开连接,提交文件,{拉和合并},变更推
我可以打开连接,提交文件但休息操作不起作用。
无法识别什么是问题在这里我是新的nodegit。
代码:
import Git from "nodegit";
import path from "path";
import fs from "fs";
import promisify from "promisify-node";
import fs_extra from "fs-extra";
let url = "XXX/tutorial.git",
local = "./Cloned",
directoryName = "Code",
cloneOpts = {
fetchOpts: {
callbacks: {
credentials: function(url, userName) {
return Git.Cred.userpassPlaintextNew("***[email protected]","*****");
}
}
}
};
let repo,
index,
oid,
remote;
var fse = promisify(fs_extra);
var fileName = "letmebe.txt";
var fileContent = "Costal Area is good";
fse.ensureDir = promisify(fse.ensureDir);
let repoDir = "../../Code";
Git.Repository.open(local)
.then(function (repoResult) {
repo = repoResult;
return fse.ensureDir(path.join(repo.workdir(), directoryName));
})
.then(function() {
return fs.writeFile(path.join(repo.workdir(), directoryName, fileName), fileContent);
})
.then(function() {
return repo.refreshIndex();
})
.then(function (indexResult) {
index = indexResult;
})
.then(function() {
return index.addByPath(path.join(directoryName, fileName))
.then(function() {
return index.write();
})
.then(function() {
return index.writeTree();
});
})
.then(function (oidResult) {
oid = oidResult;
return Git.Reference.nameToId(repo, "HEAD");
})
.then(function (head) {
return repo.getCommit(head);
})
.then(function (parent) {
var author = Git.Signature.create("Kunal Vashist",
"[email protected]", 123456789, 60);
var committer = Git.Signature.create("Kunal Vashist",
"[email protected]", 987654321, 90);
return repo.createCommit("HEAD", author, committer, "message", oid, [parent]);
})
.then(function() {
return Git.Remote.create(repo, "origin",url)
.then(function(remoteResult) {
remote = remoteResult;
// Create the push object for this remote
return remote.push(
["refs/heads/master:refs/heads/master"],
{
callbacks: {
credentials: function(url, userName) {
return Git.Cred.userpassPlaintextNew("****@gmail.com","****");
}
}
}
);
});
})
.catch(function (err) {
console.log(err);
})
.done(function (commitId) {
console.log("New Commit: ", commitId);
});
文件越来越承诺正常,但不能推。