NodeGit
Node bindings to the libgit2 project.
Linux | OS X | Windows | Coverage | Dependencies |
---|
|
|
|
|
Stable (libgit2#master): 0.16.0
Stable (libgit2@0.24): 0.14.1
Have a problem? Come chat with us!
Maintained by
Tim Branyen @tbranyen,
John Haley @johnhaley81, and
Max Korp @maxkorp with help from tons of
awesome contributors!
Alumni Maintainers
Steve Smith @orderedlist,
Michael Robinson @codeofinterest, and
Nick Kallen @nk
API Documentation.
http://www.nodegit.org/
Getting started.
NodeGit will work on most systems out-of-the-box without any native
dependencies.
npm install nodegit
If you receive errors about libstdc++, which are commonly experienced when
building on Travis-CI, you can fix this by upgrading to the latest
libstdc++-4.9.
In Ubuntu:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install libstdc++-4.9-dev
In Travis:
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libstdc++-4.9-dev
In 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
If you are still encountering problems while installing, you should try the
Building from source
instructions.
API examples.
Cloning a repository and reading a file:
var Git = require("nodegit");
Git.Clone("https://github.com/nodegit/nodegit", "./tmp")
.then(function(repo) {
return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5");
})
.then(function(commit) {
return commit.getEntry("README.md");
})
.then(function(entry) {
return entry.getBlob().then(function(blob) {
blob.entry = entry;
return blob;
});
})
.then(function(blob) {
console.log(blob.entry.path() + blob.entry.sha() + blob.rawsize() + "b");
console.log(Array(72).join("=") + "\n\n");
console.log(String(blob));
})
.catch(function(err) { console.log(err); });
Emulating git log:
var Git = require("nodegit");
Git.Repository.open("tmp")
.then(function(repo) {
return repo.getMasterCommit();
})
.then(function(firstCommitOnMaster) {
var history = firstCommitOnMaster.history();
var count = 0;
history.on("commit", function(commit) {
if (++count >= 9) {
return;
}
console.log("commit " + commit.sha());
var author = commit.author();
console.log("Author:\t" + author.name() + " <" + author.email() + ">");
console.log("Date:\t" + commit.date());
console.log("\n " + commit.message());
});
history.start();
});
For more examples, check the examples/
folder.
Unit tests.
You will need to build locally before running the tests. See above.
npm test