Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions generate/templates/templates/nodegit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ require("./utils/lookup_wrapper");
require("./utils/normalize_options");

// Load up extra types;
require("./convenient_line");
require("./convenient_hunk");
require("./convenient_patch");
require("./status_file");
Expand Down
3 changes: 2 additions & 1 deletion lib/convenient_hunk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var NodeGit = require("../");
var ConvenientLine = NodeGit.ConvenientLine;

function ConvenientHunk(raw, i) {
this.raw = raw;
Expand Down Expand Up @@ -29,7 +30,7 @@ ConvenientHunk.prototype.size = function() {
ConvenientHunk.prototype.lines = function() {
var result = [];
for (var i = 0; i < this.size(); i++) {
result.push(this.raw.getLineInHunk(this.i, i));
result.push(new ConvenientLine(this.raw.getLineInHunk(this.i, i), i));
}
return result;
};
Expand Down
73 changes: 73 additions & 0 deletions lib/convenient_line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
var NodeGit = require("../");

function ConvenientLine(raw, i) {
this.raw = raw;
this.i = i;
}

/**
* The content of the line
* @return {String}
*/
ConvenientLine.prototype.origin = function() {
return this.raw.origin();
};

/**
* The content of the line
* @return {String}
*/
ConvenientLine.prototype.oldLineno = function() {
return this.raw.oldLineno();
};

/**
* The content of the line
* @return {String}
*/
ConvenientLine.prototype.newLineno = function() {
return this.raw.newLineno();
};

/**
* The content of the line
* @return {String}
*/
ConvenientLine.prototype.numLines = function() {
return this.raw.numLines();
};

/**
* The content of the line
* @return {String}
*/
ConvenientLine.prototype.contentLen = function() {
return this.raw.contentLen();
};


/**
* The content of the line
* @return {String}
*/
ConvenientLine.prototype.contentOffset = function() {
return this.raw.contentOffset();
};

/**
* The content of the line
* @return {String}
*/
ConvenientLine.prototype.rawContent = function() {
return this.raw.content();
};

/**
* The relevant line
* @return {String}
*/
ConvenientLine.prototype.content = function() {
return this.raw.content().substring(0, this.raw.contentLen() - 1);
};

NodeGit.ConvenientLine = ConvenientLine;
15 changes: 13 additions & 2 deletions test/tests/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ describe("Diff", function() {

var oldContent = "__Before submitting a pull request, please ensure " +
"both unit tests and lint checks pass.__\n";
assert.equal(lines[3].content(), oldContent);
assert.equal(lines[3].rawContent(), oldContent);
assert.equal(lines[3].origin(), Diff.LINE.DELETION);
assert.equal(lines[3].contentLen(), 90);

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";
assert.equal(lines[4].content(), newContent);
assert.equal(lines[4].rawContent(), newContent);
assert.equal(lines[4].origin(), Diff.LINE.ADDITION);
assert.equal(lines[4].contentLen(), 162);
});
Expand All @@ -134,6 +134,17 @@ describe("Diff", function() {
assert.equal(newFile.size(), 23);
});

it("can resolve individual line chages from the patch hunks", function() {
this.workdirDiff.patches().forEach(function(convenientPatch) {
convenientPatch.hunks().forEach(function(convenientHunk) {
convenientHunk.lines().forEach(function(line) {
assert(!/\n/.exec(line.content()));
assert(/\n/.exec(line.rawContent()));
});
});
});
});

it("can diff with a null tree", function() {
var repo = this.repository;
var tree = this.masterCommitTree;
Expand Down