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
64 changes: 64 additions & 0 deletions 64 generate/input/libgit2-supplement.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,70 @@
]
}
}
],
[
"git_diff_options",
{
"type": "struct",
"fields": [
{
"type": "unsigned int",
"name": "version"
},
{
"type": "uint32_t",
"name": "flags"
},
{
"type": "git_submodule_ignore_t",
"name": "ignore_submodules"
},
{
"type": "git_strarray",
"name": "pathspec"
},
{
"type": "git_diff_notify_cb",
"name": "notify_cb"
},
{
"type": "void *",
"name": "notify_payload"
},
{
"type": "uint32_t",
"name": "context_lines"
},
{
"type": "uint32_t",
"name": "interhunk_lines"
},
{
"type": "uint16_t",
"name": "id_abbrev"
},
{
"type": "git_off_t",
"name": "max_size"
},
{
"type": "const char *",
"name": "old_prefix"
},
{
"type": "const char *",
"name": "new_prefix"
}
],
"used": {
"needs": [
"git_diff_init_options",
"git_diff_tree_to_workdir",
"git_diff_tree_to_workdirext",
"git_diff_tree_to_tree"
]
}
}
]
],
"groups": [
Expand Down
4 changes: 4 additions & 0 deletions 4 generate/templates/partials/field_accessors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

{% elsif field.isCallbackFunction %}
if (value->IsFunction()) {
if (!wrapper->raw->{{ field.name }}) {
wrapper->raw->{{ field.name }} = ({{ field.cType }}){{ field.name }}_cppCallback;
}

wrapper->{{ field.name }} = new NanCallback(value.As<Function>());
}

Expand Down
2 changes: 1 addition & 1 deletion 2 generate/templates/templates/struct_content.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void {{ cppClassName }}::ConstructFields() {

// Set the static method call and set the payload for this function to be
// the current instance
this->raw->{{ field.name }} = ({{ field.cType }}){{ field.name }}_cppCallback;
this->raw->{{ field.name }} = NULL;
this->raw->{{ fields|payloadFor field.name }} = (void *)this;
this->{{ field.name }} = new NanCallback();
{% elsif field.payloadFor %}
Expand Down
97 changes: 46 additions & 51 deletions 97 test/tests/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var Diff = require("../../lib/diff");
var normalizeOptions = require("../../lib/util/normalize_options");
var NodeGit = require("../../");

describe("Diff", function() {
var Repository = require("../../lib/repository");
Expand All @@ -14,55 +16,48 @@ describe("Diff", function() {
diffFilename
);

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

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

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;

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();
});
});
});
});
});
});
return repository.getBranchCommit("master");
})
.then(function(masterCommit) {
return masterCommit.getTree();
})
.then(function(tree) {
test.masterCommitTree = tree;

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

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

return fse.writeFile(diffFilepath, "1 line\n2 line\n3 line\n\n4");
})
.then(function() {
return Diff.treeToWorkdirWithIndex(
test.repository,
test.masterCommitTree,
normalizeOptions({
flags: Diff.OPTION.INCLUDE_UNTRACKED
}, NodeGit.DiffOptions)
);
})
.then(function(workdirDiff) {
test.workdirDiff = workdirDiff;
});
});

after(function(done) {
return fse.unlink(diffFilepath).then(function() {
done();
});
});

Expand Down Expand Up @@ -99,15 +94,15 @@ 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());

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

var lines = hunks[0].lines();
assert.equal(
lines[0].content().substr(0, lines[0].contentLen()),
"1 line\n"
);
var newFile = patches[0].delta.newFile();
assert.equal(newFile.path(), "wddiff.txt");
assert.equal(newFile.size(), 23);
});

it("can diff with a null tree", function() {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.