forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.js
More file actions
242 lines (222 loc) · 7.77 KB
/
commit.js
File metadata and controls
242 lines (222 loc) · 7.77 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
var git = require('../'),
rimraf = require('rimraf'),
fs = require( 'fs' );
var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';
exports.message = function(test) {
test.expect(2);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var message = commit.message();
test.equals(error, null, 'There should be no error');
test.equals(message, 'Update README.md', 'Message should match expected value');
test.done();
});
});
};
exports.sha = function(test) {
test.expect(2);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var sha = commit.sha();
test.equals(error, null, 'There should be no error');
test.equals(sha, historyCountKnownSHA, 'SHA should match expected value');
test.done();
});
});
};
exports.time = function(test) {
test.expect(2);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var time = commit.timeMs();
test.equals(error, null, 'There should be no error');
test.equals(time, 1362012884000, 'Time should match expected value');
test.done();
});
});
};
exports.date = function(test) {
test.expect(2);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var date = commit.date();
test.equals(error, null, 'There should be no error');
test.equals(date.getTime(), 1362012884000, 'Date should match expected value');
test.done();
});
});
};
exports.offset = function(test) {
test.expect(2);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var offset = commit.offset();
test.equals(error, null, 'There should be no error');
test.equals(offset, 780, 'Offset should match expected value');
test.done();
});
});
};
exports.author = function(test) {
test.expect(2);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var author = commit.author();
test.equals(error, null, 'There should be no error');
test.notEqual(author, null, 'Author should not be null');
test.done();
});
});
};
exports.authorName = function(test) {
test.expect(1);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var author = commit.author();
var name = author.name();
test.equals(name, 'Michael Robinson', 'The author name should match expected value');
test.done();
});
});
};
exports.authorEmail = function(test) {
test.expect(1);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var author = commit.author();
var email = author.email();
test.equals(email, 'mike@panmedia.co.nz', 'The author email should match expected value');
test.done();
});
});
};
exports.committerName = function(test) {
test.expect(1);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var committer = commit.committer();
var name = committer.name();
test.equals(name, 'Michael Robinson', 'The author name should match expected value');
test.done();
});
});
};
exports.committerEmail = function(test) {
test.expect(1);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var committer = commit.committer();
var email = committer.email();
test.equals(email, 'mike@panmedia.co.nz', 'The committer email should match expected value');
test.done();
});
});
};
/**
* Test that improper commit ID's result in an error message
*/
exports.improperCommitId = function(test) {
test.expect(1);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit('not a proper commit sha', function(error, commit) {
test.notEqual(error, null, 'Error should occur');
test.done();
});
});
};
/**
* Test that retreiving walking a given commit's history works as expected.
*/
exports.history = function(test) {
test.expect(4);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
test.equals(null, error, 'Getting latest branch commit should not error');
var historyCount = 0;
var expectedHistoryCount = 364;
commit.history().on('commit', function(commit) {
historyCount++;
}).on('end', function(commits) {
test.equals(null, error, 'There should be no errors');
test.equals(historyCount, expectedHistoryCount);
test.equals(commits.length, expectedHistoryCount);
test.done();
}).on('error', function(error) {
test.equals(null, error, 'There should be no errors');
test.ok(false, 'There should be no errors');
}).start();
});
});
};
/**
* Test that retreiving master branch's HEAD commit works as expected.
*/
exports.masterHead = function(test) {
test.expect(1);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getBranch('master', function(error, branch) {
var sha = branch.sha();
repository.getCommit(sha, function(error, commit) {
test.equals(error, null, 'Getting latest branch commit should not error');
test.done();
});
});
});
};
/**
* Test that retreiving parent works as expected.
*
* @param {Object} test
*/
exports.parents = function(test) {
test.expect(3);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
commit.getParents(function(error, parents) {
test.equals(parents.length, 1, 'Commit should have exactly one parent');
var sha = parents[0].sha();
test.equals(error, null, 'Getting parent SHA should not error');
test.equals(sha, 'ecfd36c80a3e9081f200dfda2391acadb56dac27', 'Parent SHA should match expected value');
test.done();
});
});
});
};
/**
* Test that retrieving and walking a commit's tree works as expected.
*/
exports.tree = function(test) {
test.expect(2);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
test.equals(error, null, 'Getting latest branch commit should not error');
var commitTreeEntryCount = 0;
var expectedCommitTreeEntryCount = 198;
commit.getTree(function(error, tree) {
tree.walk().on('entry', function(entry) {
commitTreeEntryCount++;
}).on('end', function(error, entries) {
test.equals(commitTreeEntryCount, expectedCommitTreeEntryCount, 'Commit tree entry count does not match expected');
test.done();
}).start();
});
});
});
};
/**
* Test that getDiff works as expected.
*/
exports.getDiff = function(test) {
test.expect(1);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
commit.getDiff(function(error, diff) {
test.equals(diff.length, 1, 'Should be one item in parents diff trees');
test.done();
});
});
});
};
process.on('uncaughtException', function(err) {
console.log(err.stack);
});