NodeGit
Node bindings to the libgit2 project.
Stable: 0.1.3
Maintained by Tim Branyen @tbranyen, Michael
Robinson @codeofinterest, and Nick Kallen
@nk, with help from awesome
contributors!
API Documentation.
http://www.nodegit.org/nodegit/
Building and Installing.
Minimum dependencies:
npm install nodegit
Building manually:
If you wish to help contribute to nodegit it is useful to build locally.
git clone git://github.com/tbranyen/nodegit.git
cd nodegit
npm install ejs && npm run codegen && npm install
If you encounter errors, you most likely have not configured the dependencies
correctly.
Installing dependencies:
OS X
Using Brew:
brew install cmake libzip
Linux
Using APT in Ubuntu:
sudo apt-get install cmake libzip-dev build-essential
Using Pacman in Arch Linux:
sudo pacman -S cmake libzip 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("nodegit").Repo.clone;
clone("https://github.com/nodegit/nodegit", "tmp", null, function(err, repo) {
if (err) {
throw err;
}
var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";
repo.getCommit(sha, function(err, commit) {
if (err) {
throw error;
}
commit.getEntry("README.md", function(err, entry) {
if (err) {
throw error;
}
entry.getBlob(function(err, blob) {
if (err) {
throw err;
}
console.log(entry.name() + entry.sha() + blob.size() + "b");
console.log(Array(72).join("=") + "\n\n");
console.log(String(blob));
});
});
});
});
Emulating git log:
var open = require("nodegit").Repo.open;
open("tmp", function(err, repo) {
if (err) {
throw err;
}
repo.getMaster(function(err, branch) {
if (err) {
throw err;
}
var history = branch.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