Skip to content

Commit df70270

Browse files
committed
Merge pull request nodegit#366 from nodegit/untracked
INCLUDE_UNTRACKED option not working for diffs
2 parents e3d82d0 + 22ce509 commit df70270

4 files changed

Lines changed: 115 additions & 52 deletions

File tree

generate/input/libgit2-supplement.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,70 @@
279279
]
280280
}
281281
}
282+
],
283+
[
284+
"git_diff_options",
285+
{
286+
"type": "struct",
287+
"fields": [
288+
{
289+
"type": "unsigned int",
290+
"name": "version"
291+
},
292+
{
293+
"type": "uint32_t",
294+
"name": "flags"
295+
},
296+
{
297+
"type": "git_submodule_ignore_t",
298+
"name": "ignore_submodules"
299+
},
300+
{
301+
"type": "git_strarray",
302+
"name": "pathspec"
303+
},
304+
{
305+
"type": "git_diff_notify_cb",
306+
"name": "notify_cb"
307+
},
308+
{
309+
"type": "void *",
310+
"name": "notify_payload"
311+
},
312+
{
313+
"type": "uint32_t",
314+
"name": "context_lines"
315+
},
316+
{
317+
"type": "uint32_t",
318+
"name": "interhunk_lines"
319+
},
320+
{
321+
"type": "uint16_t",
322+
"name": "id_abbrev"
323+
},
324+
{
325+
"type": "git_off_t",
326+
"name": "max_size"
327+
},
328+
{
329+
"type": "const char *",
330+
"name": "old_prefix"
331+
},
332+
{
333+
"type": "const char *",
334+
"name": "new_prefix"
335+
}
336+
],
337+
"used": {
338+
"needs": [
339+
"git_diff_init_options",
340+
"git_diff_tree_to_workdir",
341+
"git_diff_tree_to_workdirext",
342+
"git_diff_tree_to_tree"
343+
]
344+
}
345+
}
282346
]
283347
],
284348
"groups": [

generate/templates/partials/field_accessors.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343

4444
{% elsif field.isCallbackFunction %}
4545
if (value->IsFunction()) {
46+
if (!wrapper->raw->{{ field.name }}) {
47+
wrapper->raw->{{ field.name }} = ({{ field.cType }}){{ field.name }}_cppCallback;
48+
}
49+
4650
wrapper->{{ field.name }} = new NanCallback(value.As<Function>());
4751
}
4852

generate/templates/templates/struct_content.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void {{ cppClassName }}::ConstructFields() {
6363

6464
// Set the static method call and set the payload for this function to be
6565
// the current instance
66-
this->raw->{{ field.name }} = ({{ field.cType }}){{ field.name }}_cppCallback;
66+
this->raw->{{ field.name }} = NULL;
6767
this->raw->{{ fields|payloadFor field.name }} = (void *)this;
6868
this->{{ field.name }} = new NanCallback();
6969
{% elsif field.payloadFor %}

test/tests/diff.js

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var path = require("path");
33
var promisify = require("promisify-node");
44
var fse = promisify(require("fs-extra"));
55
var Diff = require("../../lib/diff");
6+
var normalizeOptions = require("../../lib/util/normalize_options");
7+
var NodeGit = require("../../");
68

79
describe("Diff", function() {
810
var Repository = require("../../lib/repository");
@@ -14,55 +16,48 @@ describe("Diff", function() {
1416
diffFilename
1517
);
1618

17-
before(function(done) {
19+
before(function() {
1820
var test = this;
1921

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

23-
return repository.getBranchCommit("master").then(function(masterCommit) {
24-
25-
return masterCommit.getTree().then(function(tree) {
26-
test.masterCommitTree = tree;
27-
28-
return repository.getCommit(oid).then(function(commit) {
29-
test.commit = commit;
30-
31-
return commit.getDiff().then(function(diff) {
32-
test.diff = diff;
33-
34-
fse.writeFile(diffFilepath, "1 line\n2 line\n3 line\n\n4")
35-
.then(function() {
36-
return test.repository.openIndex();
37-
})
38-
.then(function(indexResult) {
39-
test.index = indexResult;
40-
return test.index.read(1);
41-
})
42-
.then(function() {
43-
return test.index.addByPath(diffFilename);
44-
})
45-
.then(function() {
46-
return test.index.write();
47-
})
48-
.then(function() {
49-
return test.index.writeTree();
50-
})
51-
.then(function() {
52-
Diff.treeToWorkdirWithIndex(
53-
test.repository,
54-
test.masterCommitTree,
55-
null
56-
)
57-
.then(function(workdirDiff) {
58-
test.workdirDiff = workdirDiff;
59-
done();
60-
});
61-
});
62-
});
63-
});
64-
});
65-
});
25+
return repository.getBranchCommit("master");
26+
})
27+
.then(function(masterCommit) {
28+
return masterCommit.getTree();
29+
})
30+
.then(function(tree) {
31+
test.masterCommitTree = tree;
32+
33+
return test.repository.getCommit(oid);
34+
})
35+
.then(function(commit) {
36+
test.commit = commit;
37+
38+
return commit.getDiff();
39+
}).then(function(diff) {
40+
test.diff = diff;
41+
42+
return fse.writeFile(diffFilepath, "1 line\n2 line\n3 line\n\n4");
43+
})
44+
.then(function() {
45+
return Diff.treeToWorkdirWithIndex(
46+
test.repository,
47+
test.masterCommitTree,
48+
normalizeOptions({
49+
flags: Diff.OPTION.INCLUDE_UNTRACKED
50+
}, NodeGit.DiffOptions)
51+
);
52+
})
53+
.then(function(workdirDiff) {
54+
test.workdirDiff = workdirDiff;
55+
});
56+
});
57+
58+
after(function(done) {
59+
return fse.unlink(diffFilepath).then(function() {
60+
done();
6661
});
6762
});
6863

@@ -99,15 +94,15 @@ describe("Diff", function() {
9994
it("can diff the workdir with index", function() {
10095
var patches = this.workdirDiff.patches();
10196
assert.equal(patches.length, 1);
97+
assert(patches[0].isUntracked());
10298

103-
var hunks = patches[0].hunks();
104-
assert.equal(hunks.length, 1);
99+
var oldFile = patches[0].delta.oldFile();
100+
assert.equal(oldFile.path(), "wddiff.txt");
101+
assert.equal(oldFile.size(), 0);
105102

106-
var lines = hunks[0].lines();
107-
assert.equal(
108-
lines[0].content().substr(0, lines[0].contentLen()),
109-
"1 line\n"
110-
);
103+
var newFile = patches[0].delta.newFile();
104+
assert.equal(newFile.path(), "wddiff.txt");
105+
assert.equal(newFile.size(), 23);
111106
});
112107

113108
it("can diff with a null tree", function() {

0 commit comments

Comments
 (0)