Skip to content

Commit

Permalink
Fixes for running tests in Windows, added Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Jul 11, 2014
1 parent 8d338f3 commit 6f15ebd
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 90 deletions.
20 changes: 7 additions & 13 deletions lib/repository.js
Expand Up @@ -196,33 +196,27 @@ Repository.prototype.createCommit = function(
// FIXME // FIXME
updateRef, author, committer, message, tree, parents, callback) { updateRef, author, committer, message, tree, parents, callback) {
if (tree instanceof Tree) { if (tree instanceof Tree) {
Commit.createCommit.call( return Commit.createCommit.call(
this, this,
updateRef, updateRef,
author, author,
committer, committer,
null /* use default message encoding */, null /* use default message encoding */,
message, message,
tree, tree,
parents.length, parents, parents.length, parents);
callback);
} else { } else {
var self = this; var self = this;
this.getTree(tree, function(error, tree) { return this.getTree(tree).then(function(tree) {
if (error) { return Commit.createCommit.call(
return callback(error);
}

Commit.createCommit.call(
self, self,
updateRef, updateRef,
author, author,
committer, committer,
null /* use default message encoding */, null /* use default message encoding */,
message, message,
tree, tree,
parents.length, parents, parents.length, parents);
callback);
}); });
} }
}; };
Expand All @@ -234,8 +228,8 @@ Repository.prototype.createCommit = function(
* @param {Function} callback * @param {Function} callback
* @return {Blob} * @return {Blob}
*/ */
Repository.prototype.createBlobFromBuffer = function(buffer, callback) { Repository.prototype.createBlobFromBuffer = function(buffer) {
Blob.createFrombuffer.call(this, buffer, buffer.length, callback); return Blob.createFrombuffer.call(this, buffer, buffer.length);
}; };


/** /**
Expand Down
13 changes: 4 additions & 9 deletions lib/tree.js
Expand Up @@ -6,8 +6,6 @@ var events = require("events");


var oldBuilder = TreeBuilder.create; var oldBuilder = TreeBuilder.create;
var oldEntryByIndex = Tree.prototype.entryByindex; var oldEntryByIndex = Tree.prototype.entryByindex;
var oldEntryByName = Tree.prototype.entryByname;
var oldGetEntry = Tree.prototype.entryBypath;


// Backwards compatibility. // Backwards compatibility.
Object.defineProperties(Tree.prototype, { Object.defineProperties(Tree.prototype, {
Expand Down Expand Up @@ -46,7 +44,7 @@ Tree.prototype.entryByIndex = function(i) {
* @return {TreeEntry} * @return {TreeEntry}
*/ */
Tree.prototype.entryByName = function(name) { Tree.prototype.entryByName = function(name) {
var entry = oldEntryByName.call(this, name); var entry = this.entryByname(name);
entry.parent = this; entry.parent = this;
return entry; return entry;
}; };
Expand All @@ -58,18 +56,15 @@ Tree.prototype.entryByName = function(name) {
* @param {String} path * @param {String} path
* @return {TreeEntry} * @return {TreeEntry}
*/ */
Tree.prototype.getEntry = function(path, callback) { Tree.prototype.getEntry = function(path) {
// FIXME: this method ought to implement the recursion directly, rather than // FIXME: this method ought to implement the recursion directly, rather than
// rely on oldGetEntry, in order to ensure that `parent` pointers are direct. // rely on oldGetEntry, in order to ensure that `parent` pointers are direct.
var self = this; var self = this;
oldGetEntry.call(this, path, function(error, entry) {
if (error) {
return callback(error);
}


return this.entryBypath(path).then(function(entry) {
entry.parent = self; entry.parent = self;
entry.path = function() { return path; }; entry.path = function() { return path; };
callback(null, entry); return entry;
}); });
}; };


Expand Down
4 changes: 2 additions & 2 deletions lib/tree_entry.js
Expand Up @@ -81,8 +81,8 @@ TreeEntry.prototype.getTree = function(callback) {
* Retrieve the tree for this entry. Make sure to call `isTree` first! * Retrieve the tree for this entry. Make sure to call `isTree` first!
* @return {Blob} * @return {Blob}
*/ */
TreeEntry.prototype.getBlob = function(callback) { TreeEntry.prototype.getBlob = function() {
this.parent.repo.getBlob(this.oid(), callback); return this.parent.repo.getBlob(this.oid());
}; };


/** /**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -68,7 +68,7 @@
}, },
"scripts": { "scripts": {
"lint": "jshint lib test/tests", "lint": "jshint lib test/tests",
"mocha": "istanbul cover _mocha -- test/runner test/tests --report=lcov", "mocha": "istanbul cover node_modules/mocha/bin/_mocha -- test/runner test/tests --report=lcov",
"test": "npm run lint && npm run mocha", "test": "npm run lint && npm run mocha",
"publish": "node-pre-gyp package && node-pre-gyp publish", "publish": "node-pre-gyp package && node-pre-gyp publish",
"generate": "node generate/setup && node generate", "generate": "node generate/setup && node generate",
Expand Down
5 changes: 3 additions & 2 deletions test/tests/repository.js
Expand Up @@ -3,6 +3,7 @@ var path = require("path");


describe("Repository", function() { describe("Repository", function() {
var reposPath = path.resolve("test/repos/workdir/.git"); var reposPath = path.resolve("test/repos/workdir/.git");
var newRepo = path.resolve("test/repos/newrepo");


var Repository = require("../../lib/repository"); var Repository = require("../../lib/repository");


Expand Down Expand Up @@ -33,8 +34,8 @@ describe("Repository", function() {
}); });


it("can initialize a repository into a folder", function() { it("can initialize a repository into a folder", function() {
return Repository.init("repos/newrepo", 1).then(function(path, isBare) { return Repository.init(newRepo, 1).then(function(path, isBare) {
return Repository.open("repos/newrepo"); return Repository.open(newRepo);
}); });
}); });
}); });
Empty file removed test/tests/tree.js
Empty file.
63 changes: 0 additions & 63 deletions test/tree.js

This file was deleted.

0 comments on commit 6f15ebd

Please sign in to comment.