Browse files

Fixes for running tests in Windows, added Tree

  • Loading branch information...
1 parent 8d338f3 commit 6f15ebd116539f6f168ab3aa4a9ae762b61f6a81 @tbranyen tbranyen committed Jul 11, 2014
Showing with 17 additions and 90 deletions.
  1. +7 −13 lib/repository.js
  2. +4 −9 lib/tree.js
  3. +2 −2 lib/tree_entry.js
  4. +1 −1 package.json
  5. +3 −2 test/tests/repository.js
  6. 0 test/tests/tree.js
  7. +0 −63 test/tree.js
View
20 lib/repository.js
@@ -196,33 +196,27 @@ Repository.prototype.createCommit = function(
// FIXME
updateRef, author, committer, message, tree, parents, callback) {
if (tree instanceof Tree) {
- Commit.createCommit.call(
+ return Commit.createCommit.call(
this,
updateRef,
author,
committer,
null /* use default message encoding */,
message,
tree,
- parents.length, parents,
- callback);
+ parents.length, parents);
} else {
var self = this;
- this.getTree(tree, function(error, tree) {
- if (error) {
- return callback(error);
- }
-
- Commit.createCommit.call(
+ return this.getTree(tree).then(function(tree) {
+ return Commit.createCommit.call(
self,
updateRef,
author,
committer,
null /* use default message encoding */,
message,
tree,
- parents.length, parents,
- callback);
+ parents.length, parents);
});
}
};
@@ -234,8 +228,8 @@ Repository.prototype.createCommit = function(
* @param {Function} callback
* @return {Blob}
*/
-Repository.prototype.createBlobFromBuffer = function(buffer, callback) {
- Blob.createFrombuffer.call(this, buffer, buffer.length, callback);
+Repository.prototype.createBlobFromBuffer = function(buffer) {
+ return Blob.createFrombuffer.call(this, buffer, buffer.length);
};
/**
View
13 lib/tree.js
@@ -6,8 +6,6 @@ var events = require("events");
var oldBuilder = TreeBuilder.create;
var oldEntryByIndex = Tree.prototype.entryByindex;
-var oldEntryByName = Tree.prototype.entryByname;
-var oldGetEntry = Tree.prototype.entryBypath;
// Backwards compatibility.
Object.defineProperties(Tree.prototype, {
@@ -46,7 +44,7 @@ Tree.prototype.entryByIndex = function(i) {
* @return {TreeEntry}
*/
Tree.prototype.entryByName = function(name) {
- var entry = oldEntryByName.call(this, name);
+ var entry = this.entryByname(name);
entry.parent = this;
return entry;
};
@@ -58,18 +56,15 @@ Tree.prototype.entryByName = function(name) {
* @param {String} path
* @return {TreeEntry}
*/
-Tree.prototype.getEntry = function(path, callback) {
+Tree.prototype.getEntry = function(path) {
// FIXME: this method ought to implement the recursion directly, rather than
// rely on oldGetEntry, in order to ensure that `parent` pointers are direct.
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.path = function() { return path; };
- callback(null, entry);
+ return entry;
});
};
View
4 lib/tree_entry.js
@@ -81,8 +81,8 @@ TreeEntry.prototype.getTree = function(callback) {
* Retrieve the tree for this entry. Make sure to call `isTree` first!
* @return {Blob}
*/
-TreeEntry.prototype.getBlob = function(callback) {
- this.parent.repo.getBlob(this.oid(), callback);
+TreeEntry.prototype.getBlob = function() {
+ return this.parent.repo.getBlob(this.oid());
};
/**
View
2 package.json
@@ -68,7 +68,7 @@
},
"scripts": {
"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",
"publish": "node-pre-gyp package && node-pre-gyp publish",
"generate": "node generate/setup && node generate",
View
5 test/tests/repository.js
@@ -3,6 +3,7 @@ var path = require("path");
describe("Repository", function() {
var reposPath = path.resolve("test/repos/workdir/.git");
+ var newRepo = path.resolve("test/repos/newrepo");
var Repository = require("../../lib/repository");
@@ -33,8 +34,8 @@ describe("Repository", function() {
});
it("can initialize a repository into a folder", function() {
- return Repository.init("repos/newrepo", 1).then(function(path, isBare) {
- return Repository.open("repos/newrepo");
+ return Repository.init(newRepo, 1).then(function(path, isBare) {
+ return Repository.open(newRepo);
});
});
});
View
0 test/tests/tree.js
No changes.
View
63 test/tree.js
@@ -1,63 +0,0 @@
-var git = require('../'),
- rimraf = require('rimraf'),
- fs = require('fs'),
- path = require('path');
-
-var sha = '5716e9757886eaf38d51c86b192258c960d9cfea';
-var fileCount = 512; // Number of blob & blob executabless
-
-exports.walk = function(test) {
- test.expect(515);
-
- git.Repo.open('repos/workdir/.git', function(error, repo) {
- repo.getCommit(sha, function(error, commit) {
- var entryCount = 0;
- commit.getTree(function(error, tree) {
- tree.walk().on('entry', function(index, entry) {
- test.equals(error, null, 'There should be no error');
- entryCount++;
- }).on('end', function(errors, entries) {
- test.equals(errors, null, 'There should be no error');
- test.equals(entryCount, fileCount, 'The manual tree entry count and the "end" tree entry count do not match');
- test.equals(entries.length, fileCount, 'The end entries count and the manual entry count do not match');
- test.done();
- }).start();
- });
- });
- });
-};
-
-exports.insert = function(test) {
- test.expect(1);
-
- git.Repo.open('repos/workdir/.git', function(error, repo) {
- repo.getCommit(sha, function(error, commit) {
- commit.getTree(function(error, tree) {
- var text = "this is a file\n",
- buffer = new Buffer(text);
- repo.createBlobFromBuffer(buffer, function(error, blobId) {
- var builder = tree.builder();
- builder.insert("lib_baz_bar.txt", blobId, git.TreeEntry.FileMode.Blob);
- builder.write(repo, function(error, treeId) {
- repo.getTree(treeId, function(error, tree) {
- var author = git.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60),
- committer = git.Signature.create("Scott A Chacon", "scott@github.com", 987654321, 90);
- repo.createCommit(null, author, committer, "message", tree, [commit], function(error, commitId) {
- repo.getCommit(commitId, function(error, commit) {
- commit.getTree(function(error, tree) {
- tree.getEntry('lib_baz_bar.txt', function(error, entry) {
- entry.getBlob(function(error, blob) {
- test.equals(blob.toString(), text);
- test.done();
- });
- });
- });
- });
- });
- });
- });
- });
- });
- });
- });
-};

0 comments on commit 6f15ebd

Please sign in to comment.