Skip to content

Commit 72baaaf

Browse files
committed
TreeBuilder.create has source as optional param, plus associated tests
1 parent 6f700f0 commit 72baaaf

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

generate/input/descriptor.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,13 @@
20992099
"isReturn": true
21002100
}
21012101
}
2102+
},
2103+
"git_treebuilder_new": {
2104+
"args": {
2105+
"source": {
2106+
"isOptional": true
2107+
}
2108+
}
21022109
}
21032110
}
21042111
},

test/tests/treebuilder.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var assert = require("assert");
2+
var path = require("path");
3+
var fs = require('fs');
4+
var promisify = require("promisify-node");
5+
var readDir = promisify(fs.readdir);
6+
var local = path.join.bind(path, __dirname);
7+
8+
describe("TreeBuilder", function(){
9+
10+
var RepoUtils = require("../utils/repository_setup");
11+
var Git = require("../../");
12+
var reposPath = local("../repos/workdir");
13+
//setup test repo each test
14+
beforeEach(function() {
15+
var test = this;
16+
17+
return Git.Repository.open(reposPath)
18+
.then(function(repo) {
19+
test.repo = repo;
20+
});
21+
});
22+
//treebuilder created with no source when creating a new folder (each folder in git is a tree), or the root folder for a root commit
23+
it("Can create a new treebuilder with no source", function(){
24+
25+
return Git.Treebuilder.create(this.repo, null);
26+
});
27+
//treebuilder created with a source tree can add / read from tree
28+
it("Can create a treebuilder from the latest commit tree", function(){
29+
30+
var test = this;
31+
//get latest commit
32+
return test.repo.getHeadCommit()
33+
//get tree of commit
34+
.then(function(commit){ return commit.getTree() })
35+
//make treebuilder from tree
36+
.then(function(tree){ return Git.Treebuilder.create(test.repo, tree)})
37+
//verify treebuilder can do stuff
38+
.then(function(treeBuilder){
39+
//check
40+
//count how many entries we should have
41+
return readDir(reposPath)
42+
//treebuilder should have all entries in the clean working dir (minus .git folder)
43+
.then(dirEntries => assert.equal(dirEntries.length-1, treeBuilder.entrycount()));
44+
});
45+
});
46+
})

0 commit comments

Comments
 (0)