diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 1e9aeaf8b..1290486d9 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -402,6 +402,7 @@ "selfFreeing": true, "functions": { "git_commit_amend": { + "isAsync": true, "args": { "author": { "isOptional": true @@ -1268,13 +1269,35 @@ "merge": { "functions": { "git_merge": { + "isAsync": true, "args": { + "repo": { + "cppClassName": "GitRepository", + "cType": "git_repository *", + "jsClassName": "Repo" + }, "their_heads": { "cType": "const git_annotated_commit **", "cppClassName": "Array", "jsClassName": "Array", "arrayElementCppClassName": "GitAnnotatedCommit" + }, + "their_heads_len": { + "cType": "size_t", + "cppClassName": "Number", + "jsClassName": "Number" + }, + "merge_opts": { + "cType": "git_merge_options *", + "cppClassName": "GitMergeOptions" + }, + "checkout_opts": { + "cType": "git_checkout_options *", + "cppClassName": "GitCheckoutOptions" } + }, + "return": { + "isErrorCode": true } }, "git_merge_analysis": { @@ -1659,8 +1682,12 @@ "rebase": { "functions": { "git_rebase_commit": { + "isAsync": true, "args": { "id": { + "cType": "git_oid *", + "cppClassName": "GitOid", + "jsClassName": "Oid", "isReturn": true, "shouldAlloc": true }, @@ -1673,6 +1700,9 @@ "message": { "isOptional": true } + }, + "return": { + "isErrorCode": true } }, "git_rebase_finish": { @@ -1700,6 +1730,22 @@ "isOptional": true } } + }, + "git_rebase_abort": { + "isAsync": true, + "args": { + "rebase": { + "cType": "git_rebase *", + "cppClassName": "GitRebase", + "jsClassName": "Rebase", + "isOptional": false, + "isSelf": true, + "isReturn": false + } + }, + "return": { + "isErrorCode": true + } } } }, @@ -1798,6 +1844,17 @@ "needsForwardDeclaration": false, "ignore": true }, + "reflog": { + "functions": { + "git_reflog_write": { + "isAsync": true, + "isSelf": true, + "return": { + "isErrorCode": true + } + } + } + }, "reflog_entry": { "functions": { "git_reflog_entry_id_new": { @@ -2241,9 +2298,11 @@ "isAsync": false }, "git_status_file": { + "isAsync": true, "args": { "status_flags": { - "isReturn": true + "isReturn": true, + "shouldAlloc": true }, "return": { "isErrorCode": true diff --git a/lib/rebase.js b/lib/rebase.js index 22ca72c7d..28882ea6c 100644 --- a/lib/rebase.js +++ b/lib/rebase.js @@ -5,6 +5,8 @@ var shallowClone = NodeGit.Utils.shallowClone; var _init = Rebase.init; var _open = Rebase.open; +var _abort = Rebase.prototype.abort; +var _commit = Rebase.prototype.commit; /** * Initializes a rebase * @async @@ -83,3 +85,12 @@ Rebase.open = function(repository, options) { ); return _open(repository, options); }; + +Rebase.prototype.commit = function(author, committer, encoding, message) { + return _commit.call(this, author, committer, encoding, message); +}; + +Rebase.prototype.abort = function() { + return _abort.call(this); +}; + diff --git a/lib/repository.js b/lib/repository.js index 90be1d91c..bcf8591c7 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) { @@ -217,23 +217,26 @@ function performRebase( function getPromise() { return rebase.next() .then(function() { - return repository.refreshIndex() - .then(function(index) { - if (index.hasConflicts()) { - throw index; - } + return repository.refreshIndex(); + }) + .then(function(index) { + if (index.hasConflicts()) { + throw index; + } - rebase.commit(null, signature); + return rebase.commit(null, signature); + }) + .then(function() { - return performRebase( - repository, - rebase, - signature, - beforeNextFn, - beforeFinishFn - ); - }); - }, function(error) { + return performRebase( + repository, + rebase, + signature, + beforeNextFn, + beforeFinishFn + ); + }) + .catch(function(error) { if (error && error.errno === NodeGit.Error.CODE.ITEROVER) { const calcRewritten = fp.flow([ fp.split("\n"), @@ -435,6 +438,7 @@ Repository.prototype.continueRebase = function( signature = signature || repo.defaultSignature(); + var rebase; return repo.refreshIndex() .then(function(index) { if (index.hasConflicts()) { @@ -443,9 +447,17 @@ Repository.prototype.continueRebase = function( return NodeGit.Rebase.open(repo); }) - .then(function(rebase) { - rebase.commit(null, signature); - + .then(function(_rebase) { + rebase = _rebase; + return rebase.commit(null, signature) + .catch(function() { + // Ignore all errors to prevent + // this routine from choking now + // that we made rebase.commit + // asynchronous + }); + }) + .then(function() { return performRebase( repo, rebase, @@ -1636,17 +1648,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) { diff --git a/test/tests/merge.js b/test/tests/merge.js index 66728bdb9..86531aa2c 100644 --- a/test/tests/merge.js +++ b/test/tests/merge.js @@ -1539,9 +1539,7 @@ describe("Merge", function() { .then(function(theirAnnotatedCommit) { return NodeGit.Merge(repository, theirAnnotatedCommit); }) - .then(function(result) { - assert.equal(result, 0); - + .then(function() { assert.equal(repository.state(), NodeGit.Repository.STATE.MERGE); // verify the convenience method diff --git a/test/tests/rebase.js b/test/tests/rebase.js index 731884f82..d121a6c0f 100644 --- a/test/tests/rebase.js +++ b/test/tests/rebase.js @@ -658,7 +658,7 @@ describe("Rebase", function() { }); }) .then(function() { - return rebase.abort(ourSignature); + return rebase.abort(); }) .then(function() { return NodeGit.Rebase.open(repository)