Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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 1 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@

*.log
.DS_STORE
.idea
18 changes: 16 additions & 2 deletions 18 generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,24 @@
}
},
"git_diff_tree_to_workdir": {
"ignore": true
"args": {
"old_tree": {
"isOptional": true
},
"opts": {
"isOptional": true
}
}
},
"git_diff_tree_to_workdir_with_index": {
"ignore": true
"args": {
"old_tree": {
"isOptional": true
},
"opts": {
"isOptional": true
}
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion 2 lib/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Commit.prototype.getDiff = function(callback) {
var diffs = parents.map(function(parent) {
return parent.getTree().then(function(parentTree) {
return commit.getTree().then(function(thisTree) {
return parentTree.diff(thisTree);
return thisTree.diff(parentTree);
});
});
});
Expand Down
82 changes: 69 additions & 13 deletions 82 test/tests/diff.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,66 @@
var assert = require("assert");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var Diff = require("../../lib/diff");

describe("Diff", function() {
var Repository = require("../../lib/repository");
var reposPath = path.resolve("test/repos/workdir/.git");
var oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6";
var diffFilename = "wddiff.txt";
var diffFilepath = path.join(
path.resolve("test/repos/workdir"),
diffFilename
);

var Repository = require("../../lib/repository");
var Diff = require("../../lib/diff");

before(function() {
before(function(done) {
var test = this;

return Repository.open(reposPath).then(function(repository) {
test.repository = repository;

return repository.getCommit(oid).then(function(commit) {
test.commit = commit;
return repository.getBranchCommit("master").then(function(masterCommit) {

return masterCommit.getTree().then(function(tree) {
test.masterCommitTree = tree;

return repository.getCommit(oid).then(function(commit) {
test.commit = commit;

return commit.getDiff().then(function(diff) {
test.diff = diff;
return commit.getDiff().then(function(diff) {
test.diff = diff;

fse.writeFile(diffFilepath, "1 line\n2 line\n3 line\n\n4")
.then(function() {
return test.repository.openIndex();
})
.then(function(indexResult) {
test.index = indexResult;
return test.index.read(1);
})
.then(function() {
return test.index.addByPath(diffFilename);
})
.then(function() {
return test.index.write();
})
.then(function() {
return test.index.writeTree();
})
.then(function() {
Diff.treeToWorkdirWithIndex(
test.repository,
test.masterCommitTree,
null
)
.then(function(workdirDiff) {
test.workdirDiff = workdirDiff;
done();
});
});
});
});
});
});
});
Expand All @@ -40,17 +82,31 @@ describe("Diff", function() {
assert.equal(lines[1].origin(), Diff.LINE.CONTEXT);
assert.equal(lines[2].origin(), Diff.LINE.CONTEXT);

var oldContent = "\n__Before submitting a pull request, please ensure " +
var oldContent = "__Before submitting a pull request, please ensure " +
"both unit tests and lint checks pass.__\n";
assert.equal(lines[2].content(), oldContent);
assert.equal(lines[3].content(), oldContent);
assert.equal(lines[3].origin(), Diff.LINE.DELETION);
assert.equal(lines[4].contentLen(), 90);
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[3].content(), newContent);
assert.equal(lines[4].content(), newContent);
assert.equal(lines[4].origin(), Diff.LINE.ADDITION);
assert.equal(lines[3].contentLen(), 162);
assert.equal(lines[4].contentLen(), 162);
});

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

var hunks = patches[0].hunks();
assert.equal(hunks.length, 1);

var lines = hunks[0].lines();
assert.equal(
lines[0].content().substr(0, lines[0].contentLen()),
"1 line\n"
);
});
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.