Skip to content
Closed
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 generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,7 @@
"isAsync": false
},
"git_status_file": {
"isAsync": true,
"args": {
"status_flags": {
"isReturn": true
Expand Down
11 changes: 11 additions & 0 deletions generate/templates/partials/async_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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 %}
Expand Down
59 changes: 39 additions & 20 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down