NodeGit
Node bindings to the libgit2 project.
![Gitter](https://badges.gitter.im/Join Chat.svg)
Stable: 0.2.4
Maintained by Tim Branyen @tbranyen, Michael Robinson @codeofinterest, John Haley @johnhaley81, Max Korp @maxkorp, and Nick Kallen @nk with help from awesome contributors!
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 encounter problems while installing, you should try the Building from source instructions below.
Building from source.
Minimum dependencies:
If you wish to help contribute to nodegit it is useful to build locally.
git clone git://github.com/nodegit/nodegit.git
cd nodegit
npm install
If you encounter errors, you most likely have not configured the dependencies correctly.
Installing dependencies:
Mac OS X
Linux
Using APT in Ubuntu:
sudo apt-get install build-essential
Using Pacman in Arch Linux:
sudo pacman -S base-devel
Windows
You may have to add a build flag to the installation process to successfully install. Try first without, if the build fails, try again with the flag.
Allegedly the order in which you install Visual Studio could trigger this error.
npm install nodegit --msvs_version=2013
API examples.
Cloning a repository and reading a file:
var clone = require("./").Clone.clone;
clone("https://github.com/nodegit/nodegit", "tmp", null)
.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.name() + blob.entry.sha() + blob.size() + "b");
console.log(Array(72).join("=") + "\n\n");
console.log(String(blob));
})
.catch(function(err) { console.log(err); });
Emulating git log:
var open = require("nodegit").Repository.open;
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();
});
Unit tests.
You will need to build locally before running the tests. See above.
npm test
Migrating from old versions.
The bump from 0.1.4 to 0.2.0 was a big one. Many things changed, see here:
https://github.com/nodegit/nodegit/compare/refs/tags/0.1.4...0.2.0
This update is wholly and entirely a breaking one, and older versions won't be
maintained. For the purpose of migration, perhaps the biggest point to make
is that async methods can now use promises, rather than just taking callbacks. Additionally, lots of method and property names have changed.
Node-Webkit
A common issue is with nodegit not functioning properly inside of
node-webkit applications. Because nodegit
is a native module, it has to be rebuilt for node-webkit using
nw-gyp. By default, nodegit will look in the root package's package.json for an engines
property, and within look for a node-webkit
property that holds a specific version of node-webkit. The value of this property is what will get passed as the --target
argument to nw-gyp configure
.
Currently, support for node-webkit is limited, although we intend to support it better in the future.