我整个上午都在尝试打开现有的仓库并使用nodegit更改分支或标记.文档很广泛但似乎已经过时了.关于我做错了什么的任何想法?
var NodeGit = require("nodegit");
var open = NodeGit.Repository.open;
var Tag = NodeGit.Tag;
var Checkout = NodeGit.Checkout;
open(location).then(function (repo) {
Tag.list(repo).then(function(array) {
// array is ['v1.0.0']
var ref = array[0]
Checkout.tree(repo, ref).then(function() {
// Want tag to be checked out out in detached state.
});
});
});
Run Code Online (Sandbox Code Playgroud) 使用 Node-git 我只想:
使用 git cli 我会写这样的东西
cd repo
git add file.js
git commit -m "Added file.js"
Run Code Online (Sandbox Code Playgroud)
我正在尝试按照此处描述如何使用 nodegit 执行此操作的示例进行操作,但很难遵循以下代码行:
.then(function() {
return repo.refreshIndex();
})
.then(function(indexResult) {
index = indexResult;
})
.then(function() {
// this file is in the root of the directory and doesn't need a full path
return index.addByPath(fileName);
})
.then(function() {
// this file is in a subdirectory and can use a relative path
return index.addByPath(path.join(directoryName, fileName));
})
.then(function() { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用库 nodegit(0.2.4 版)和 ssh 从 node.js 中的 teamforge 服务器克隆 git 存储库。我们的服务器向用户请求身份验证,当我尝试仅使用克隆方法而不传递选项时,我收到错误消息:“回调无法初始化 SSH 凭据”。
我在文件 private.key 和 public.key 中有私钥和公钥。它们位于我在网络风暴中设置为工作目录的目录中,因此位置应该不是问题。
没有找到如何做的例子(也许我错过了),但下面的代码是我得到的最接近的:
'use strict';
var nodegit = require("nodegit"),
Clone = nodegit.Clone,
cred = nodegit.Cred;
var options = {
remoteCallbacks: {
credentials: function () {
return cred.sshKeyNew('user', 'public.key', 'private.key', '');
}
}
};
Clone.clone("ssh://user@teamforgeserver.net/reponame", "localTmp", options)
.then(function(repo) {
var r = repo;
},
function(err){
var e = err;
}
);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
TypeError: Object #<Object> has no method 'isFulfilled' at value
(c:\...\proj\node_modules\nodegit\node_modules\nodegit-promise\lib\core.js:36:15)
Run Code Online (Sandbox Code Playgroud)
你有什么提示可能是错误的或一般如何做吗?
NodeGit似乎没有提供任何API来检索Git配置值.
见http://www.nodegit.org/#Config
我期待像Config#getValue()或类似的API来检索配置值.
也许,截至目前,NodeGit中缺少它,因为libgit2具有这些API.
任何提示?
我有两个分支,master并且master.min在我的仓库中。
假设我当前的分支是master.min.
我的主分支正在提交 - abcd
一些推送发生在 master 分支 - efgh,ijkl
我存储我的主分支的当前提交:
repo.getBranchCommit("master")
.then(function(commit) {
startCommit = commit;
})
Run Code Online (Sandbox Code Playgroud)
由于分支之间的切换时间很长,我需要完成所有剩余的操作 master.min
所以,我做了一个提取:
repo.fetch("master");
Run Code Online (Sandbox Code Playgroud)
现在,我需要获取在abcd&之间添加、修改或删除的所有文件的列表ijkl
commit.getDiff() is not enough. I need diff between two commits.
Run Code Online (Sandbox Code Playgroud) 伙计们,我有一个分支user/foo,我想从远程办理退房.码:
Git.prototype.refresh = function refresh(branch) {
var options = {
credentials: function() {
return NodeGit.Cred.userpassPlaintextNew(GITHUB_TOKEN, "x-oauth-basic");
},
certificateCheck: function() {
return 1;
}
};
return NodeGit.Repository.open(localPath).then(function (repo) {
return repo.checkoutBranch(branch, options).then(function (checkoutresult) {
return repo.fetchAll(options).then(function (result) {
return Promise.resolve(result);
}).catch(function (err) {
console.log('Unable to fetch',err);
return Promise.reject(new Error(err));
});
}).catch(function(err) {
console.log('checkoutBranch',err);
return Promise.reject(new Error(err));
});
});
};
Run Code Online (Sandbox Code Playgroud)
错误:
[Error: Error: Reference 'refs/remotes/user/foo/HEAD' not found]
Run Code Online (Sandbox Code Playgroud)
我是否正确使用checkoutBranch?我已将远程克隆到本地目录,并尝试切换到特定分支.
谢谢!
我正在写一个小应用程序,用于分析文件夹内的git存储库。我正在使用nodegit来解析基于libgit2的仓库。
如何使用nodegit从仓库中的所有分支获取所有提交?
这是我当前的代码:
var git = require('nodegit');
var fs = require('fs');
var path = require('path');
var getDirectories = function(srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory();
});
}
var getData = function(srcDir) {
var repos = getDirectories(srcDir);
var globalCommits = [];
var promises = repos.map(repoName => {
return git.Repository.open(path.join(srcDir, repoName)).then(function(repo) {
var walker = git.Revwalk.create(repo);
walker.pushHead();
return walker.getCommitsUntil(c => true).then(function (commits) {
var cmts = commits.map(x => ({
sha: x.sha(),
msg: x.message().split('\n')[0],
date: x.date(),
author: x.author(),
repo: repoName …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 nodegit 将 git 视为内容的数据库。因此,我正在编写函数来访问 repo 中的内容。我能够检索关于给定文件的文件 blob 和其他信息,但我正在努力获取时间戳信息。
我想获得 1) 创建文件的日期,以及 2) 上次更新的日期。但到目前为止,我还没有弄清楚这怎么可能。
为了获取文件,我需要按照以下步骤操作:
1)Commit使用检索最新的getMasterCommit。
2) 从 中Commit,TreeEntry使用getEntry.
3) 从TreeEntry,获取各种元数据,然后获取Blobwith getBlob。
4) 从Blob,获取其他元数据以及文件的原始文本。
问题是,我唯一能得到我找到的日期的地方是Commit,它有一个date函数。这可能有助于获取上次更新日期,但实际上并没有帮助,因为它只返回Commmit(显然!)的日期,但尚不清楚该文件是否已针对该提交进行了更新。
我还希望能够获取为给定文件创建的日期。我可以想象这可能通过搜索给定 TreeEntry 的提交历史来获得,但我尚不清楚如何做到这一点。事实上,能够搜索给定文件的提交历史可能是这里需要的东西。但我一直无法看到这是否可能。
有人可以在这里提供指导吗?
我是nodegit的新手。我想查看最新的10次回购提交,文件更改以及相应提交中引入的更改。
我有最近提交的10个列表,但是我一直在获取提交细节。
这是我正在使用的代码
var nodegit = require('nodegit');
var repoPath = "some_repo_path";
//open branch
nodegit.Repository.open(repoPath).then(function(repo){
//get branch
return repo.getCurrentBranch().then(function(ref) {
console.log("On " + ref.shorthand() + " (" + ref.target() + ")");
//get commit
return repo.getBranchCommit(ref.shorthand());
}).then(function(commit) {
//get commit history
var history = commit.history();
p = new Promise(function(resolve, reject) {
history.on("end", resolve);
history.on("error", reject);
});
history.start();
return p;
}).then(function(commits){
//iterate through last 10 commits
for (var i = 0; i < 10; i++) {
var sha = commits[i].sha().substr(0,7),
msg = commits[i].message().split('\n')[0]; …Run Code Online (Sandbox Code Playgroud) 我有这个:
nodegit.Reference
.lookup(repo, `refs/tags/${tagName}`)
.then(ref => nodegit.Commit.lookup(repo, ref.target()))
.then(commit => ({
tag: tagName,
hash: commit.sha(),
date: commit.date().toJSON(),
}))
Run Code Online (Sandbox Code Playgroud)
如果tagName只是提交的别名,则此代码有效,但是如果标记是使用nodegit创建的正确标记,则会给我一个错误:
the requested type does not match the type in the ODB
Run Code Online (Sandbox Code Playgroud)
使用git show [tagname]时显示如下:
tag release_2017-07-21_1413
Tagger: xxx
Date: Fri Jul 21 16:13:47 2017 +0200
commit c465e3323fc2c63fbeb91f9b9b43379d28f9b761 (tag: release_2017-07-21_1413, initialRelease)
Run Code Online (Sandbox Code Playgroud)
那么,如何从该标记引用到提交本身(c465e)?
我编写了一个使用nodegit的 Electron 应用程序。对于我的测试部分,我结合使用ava和 Spectron 来测试我的应用程序。我的所有测试都有效 - 包括在我的应用程序中使用nodegit 的功能。
除了上述测试之外,我还制作了一个纯非 Electron测试文件,在其中直接导入 nodegit。
import * as nodegit from 'nodegit';
Run Code Online (Sandbox Code Playgroud)
现在通过ava执行此测试将返回:
node_modules\.pnpm\nodegit@0.27.0\node_modules\nodegit\build\Release\nodegit.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 82. This version of Node.js requires
NODE_MODULE_VERSION 83. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at Module._extensions..node (internal/modules/cjs/loader.js:1122:18)
Run Code Online (Sandbox Code Playgroud)
82版本到底来自哪里?我只安装了nodejs 14.15.0,它使用了83预期的版本。为什么节点认为该版本与我的应用程序中实际运行的版本不匹配?这就是我的package.json样子:
"devDependencies": {
"ava": "^3.13.0",
},
"scripts": …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用nodegit打开一个包含以下代码的git存储库:
var git = require('nodegit');
git.Repo(repoPath, function(error, repository) {
if (error) throw error;
}
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误,无论我分配repoPath变量:
git.Repo(repoPath, function(error, repository) {
^
Error: git_repository is required.
Run Code Online (Sandbox Code Playgroud)
我试过路径到本地文件夹,我已经尝试过路径到本地文件夹,包括.git文件夹,我已经尝试过使用url的远程仓库.没什么.
任何人都可以帮忙吗?
我正在使用
节点v0.10.24
nodegit v0.1.4.
git 1.9.0.msysgit.0
win 8.1 pro 64bit
nodegit ×13
git ×10
node.js ×9
javascript ×4
libgit2 ×2
ava ×1
electron ×1
git-commit ×1
spectron ×1
ssh ×1