You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to call tree.diffWorkDir and am running into problems with the required DiffOptions parameter. I don't see any way to pass in a DiffOptions object in any of the examples, the docs or in the JS code. I've tried figuring it out from the C++ side but am hitting the wall. Is this supported or am I just missing something simple?
Here is how to fix: edit v0.18.json and add "isOptional": true, to the diffOptions parameter of diffWorkDir. Recompile using the instructions in the readme. Use npm link to test this out; submit a pull request when you're done.
I gave it a shot -- it changed the error message but still doesn't appear to work.
Changed JSON for the opts parameter of diffWorkDir:
{"name": "opts","cType": "const git_diff_options *","cppClassName": "GitDiffOptions","jsClassName": "DiffOptions","isOptional": true,"comment": "Structure with options to influence diff or NULL for defaults."}
Here is how the function is getting called:
tree.diffWorkDir(repo,function(diffList){
...
}
Here is the error message:
tree.diffWorkDir(repo, function(err, diffList) {
Error: Callback is required and must be a Function.
I wouldn't even mind passing in the DiffOpts as opposed to omitting the argument, but I don't see how to pass in a DiffOpts object as it doesn't appear to exist. Even if I try to just pass in a JSON object I don't know what to put in there. Tried specifying some fields/values based on libgit2 docs without success.
I believe the root of the problem is in asyncFunction.cc.ejs. The code that generates the check functions doesn't take into account the fact some arguments may be optional and generates static indexing that may or may not be accurate at runtime.
if(args.Length()==<%-jsArg%>||!args[<%-jsArg%>]->IsFunction()){returnThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));}
In the case of diffWorkDir, this generates the following code in tree.cc:
if (args.Length() == 0 || !args[0]->IsObject()) {
returnThrowException(Exception::Error(String::New("Repository repo is required.")));
}
if (args.Length() == 2 || !args[2]->IsFunction()) {
returnThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
}
When I omit the DiffOpts argument, argument 0 is the repo and argument 1 is the callback, which doesn't fly with the check functions.
I believe this is the issue, but am not sure how to go about correcting it because I'm not familiar with the templates. Will spend some time looking into it.
Currently, there's no way to instantiate a DiffOptions object directly... It is several hours of work to get this working, so I don't expect to get to it soon -- and you don't need this yet anyway.
Thanks, passing null works. I tried that before but it only works after changing the DiffOptions argument to optional. Pull request has been submitted.
Activity
nkallen commentedon Oct 5, 2013
I think this is broken ATM.
Here is how to fix: edit v0.18.json and add
"isOptional": true,to the diffOptions parameter ofdiffWorkDir. Recompile using the instructions in the readme. Use npm link to test this out; submit a pull request when you're done.kmctown commentedon Oct 6, 2013
I gave it a shot -- it changed the error message but still doesn't appear to work.
Changed JSON for the opts parameter of diffWorkDir:
Here is how the function is getting called:
Here is the error message:
I wouldn't even mind passing in the DiffOpts as opposed to omitting the argument, but I don't see how to pass in a DiffOpts object as it doesn't appear to exist. Even if I try to just pass in a JSON object I don't know what to put in there. Tried specifying some fields/values based on libgit2 docs without success.
kmctown commentedon Oct 7, 2013
I believe the root of the problem is in asyncFunction.cc.ejs. The code that generates the check functions doesn't take into account the fact some arguments may be optional and generates static indexing that may or may not be accurate at runtime.
In the case of diffWorkDir, this generates the following code in tree.cc:
When I omit the DiffOpts argument, argument 0 is the repo and argument 1 is the callback, which doesn't fly with the check functions.
I believe this is the issue, but am not sure how to go about correcting it because I'm not familiar with the templates. Will spend some time looking into it.
nkallen commentedon Oct 7, 2013
I think it'll work if you just pass null:
tree.diffWorkDir(repo, null, function(err, diffList) {nkallen commentedon Oct 7, 2013
Currently, there's no way to instantiate a DiffOptions object directly... It is several hours of work to get this working, so I don't expect to get to it soon -- and you don't need this yet anyway.
kmctown commentedon Oct 7, 2013
Thanks, passing null works. I tried that before but it only works after changing the DiffOptions argument to optional. Pull request has been submitted.