nodegit
节点绑定与libgit2项目。
稳定(libgit2@v0.28.3):0.28.3
有问题吗?来和我们聊天!
请访问slack.libgit2.org注册,然后加入我们的nodegit 。
维护
泰勒·安·瓦尼克(Tyler Ang-Wanek)@Twwanek在大量出色的贡献者的帮助下!
校友维护者
Tim Branyen @Tbranyen,John Haley @Johnhaley81,Max Korp @maxkorp,Steve Smith @orderedlist,Michael Robinson @codeofinterest和Nick Kallen @NK
API文档。
http://www.*node*g*it.org/
入门。
nodegit将在大多数开箱即用,而无需任何本机依赖。
npm install nodegit
如果您收到有关libstdc ++的错误,这些错误通常是在Travis-CI上构建时经历的,则可以通过升级到最新的LIBSTDC ++ -4.9来解决此问题。
在Ubuntu:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install libstdc++-4.9-dev
在特拉维斯:
addons : apt : sources : - ubuntu-toolchain-r-test packages : - libstdc++-4.9-dev
在Circleci:
dependencies : pre : - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install -y libstdc++-4.9-dev
如果您收到有关LifeCycleScript的错误,请启动/安装,您可能会错过Ubuntu中的Libssl-Dev :
sudo apt-get install libssl-dev
您需要在Linux机上安装以下库:
- libpcre
- libpcreposix
- libkrb5
- libk5crypto
- libcom_err
在本地构建时,您还需要Kerberos和PCRE的开发包,因此机器上必须存在这两个公用事业:
- pcre-config
- Krb5-Config
如果您在安装时仍遇到问题,则应从源说明中尝试建筑物。
API示例。
克隆存储库并读取文件:
nodegit\”);
// Clone a given repository into the `./tmp` folder.
Git.Clone(\”https://*github.*c*om/nodegit/ nodegit \”, \”./tmp\”)
// Look up this known commit.
.then(function(repo) {
// Use a known commit sha from this repository.
return repo.getCommit(\”59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5\”);
})
// Look up a specific file within that commit.
.then(function(commit) {
return commit.getEntry(\”README.md\”);
})
// Get the blob contents from the file.
.then(function(entry) {
// Patch the blob to contain a reference to the entry.
return entry.getBlob().then(function(blob) {
blob.entry = entry;
return blob;
});
})
// Display information about the blob.
.then(function(blob) {
// Show the path, sha, and filesize in bytes.
console.log(blob.entry.path() + blob.entry.sha() + blob.rawsize() + \”b\”);
// Show a spacer.
console.log(Array(72).join(\”=\”) + \”\\n\\n\”);
// Show the entire file.
console.log(String(blob));
})
.catch(function(err) { console.log(err); });
\”>
var Git = require ( \" nodegit \" ) ; // Clone a given repository into the `./tmp` folder. Git . Clone ( \"https://*github.*c*om/nodegit/ nodegit \" , \"./tmp\" ) // Look up this known commit. . then ( function ( repo ) { // Use a known commit sha from this repository. return repo . getCommit ( \"59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5\" ) ; } ) // Look up a specific file within that commit. . then ( function ( commit ) { return commit . getEntry ( \"README.md\" ) ; } ) // Get the blob contents from the file. . then ( function ( entry ) { // Patch the blob to contain a reference to the entry. return entry . getBlob ( ) . then ( function ( blob ) { blob . entry = entry ; return blob ; } ) ; } ) // Display information about the blob. . then ( function ( blob ) { // Show the path, sha, and filesize in bytes. console . log ( blob . entry . path ( ) + blob . entry . sha ( ) + blob . rawsize ( ) + \"b\" ) ; // Show a spacer. console . log ( Array ( 72 ) . join ( \"=\" ) + \"\\n\\n\" ) ; // Show the entire file. console . log ( String ( blob ) ) ; } ) . catch ( function ( err ) { console . log ( err ) ; } ) ;
模拟git日志:
nodegit\”);
// Open the repository directory.
Git.Repository.open(\”tmp\”)
// Open the master branch.
.then(function(repo) {
return repo.getMasterCommit();
})
// Display information about commits on master.
.then(function(firstCommitOnMaster) {
// Create a new history event emitter.
var history = firstCommitOnMaster.history();
// Create a counter to only show up to 9 entries.
var count = 0;
// Listen for commit events from the history.
history.on(\”commit\”, function(commit) {
// Disregard commits past 9.
if (++count >= 9) {
return;
}
// Show the commit sha.
console.log(\”commit \” + commit.sha());
// Store the author object.
var author = commit.author();
// Display author information.
console.log(\”Author:\\t\” + author.name() + \” <\” + author.email() + \”>\”);
// Show the commit date.
console.log(\”Date:\\t\” + commit.date());
// Give some space and show the message.
console.log(\”\\n \” + commit.message());
});
// Start emitting events.
history.start();
});\”>
var Git = require ( \" nodegit \" ) ; // Open the repository directory. Git . Repository . open ( \"tmp\" ) // Open the master branch. . then ( function ( repo ) { return repo . getMasterCommit ( ) ; } ) // Display information about commits on master. . then ( function ( firstCommitOnMaster ) { // Create a new history event emitter. var history = firstCommitOnMaster . history ( ) ; // Create a counter to only show up to 9 entries. var count = 0 ; // Listen for commit events from the history. history . on ( \"commit\" , function ( commit ) { // Disregard commits past 9. if ( ++ count >= 9 ) { return ; } // Show the commit sha. console . log ( \"commit \" + commit . sha ( ) ) ; // Store the author object. var author = commit . author ( ) ; // Display author information. console . log ( \"Author:\\t\" + author . name ( ) + \" <\" + author . email ( ) + \">\" ) ; // Show the commit date. console . log ( \"Date:\\t\" + commit . date ( ) ) ; // Give some space and show the message. console . log ( \"\\n \" + commit . message ( ) ) ; } ) ; // Start emitting events. history . start ( ) ; } ) ;
有关更多示例,请检查示例/文件夹。
单位测试。
在进行测试之前,您需要在本地建立。见上文。
npm test
