|
| 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