Skip to content

Commit 9ea39f6

Browse files
committed
Added all test files and did some refactoring
1 parent f4b9313 commit 9ea39f6

29 files changed

+168
-198
lines changed

generate/descriptor.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
"isConstructorMethod": true,
228228
"args": [
229229
{ "isReturn": true },
230-
{ "isSelf": true },
230+
{ "isSelf": false },
231231
{},
232232
{},
233233
{ "isOptional": true }

lib/commit.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Commit.prototype.date = function() {
3232
* Get the tree associated with this commit.
3333
* @return {Tree}
3434
*/
35-
Commit.prototype.getTree = function(callback) {
36-
return this.repo.getTree(this.treeId(), callback);
35+
Commit.prototype.getTree = function() {
36+
return this.repo.getTree(this.treeId());
3737
};
3838

3939
/**
@@ -44,16 +44,12 @@ Commit.prototype.getTree = function(callback) {
4444
* @param {Function} callback
4545
* @return {TreeEntry}
4646
*/
47-
Commit.prototype.getEntry = function(path, callback) {
47+
Commit.prototype.getEntry = function(path) {
4848
return this.getTree().then(function(tree) {
4949
return tree.getEntry(path).then(function(entry) {
50-
if (callback) {
51-
callback(entry);
52-
}
53-
5450
return entry;
5551
});
56-
}, callback);
52+
});
5753
};
5854

5955
/**
@@ -172,19 +168,21 @@ Commit.prototype.getDiff = function(callback) {
172168
var commit = this;
173169

174170
return commit.getParents().then(function(parents) {
175-
return parents.map(function(parent) {
176-
return parent.getTree(function(parentTree) {
177-
return commit.getTree(function(thisTree) {
171+
var diffs = parents.map(function(parent) {
172+
return parent.getTree().then(function(parentTree) {
173+
return commit.getTree().then(function(thisTree) {
178174
return parentTree.diff(thisTree);
179175
});
180176
});
181177
});
182-
}).then(function(parentDiffs) {
178+
179+
return Promise.all(diffs);
180+
}).then(function(diffs) {
183181
if (callback) {
184-
callback(null, parentDiffs);
182+
callback(null, diffs);
185183
}
186184

187-
return parentDiffs;
185+
return diffs;
188186
}, callback);
189187
};
190188

lib/diff.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ Diff.LineOrigin = {
5454
Diff.prototype.patches = function() {
5555
var size = this.size();
5656
var result = [];
57+
5758
for (var i = 0; i < size; i++) {
5859
result.push(new ConvenientPatch(this.getDelta(i), Patch.fromDiff(this, i)));
5960
}
61+
6062
return result;
6163
};
6264

lib/nodegit.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,6 @@ catch (e) {
1212
rawApi = require("../build/Debug/nodegit");
1313
}
1414

15-
// Set the exports prototype to the raw API.
16-
exports.__proto__ = rawApi;
17-
18-
// Import extensions
19-
require("./commit.js");
20-
require("./diff.js");
21-
require("./blob.js");
22-
require("./object.js");
23-
require("./signature.js");
24-
require("./odb.js");
25-
require("./oid.js");
26-
require("./index.js");
27-
require("./repository.js");
28-
require("./reference.js");
29-
require("./revwalk.js");
30-
require("./tree.js");
31-
32-
// Wrap asynchronous methods to return promises.
33-
promisify(exports);
34-
3515
// Native methods do not return an identifiable function, so this function will
3616
// filter down the function identity to match the libgit2 descriptor.
3717
descriptors.forEach(function(descriptor) {
@@ -55,6 +35,26 @@ descriptors.forEach(function(descriptor) {
5535
});
5636
});
5737

38+
// Set the exports prototype to the raw API.
39+
exports.__proto__ = rawApi;
40+
41+
// Import extensions
42+
require("./commit.js");
43+
require("./diff.js");
44+
require("./blob.js");
45+
require("./object.js");
46+
require("./signature.js");
47+
require("./odb.js");
48+
require("./oid.js");
49+
require("./index.js");
50+
require("./repository.js");
51+
require("./refs.js");
52+
require("./revwalk.js");
53+
require("./tree.js");
54+
55+
// Wrap asynchronous methods to return promises.
56+
promisify(exports);
57+
5858
// Set version.
5959
exports.version = require("../package").version;
6060

File renamed without changes.

lib/repository.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var NodeGit = require("../");
22
var normalizeOid = require("./util/normalize_oid");
33
var Blob = require("./blob");
44
var Tree = require("./tree");
5-
var Reference = require("./reference");
5+
var Reference = require("./refs");
66
var Revwalk = require("./revwalk");
77
var Commit = require("./commit");
88

@@ -122,7 +122,6 @@ Repository.prototype.getTree = function(oid, callback) {
122122

123123
var repository = this;
124124

125-
126125
return Tree.lookup(repository, oid).then(function(tree) {
127126
tree.repo = repository;
128127

lib/revwalk.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
var git = require("../");
2-
var util = require("./util");
3-
var Revwalk = git.Revwalk;
1+
var NodeGit = require("../");
2+
var normalizeOid = require("./util/normalize_oid");
3+
4+
var Revwalk = NodeGit.Revwalk;
45

56
// Backwards compatibility.
6-
Object.defineProperty(git, "RevWalk", {
7+
Object.defineProperty(NodeGit, "RevWalk", {
78
value: Revwalk,
89
enumerable: false
910
});
1011

1112
var oldSorting = Revwalk.prototype.sorting;
1213

1314
/**
14-
* Refer to vendor/libgit2/include/git2/revwalk.h for sort definitions.
15+
* Refer to vendor/libNodeGit2/include/NodeGit2/revwalk.h for sort definitions.
1516
*/
1617
Revwalk.Sort = {
1718
None: 0,
@@ -22,7 +23,7 @@ Revwalk.Sort = {
2223

2324
/**
2425
* Set the sort order for the revwalk. This function takes variable arguments
25-
* like `revwalk.sorting(git.RevWalk.Topological, git.RevWalk.Reverse).`
26+
* like `revwalk.sorting(NodeGit.RevWalk.Topological, NodeGit.RevWalk.Reverse).`
2627
*
2728
* @param {Number} sort
2829
*/
@@ -45,6 +46,8 @@ Revwalk.prototype.sorting = function() {
4546
* @return {Commit}
4647
*/
4748
Revwalk.prototype.walk = function(oid, callback) {
49+
oid = normalizeOid(oid);
50+
4851
var self = this;
4952

5053
this.push(oid);
@@ -73,7 +76,4 @@ Revwalk.prototype.walk = function(oid, callback) {
7376
walk();
7477
};
7578

76-
util.normalizeOid(Revwalk.prototype, "walk");
77-
util.makeSafe(Revwalk.prototype, "walk");
78-
7979
module.exports = Revwalk;

lib/tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Object.defineProperties(Tree.prototype, {
2424
* @return {DiffList}
2525
*/
2626
Tree.prototype.diff = function(tree, callback) {
27-
return Diff.treeToTree.call(this.repo, tree, this, null, callback);
27+
return Diff.treeToTree(this.repo, tree, this, null).then(null, callback);
2828
};
2929

3030
/**

lib/util.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/commit.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)