forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_entry.js
More file actions
90 lines (77 loc) · 2.39 KB
/
tree_entry.js
File metadata and controls
90 lines (77 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var assert = require("assert");
var path = require("path");
var local = path.join.bind(path, __dirname);
describe("TreeEntry", function() {
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
var Tree = NodeGit.Tree;
var reposPath = local("../repos/workdir");
var oid = "5716e9757886eaf38d51c86b192258c960d9cfea";
beforeEach(function() {
var test = this;
return Repository.open(reposPath)
.then(function(repository) {
test.repository = repository;
return repository.getCommit(oid);
})
.then(function(commit) {
test.commit = commit;
});
});
it("will fail on a missing file", function() {
return this.commit.getEntry("test/-entry.js")
.then(null, function(err) {
assert.ok(err instanceof Error);
});
});
it("provides the correct sha for a file", function() {
return this.commit.getEntry("README.md")
.then(function(entry) {
assert.equal(entry.sha(), "6cb45ba5d32532bf0d1310dc31ca4f20f59964bc");
});
});
it("provides the filename", function() {
return this.commit.getEntry("test/raw-commit.js")
.then(function(entry) {
assert.equal(entry.filename(), "raw-commit.js");
});
});
it("provides the blob representation of the entry", function() {
return this.commit.getEntry("test/raw-commit.js")
.then(function(entry) {
return entry.getBlob();
})
.then(function(blob) {
assert.equal(blob.rawsize(), 2736);
});
});
it("provides the blob representation via callback", function() {
return this.commit.getEntry("test/raw-commit.js")
.then(function(entry) {
entry.getBlob(function (error, blob) {
assert.equal(blob.rawsize(), 2736);
});
});
});
it("provides the tree the entry is part of", function() {
return this.commit.getEntry("test")
.then(function(entry) {
return entry.getTree();
})
.then(function(tree) {
assert.ok(tree instanceof Tree);
});
});
it("can determine if an entry is a file", function() {
return this.commit.getEntry("README.md")
.then(function(entry) {
assert.ok(entry.isFile());
});
});
it("can determine if an entry is a directory", function() {
return this.commit.getEntry("example")
.then(function(entry) {
assert.equal(entry.isFile(), false);
});
});
});