NodeGit
Node bindings to the libgit2 project.
Linux | OS X | Windows | Coverage | Dependencies |
---|
|
|
|
|
Stable (libgit2#master): 0.15.0
Stable (libgit2@0.24): 0.14.0
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
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
<a name="v0-15-0" href="#v0-15-0">v0.15.0</a> (2016-06-20)
Full Changelog
This updates NodeGit to use the latest HEAD
version of libgit2. The plan for staying on the official tagged releases of libgit2 is that they will get a maintenance branch and not-breaking API fixes will be backported to them. The first branch of this sort is maint/0.14
. Going forward new releases of NodeGit will follow closely to the master
branch of libgit2.
Summary of changes that were brought in:
https://github.com/libgit2/libgit2/commit/37dba1a739b5ee6c45dc9f3c0bd1f7f7a18f13f7
Changes or improvements
-
NodeGit.FetchOptions
, and NodeGit.PushOptions
now have a proxyOpts
field that accepts a NodeGit.ProxyOptions
object that allows NodeGit to use a proxy for all remote communication
-
NodeGit.MergeOptions
has a defaultDriver
field that lets the caller change the driver used to when both sides of a merge have changed
API additions
-
Commit.createWithSignature
allows the caller to create a signed commit. There are no tests for this currently so it's labelled experimental.
-
Blob
, Commit
, Tag
, and Tree
all have a new prototype dup
method on them to make a low-level copy of the libgit2 object if needed.
-
Odb#expandIds
is exposed which takes in a list of short ids and expands them in-place to the full id of the object in the database