|
| 1 | +var assert = require("assert"); |
| 2 | +var path = require("path"); |
| 3 | + |
| 4 | +describe("TreeEntry", function() { |
| 5 | + var reposPath = path.resolve("test/repos/workdir/.git"); |
| 6 | + var oid = "5716e9757886eaf38d51c86b192258c960d9cfea"; |
| 7 | + |
| 8 | + var Repository = require("../../lib/repository"); |
| 9 | + var Tree = require("../../lib/tree"); |
| 10 | + |
| 11 | + beforeEach(function() { |
| 12 | + var test = this; |
| 13 | + |
| 14 | + return Repository.open(reposPath).then(function(repository) { |
| 15 | + test.repository = repository; |
| 16 | + |
| 17 | + return repository.getCommit(oid).then(function(commit) { |
| 18 | + test.commit = commit; |
| 19 | + }); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + it("will fail on a missing file", function() { |
| 24 | + return this.commit.getEntry("test/-entry.js").then(null, function(err) { |
| 25 | + assert.ok(err instanceof Error); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + it("provides the correct sha for a file", function() { |
| 30 | + return this.commit.getEntry("README.md").then(function(entry) { |
| 31 | + var sha = entry.sha(); |
| 32 | + |
| 33 | + assert.equal(sha, "6cb45ba5d32532bf0d1310dc31ca4f20f59964bc"); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + it("provides the filename", function() { |
| 38 | + return this.commit.getEntry("test/raw-commit.js").then(function(entry) { |
| 39 | + var name = entry.name(); |
| 40 | + |
| 41 | + assert.equal(name, "raw-commit.js"); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + it("provides the blob representation of the entry", function() { |
| 46 | + return this.commit.getEntry("test/raw-commit.js").then(function(entry) { |
| 47 | + return entry.getBlob().then(function(blob) { |
| 48 | + var size = blob.rawsize(); |
| 49 | + |
| 50 | + assert.equal(size, 2736); |
| 51 | + }); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it("provides the tree the entry is part of", function() { |
| 56 | + return this.commit.getEntry("test").then(function(entry) { |
| 57 | + return entry.getTree().then(function(tree) { |
| 58 | + assert.ok(tree instanceof Tree); |
| 59 | + }); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + it("can determine if an entry is a file", function() { |
| 64 | + return this.commit.getEntry("README.md").then(function(entry) { |
| 65 | + var isFile = entry.isFile(); |
| 66 | + |
| 67 | + assert.equal(isFile, true); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + it("can determine if an entry is a directory", function() { |
| 72 | + return this.commit.getEntry("example").then(function(entry) { |
| 73 | + var isFile = entry.isFile(); |
| 74 | + |
| 75 | + assert.equal(isFile, false); |
| 76 | + }); |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
0 commit comments