forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifflist.js
More file actions
49 lines (41 loc) · 2.44 KB
/
difflist.js
File metadata and controls
49 lines (41 loc) · 2.44 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
var git = require('../'),
rimraf = require('rimraf'),
fs = require( 'fs' );
var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';
/**
* Test that retreiving parent works as expected.
*
* @param {Object} test
*/
exports.walkingDiffs = function(test) {
test.expect(16);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
commit.getDiff(function(error, diffList) {
test.equal(null, error, 'Should not error');
diffList[0].patches().forEach(function(patch) {
test.equal(null, error, 'Should not error');
test.equal(patch.oldFile().path(), 'README.md', 'Old file path should match expected');
test.equal(patch.newFile().path(), 'README.md', 'New file path should match expected');
test.equal(patch.size(), 1, 'Content array should be of known length');
test.ok(patch.isModified(), 'Status should be known type');
var hunk = patch.hunks()[0];
test.equal(hunk.size(), 5, 'Content array should be of known length');
var lines = hunk.lines();
test.equal(lines[0].lineOrigin, git.DiffList.LineOrigin.Context, 'First content item should be context');
test.equal(lines[1].lineOrigin, git.DiffList.LineOrigin.Context, 'Second content item should be context');
test.equal(lines[2].lineOrigin, git.DiffList.LineOrigin.Context, 'Third content item should be context');
var oldContent = '__Before submitting a pull request, please ensure both unit tests and lint checks pass.__\n';
test.equal(lines[3].content, oldContent, 'Old content should match known value');
test.equal(lines[3].lineOrigin, git.DiffList.LineOrigin.Deletion, 'Fourth content item should be deletion');
test.equal(lines[3].length, 90, 'Fourth content length should match known value');
var newContent = '__Before submitting a pull request, please ensure both that you\'ve added unit tests to cover your shiny new code, and that all unit tests and lint checks pass.__\n';
test.equal(lines[4].content, newContent, 'New content should match known value');
test.equal(lines[4].lineOrigin, git.DiffList.LineOrigin.Addition, 'Fifth content item should be addition');
test.equal(lines[4].length, 162, 'Fifth content length should match known value');
test.done();
});
});
});
});
};