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

Index diffing by orderedlist · Pull Request #392 · 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
21 changes: 19 additions & 2 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 @@ -443,7 +443,14 @@
"ignore": true
},
"git_diff_index_to_workdir": {
"ignore": true
"args": {
"index": {
"isOptional": true
},
"opts": {
"isOptional": true
}
}
},
"git_diff_init_options": {
"ignore": true
Expand Down Expand Up @@ -485,7 +492,17 @@
"ignore": true
},
"git_diff_tree_to_index": {
"ignore": true
"args": {
"old_tree": {
"isOptional": true
},
"index": {
"isOptional": true
},
"opts": {
"isOptional": true
}
}
},
"git_diff_tree_to_tree": {
"args": {
Expand Down
36 changes: 36 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
@@ -1,6 +1,7 @@
var NodeGit = require("../");
var Patch = require("./patch");
var ConvenientPatch = require("./convenient_patch");
var normalizeOptions = require("./util/normalize_options");

var Diff = NodeGit.Diff;

Expand All @@ -20,4 +21,39 @@ Diff.prototype.patches = function() {
return result;
};

// Override Diff.indexToWorkdir to normalize opts
var indexToWorkdir = Diff.indexToWorkdir;
Diff.indexToWorkdir = function(repo, index, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return indexToWorkdir(repo, index, opts);
};

// Override Diff.treeToIndex to normalize opts
var treeToIndex = Diff.treeToIndex;
Diff.treeToIndex = function(repo, tree, index, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return treeToIndex(repo, tree, index, opts);
};

// Override Diff.treeToTree to normalize opts
var treeToTree = Diff.treeToTree;
Diff.treeToTree = function(repo, from_tree, to_tree, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return treeToTree(repo, from_tree, to_tree, opts);
};

// Override Diff.treeToWorkdir to normalize opts
var treeToWorkdir = Diff.treeToWorkdir;
Diff.treeToWorkdir = function(repo, tree, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return treeToWorkdir(repo, tree, opts);
};

// Override Diff.treeToWorkdir to normalize opts
var treeToWorkdirWithIndex = Diff.treeToWorkdirWithIndex;
Diff.treeToWorkdirWithIndex = function(repo, tree, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return treeToWorkdirWithIndex(repo, tree, opts);
};

module.exports = Diff;
36 changes: 30 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 @@ -6,10 +6,8 @@ var fse = promisify(require("fs-extra"));
var local = path.join.bind(path, __dirname);

describe("Diff", function() {
var NodeGit = require("../../");
var Repository = require(local("../../lib/repository"));
var Diff = require(local("../../lib/diff"));
var normalizeOptions = require(local("../../lib/util/normalize_options"));

var reposPath = local("../repos/workdir/.git");
var oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6";
Expand All @@ -22,7 +20,12 @@ describe("Diff", function() {
return Repository.open(reposPath).then(function(repository) {
test.repository = repository;

return repository.getBranchCommit("master");
return repository.openIndex();
})
.then(function(index) {
test.index = index;

return test.repository.getBranchCommit("master");
})
.then(function(masterCommit) {
return masterCommit.getTree();
Expand All @@ -46,14 +49,20 @@ describe("Diff", function() {
return Diff.treeToWorkdirWithIndex(
test.repository,
test.masterCommitTree,
normalizeOptions({
flags: Diff.OPTION.INCLUDE_UNTRACKED
}, NodeGit.DiffOptions)
{ flags: Diff.OPTION.INCLUDE_UNTRACKED }
);
})
.then(function(workdirDiff) {
test.workdirDiff = workdirDiff;
})
.then(function() {
var opts = { flags: Diff.OPTION.INCLUDE_UNTRACKED };

return Diff.indexToWorkdir(test.repository, test.index, opts);
})
.then(function(diff) {
test.indexToWorkdirDiff = diff;
})
.then(function() {
return fse.remove(diffFilepath);
})
Expand Down Expand Up @@ -129,4 +138,19 @@ describe("Diff", function() {
assert.equal(diffs[0].patches().length, 8);
});
});

it("can diff tree to index", function() {
var repo = this.repository;
var tree = this.masterCommitTree;
var index = this.index;
var opts = { flags: Diff.OPTION.INCLUDE_UNTRACKED };

return Diff.treeToIndex(repo, tree, index, opts).then(function(diff) {
assert.equal(diff.patches().length, 0);
});
});

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

Back | FazBrowse Home | New Git URL