diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 1e9aeaf8b..659a63403 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -2241,6 +2241,7 @@ "isAsync": false }, "git_status_file": { + "isAsync": true, "args": { "status_flags": { "isReturn": true diff --git a/generate/templates/partials/async_function.cc b/generate/templates/partials/async_function.cc index 20813136d..ca4bd8d47 100644 --- a/generate/templates/partials/async_function.cc +++ b/generate/templates/partials/async_function.cc @@ -10,6 +10,11 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) { baton->error_code = GIT_OK; baton->error = NULL; + {%if cppClassName == "GitStatus" %} + {%if cppFunctionName == "File" %} + baton->status_flags = (unsigned int *)malloc(sizeof(unsigned int)); + {%endif%} + {%endif%} {%each args|argsInfo as arg %} {%if arg.globalPayload %} @@ -260,6 +265,12 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() { {%endeach%} } + {%if cppClassName == "GitStatus" %} + {%if cppFunctionName == "File" %} + free((void *)baton->status_flags); + {%endif%} + {%endif%} + {%each args|argsInfo as arg %} {%if arg.isCppClassStringOrArray %} {%if arg.freeFunctionName %} diff --git a/lib/repository.js b/lib/repository.js index 90be1d91c..a5a0012fa 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -150,15 +150,15 @@ function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) { }); }) .then(function(diff) { - if (!(NodeGit.Status.file(repo, filePath) & - NodeGit.Status.STATUS.WT_MODIFIED) && - !(NodeGit.Status.file(repo, filePath) & - NodeGit.Status.STATUS.INDEX_MODIFIED)) { - return Promise.reject - ("Selected staging is only available on modified files."); - } - - return diff.patches(); + return NodeGit.Status.file(repo, filePath) + .then(function(status) { + if (!(status & NodeGit.Status.STATUS.WT_MODIFIED) && + !(status & NodeGit.Status.STATUS.INDEX_MODIFIED)) { + return Promise.reject + ("Selected staging is only available on modified files."); + } + return diff.patches(); + }); }) .then(function(patches) { var pathPatch = patches.filter(function(patch) { @@ -1636,17 +1636,36 @@ Repository.prototype.stageFilemode = }) .then(function(diff) { var origLength = filePaths.length; - filePaths = filePaths.filter(function(p) { - return ( - (NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.WT_MODIFIED) || - (NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.INDEX_MODIFIED) - ); - }); - if (filePaths.length === 0 && origLength > 0) { - return Promise.reject - ("Selected staging is only available on modified files."); - } - return diff.patches(); + var fileFilterPromises = fp.map(function(p) { + return NodeGit.Status.file(repo, p) + .then(function(status) { + return { + path: p, + filter: ( + (status & NodeGit.Status.STATUS.WT_MODIFIED) || + (status & NodeGit.Status.STATUS.INDEX_MODIFIED) + ) + }; + }); + }, filePaths); + + return Promise.all(fileFilterPromises) + .then(function(results) { + filePaths = fp.flow([ + fp.filter(function(filterResult) { + return filterResult.filter; + }), + fp.map(function(filterResult) { + return filterResult.path; + }) + ])(results); + + if (filePaths.length === 0 && origLength > 0) { + return Promise.reject + ("Selected staging is only available on modified files."); + } + return diff.patches(); + }); }) .then(function(patches) { var pathPatches = patches.filter(function(patch) {