FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Introduced a new ConvenientLine class to wrap the lines returned from ConvenientHunk. by bleathem · Pull Request #541 · nodegit/nodegit · GitHub

Repository navigation

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

Filter by extension

Filter by extension .js  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions generate/templates/templates/nodegit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL