nodegit/nodegit — pull request #85 by FrozenCow (2013-09-04 21:02:45+00:00)
Title: Fixed TreeBuilder.write's missing repo argument to match its documentation

I guess TreeBuilder was not yet used to create a bare repository's first commit. In the following example TreeBuilder.write throws an exception with the old code:

git.Repo.init('repo', true, function(err,repo) {
if (err) { return cb(err); }
repo.createBlobFromFile('README.md',function(err,blobId) {
if (err) { return cb(err); }
var treeBuilder = git.TreeBuilder.create(null); // null -> this is key
treeBuilder.insert('README.md', blobId, 0100644);
treeBuilder.write(repo, function(err,treeId) { // This threw an exception
var signature = git.Signature.now('The Dude', 'thedude@dude.com');
repo.createCommit(null, signature, signature, null, 'Initial commit', treeId, 0, [], function(err,commitId) {
if (err) { return cb(err); }
cb(null, repo);
});
});
});
});

The documentation said the first argument of 'write' is the repo (http://www.nodegit.org/nodegit/#TreeBuilder-write), so this change should match the code with the documentation.
This is however a breaking change, so any code that depended on TreeBuilder.write needs to be altered. Alternatively we could potentially use something like 'repo || self.repo'.