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

Add Diff.prototype.findSimilar by orderedlist · Pull Request #452 · 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  (2) .json  (1) All 2 file types 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
19 changes: 16 additions & 3 deletions generate/input/descriptor.json
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 @@ -524,7 +524,20 @@
"ignore": true
},
"git_diff_find_similar": {
"ignore": true
"args": {
"diff": {
"isSelf": true
},
"options": {
"isOptional": true
}
},
"return": {
"cppClassName": "Number",
"jsClassName": "Number",
"isErrorCode": true
},
"isAsync": true
},
"git_diff_foreach": {
"ignore": true
Expand Down Expand Up @@ -639,12 +652,12 @@
}
},
"diff_find_options": {
"hasConstructor": true,
"fields": {
"git_diff_similarity_metric": {
"ignore": true
}
},
"ignore": true
}
},
"diff_format_email_options": {
"ignore": true
Expand Down
7 changes: 7 additions & 0 deletions lib/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 @@ -56,4 +56,11 @@ Diff.treeToWorkdirWithIndex = function(repo, tree, opts) {
return treeToWorkdirWithIndex(repo, tree, opts);
};

// Override Diff.findSimilar to normalize opts
var findSimilar = Diff.prototype.findSimilar;
Diff.prototype.findSimilar = function(opts) {
opts = normalizeOptions(opts, NodeGit.DiffFindOptions);
return findSimilar.call(this, opts);
};

module.exports = Diff;
43 changes: 37 additions & 6 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 @@ -14,6 +14,12 @@ describe("Diff", function() {
var diffFilename = "wddiff.txt";
var diffFilepath = local("../repos/workdir", diffFilename);

var moveFromFile = "README.md";
var moveToFile = "MOVED_README.md";

var moveFromPath = local("../repos/workdir", moveFromFile);
var moveToPath = local("../repos/workdir", moveToFile);

beforeEach(function() {
var test = this;

Expand Down Expand Up @@ -45,6 +51,9 @@ describe("Diff", function() {

return fse.writeFile(diffFilepath, "1 line\n2 line\n3 line\n\n4");
})
.then(function() {
return fse.move(moveFromPath, moveToPath);
})
.then(function() {
return Diff.treeToWorkdirWithIndex(
test.repository,
Expand All @@ -56,7 +65,10 @@ describe("Diff", function() {
test.workdirDiff = workdirDiff;
})
.then(function() {
var opts = { flags: Diff.OPTION.INCLUDE_UNTRACKED };
var opts = {
flags: Diff.OPTION.INCLUDE_UNTRACKED |
Diff.OPTION.RECURSE_UNTRACKED_DIRS
};

return Diff.indexToWorkdir(test.repository, test.index, opts);
})
Expand All @@ -66,6 +78,9 @@ describe("Diff", function() {
.then(function() {
return fse.remove(diffFilepath);
})
.then(function() {
return fse.move(moveToPath, moveFromPath);
})
.catch(function(e) {
return fse.remove(diffFilepath)
.then(function() {
Expand Down Expand Up @@ -106,14 +121,14 @@ describe("Diff", function() {

it("can diff the workdir with index", function() {
var patches = this.workdirDiff.patches();
assert.equal(patches.length, 1);
assert(patches[0].isUntracked());
assert.equal(patches.length, 3);
assert(patches[2].isUntracked());

var oldFile = patches[0].delta.oldFile();
var oldFile = patches[2].delta.oldFile();
assert.equal(oldFile.path(), "wddiff.txt");
assert.equal(oldFile.size(), 0);

var newFile = patches[0].delta.newFile();
var newFile = patches[2].delta.newFile();
assert.equal(newFile.path(), "wddiff.txt");
assert.equal(newFile.size(), 23);
});
Expand Down Expand Up @@ -151,6 +166,22 @@ describe("Diff", function() {
});

it("can diff index to workdir", function() {
assert.equal(this.indexToWorkdirDiff.patches().length, 1);
assert.equal(this.indexToWorkdirDiff.patches().length, 3);
});

it("can find similar files in a diff", function() {
var diff = this.indexToWorkdirDiff;
var opts = {
flags: Diff.FIND.RENAMES |
Diff.FIND.RENAMES_FROM_REWRITES |
Diff.FIND.FOR_UNTRACKED
};

assert.equal(diff.patches().length, 3);

diff.findSimilar(opts).then(function() {
// Renamed file now treated as one diff, so 3 patches -> 2
assert.equal(diff.patches().length, 2);
});
});
});

Back | FazBrowse Home | New Git URL