-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommit.js
More file actions
161 lines (123 loc) · 3.91 KB
/
Copy pathcommit.js
File metadata and controls
161 lines (123 loc) · 3.91 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
var assert = require("assert");
var path = require("path");
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
describe("Commit", function() {
var reposPath = path.resolve("test/repos/workdir/.git");
var oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6";
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 with an invalid sha", function() {
return this.repository.getCommit("invalid").then(null, function(err) {
assert.ok(err instanceof Error);
});
});
it("has a message", function() {
assert.equal(this.commit.message(), "Update README.md");
});
it("has a sha", function() {
assert.equal(this.commit.sha(), oid);
});
it("has a time", function() {
assert.equal(this.commit.timeMs(), 1362012884000);
});
it("has a date", function() {
assert.equal(this.commit.date().getTime(), 1362012884000);
});
it("has a time offset", function() {
assert.equal(this.commit.timeOffset(), 780);
});
describe("author", function() {
before(function() {
this.author = this.commit.author();
});
it("is available", function() {
assert.ok(this.author instanceof NodeGit.Signature);
});
it("has a name", function() {
assert.equal(this.author.name(), "Michael Robinson");
});
it("has an email", function() {
assert.equal(this.author.email(), "mike@panmedia.co.nz");
});
});
describe("committer", function() {
before(function() {
this.author = this.commit.committer();
});
it("is available", function() {
assert.ok(this.author instanceof NodeGit.Signature);
});
it("has a name", function() {
assert.equal(this.author.name(), "Michael Robinson");
});
it("has an email", function() {
assert.equal(this.author.email(), "mike@panmedia.co.nz");
});
});
it("can walk its repository's history", function(done) {
var historyCount = 0;
var expectedHistoryCount = 364;
var history = this.commit.history();
history.on("commit", function(commit) {
historyCount++;
});
history.on("end", function(commits) {
assert.equal(historyCount, expectedHistoryCount);
assert.equal(commits.length, expectedHistoryCount);
done();
});
history.on("error", function(err) {
assert.ok(false);
});
history.start();
});
it("can fetch the master branch HEAD", function() {
var repository = this.repository;
return repository.getBranch("master").then(function(branch) {
return repository.getCommit(branch.sha());
});
});
it("can fetch all its parents", function() {
return this.commit.getParents().then(function(parents) {
assert.equal(parents.length, 1);
var sha = parents[0].sha();
assert.equal(sha, "ecfd36c80a3e9081f200dfda2391acadb56dac27");
});
});
it("can specify a parents limit", function() {
return this.commit.getParents(0).then(function(parents) {
assert.equal(parents.length, 0);
});
});
it("can retrieve and walk a commit tree", function(done) {
var commitTreeEntryCount = 0;
var expectedCommitTreeEntryCount = 198;
this.commit.getTree().then(function(tree) {
var treeWalker = tree.walk();
treeWalker.on("entry", function(entry) {
commitTreeEntryCount++;
});
treeWalker.on("error", function() {
assert.ok(false);
});
treeWalker.on("end", function(entries) {
assert.equal(commitTreeEntryCount, expectedCommitTreeEntryCount);
done();
});
treeWalker.start();
});
});
it("can get the commit diff", function() {
return this.commit.getDiff().then(function(diff) {
assert.equal(diff.length, 1);
});
});
});