Skip to content

Commit e570bdc

Browse files
committed
Remove handwritten commit.getTree() function
There is a custom handwritte commit.getTree() JavaScript function which conflicts with the git_commit_tree C function provided by libgit2. The custom function has been removed in favour of generating such a function from libgit2's API.
1 parent 4611ca7 commit e570bdc

File tree

11 files changed

+28
-31
lines changed

11 files changed

+28
-31
lines changed

examples/walk-tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
1010
return repo.getMasterCommit();
1111
})
1212
.then(function(firstCommitOnMaster) {
13-
return firstCommitOnMaster.getTree();
13+
return firstCommitOnMaster.tree();
1414
})
1515
.then(function(tree) {
1616
// `walk()` returns an event.

generate/input/descriptor.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,13 @@
535535
"ownedByThis": true
536536
}
537537
},
538+
"git_commit_tree": {
539+
"isAsync": true,
540+
"return" : {
541+
"isReturn": true,
542+
"isErrorCode": true
543+
}
544+
},
538545
"git_commit_tree_id": {
539546
"return": {
540547
"ownedByThis": true

lib/commit.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ Commit.prototype.getDiff = function(callback) {
8181
Commit.prototype.getDiffWithOptions = function(options, callback) {
8282
var commit = this;
8383

84-
return commit.getTree().then(function(thisTree) {
84+
return commit.tree().then(function(thisTree) {
8585
return commit.getParents().then(function(parents) {
8686
var diffs;
8787
if (parents.length) {
8888
diffs = parents.map(function(parent) {
89-
return parent.getTree().then(function(parentTree) {
89+
return parent.tree().then(function(parentTree) {
9090
return thisTree.diffWithOptions(parentTree, options);
9191
});
9292
});
@@ -114,7 +114,7 @@ Commit.prototype.getDiffWithOptions = function(options, callback) {
114114
* @return {TreeEntry}
115115
*/
116116
Commit.prototype.getEntry = function(path, callback) {
117-
return this.getTree().then(function(tree) {
117+
return this.tree().then(function(tree) {
118118
return tree.getEntry(path).then(function(entry) {
119119
if (typeof callback === "function") {
120120
callback(null, entry);
@@ -162,16 +162,6 @@ Commit.prototype.getParents = function(limit, callback) {
162162
}, callback);
163163
};
164164

165-
/**
166-
* Get the tree associated with this commit.
167-
*
168-
* @async
169-
* @return {Tree}
170-
*/
171-
Commit.prototype.getTree = function(callback) {
172-
return this.repo.getTree(this.treeId(), callback);
173-
};
174-
175165
/**
176166
* Walk the history from this commit backwards.
177167
*

lib/repository.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) {
135135
if (isStaged) {
136136
return repo.getHeadCommit()
137137
.then(function getTreeFromCommit(commit) {
138-
return commit.getTree();
138+
return commit.tree();
139139
})
140140
.then(function getDiffFromTree(tree) {
141141
return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions);
@@ -400,7 +400,7 @@ Repository.prototype.checkoutRef = function(reference, opts) {
400400
NodeGit.Checkout.STRATEGY.RECREATE_MISSING);
401401
return repo.getReferenceCommit(reference.name())
402402
.then(function(commit) {
403-
return commit.getTree();
403+
return commit.tree();
404404
})
405405
.then(function(tree) {
406406
return Checkout.tree(repo, tree, opts);
@@ -1479,7 +1479,7 @@ Repository.prototype.mergeBranches = function(
14791479
" to branch " +
14801480
fromBranch.shorthand();
14811481

1482-
return branchCommits[1].getTree()
1482+
return branchCommits[1].tree()
14831483
.then(function(tree) {
14841484
if (toBranch.isHead()) {
14851485
// Checkout the tree if we're on the branch
@@ -1567,7 +1567,7 @@ Repository.prototype.mergeBranches = function(
15671567
return repo.getBranchCommit(branch);
15681568
})
15691569
.then(function(branchCommit) {
1570-
return branchCommit.getTree();
1570+
return branchCommit.tree();
15711571
})
15721572
.then(function(tree) {
15731573
var opts = {
@@ -1627,7 +1627,7 @@ Repository.prototype.stageFilemode =
16271627
:
16281628
repo.getHeadCommit()
16291629
.then(function getTreeFromCommit(commit) {
1630-
return commit.getTree();
1630+
return commit.tree();
16311631
})
16321632
.then(function getDiffFromTree(tree) {
16331633
return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions);

test/tests/commit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ describe("Commit", function() {
456456
var commitTreeEntryCount = 0;
457457
var expectedCommitTreeEntryCount = 198;
458458

459-
return this.commit.getTree().then(function(tree) {
459+
return this.commit.tree().then(function(tree) {
460460
return new Promise(function(resolve, fail) {
461461

462462
var treeWalker = tree.walk();

test/tests/diff.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("Diff", function() {
5757
return test.repository.getBranchCommit("master");
5858
})
5959
.then(function(masterCommit) {
60-
return masterCommit.getTree();
60+
return masterCommit.tree();
6161
})
6262
.then(function(tree) {
6363
test.masterCommitTree = tree;
@@ -411,7 +411,7 @@ describe("Diff", function() {
411411
return test.repository.getHeadCommit();
412412
})
413413
.then(function(headCommit) {
414-
return headCommit.getTree();
414+
return headCommit.tree();
415415
})
416416
.then(function(headTree) {
417417
return Promise.all([

test/tests/patch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("Patch", function() {
2323
return test.repository.getBranchCommit("master");
2424
})
2525
.then(function(masterCommit) {
26-
return masterCommit.getTree();
26+
return masterCommit.tree();
2727
})
2828
.then(function(tree) {
2929
test.masterCommitTree = tree;

test/tests/stage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe("Stage", function() {
8686
return test.repository.getBranchCommit("master");
8787
})
8888
.then(function(masterCommit) {
89-
var treePromise = masterCommit.getTree();
89+
var treePromise = masterCommit.tree();
9090
var indexPromise = test.repository.refreshIndex();
9191

9292
return Promise.all([treePromise, indexPromise]);
@@ -247,7 +247,7 @@ describe("Stage", function() {
247247
//fileModeDifference - expected (newfilemode) - (oldfilemode)
248248
return test.repository.getHeadCommit()
249249
.then(function(commit) {
250-
return commit.getTree();
250+
return commit.tree();
251251
})
252252
.then(function(tree) {
253253
if (vsWorkdir) {

test/tests/tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("Tree", function() {
3333

3434
it("gets an entry by name",
3535
function(done) {
36-
this.commit.getTree().then(function(tree) {
36+
this.commit.tree().then(function(tree) {
3737
var entry = tree.entryByName("README.md");
3838
assert(entry);
3939
}).done(done);
@@ -54,7 +54,7 @@ describe("Tree", function() {
5454
return RepoUtils.commitFileToRepo(repo, file2, "", commit);
5555
})
5656
.then(function(commit) {
57-
return commit.getTree();
57+
return commit.tree();
5858
})
5959
.then(function(tree) {
6060
assert(tree);

test/tests/tree_entry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("TreeEntry", function() {
8181
return Promise.all(testPromises);
8282
};
8383

84-
return this.commit.getTree()
84+
return this.commit.tree()
8585
.then(testTree)
8686
.done(function() {
8787
done();
@@ -182,7 +182,7 @@ describe("TreeEntry", function() {
182182
var test = this;
183183

184184
return leakTest(NodeGit.TreeEntry, function() {
185-
return test.commit.getTree()
185+
return test.commit.tree()
186186
.then(function(tree) {
187187
return tree.entryByPath("example");
188188
});

0 commit comments

Comments
 (0)