Commit e8f8141b authored by Remy Suen's avatar Remy Suen

Generate options if unspecified in Revert.revert

Due to the way the C++ binding layer gets the promise callback passed
to it, if there are no options specified in Revert.revert, the
promise callback ends up becoming the third parameter to the function
and the expected fourth parameter will not be satisfied which will
lead to an exception. We should generate a default options for
Revert.revert if nothing is provided by the callee to make the API
easier and simpler to use.
Signed-off-by: default avatarRemy Suen <remy.suen@gmail.com>
parent 6ff67a88
var NodeGit = require("../");
var shallowClone = NodeGit.Utils.shallowClone;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Revert = NodeGit.Revert;
var _commit = Revert.commit;
var _revert = Revert.revert;
/**
* Reverts the given commit against the given "our" commit, producing an index
......@@ -44,3 +46,40 @@ Revert.commit = function(
return result;
}, callback);
};
/**
* Reverts the given commit, producing changes in the index and
* working directory.
*
* @async
* @param {Repository} repo the repository to perform the revert in
* @param {Commit} commit the commit to revert
* @param {RevertOptions} revert_options the revert options
* (or null for defaults)
*/
Revert.revert = function(repo, commit, revertOpts) {
var mergeOpts;
var checkoutOpts;
if (revertOpts) {
revertOpts = shallowClone(revertOpts);
mergeOpts = revertOpts.mergeOpts;
checkoutOpts = revertOpts.checkoutOpts;
delete revertOpts.mergeOpts;
delete revertOpts.checkoutOpts;
}
revertOpts = normalizeOptions(revertOpts, NodeGit.RevertOptions);
if (revertOpts) {
revertOpts.mergeOpts =
normalizeOptions(mergeOpts, NodeGit.MergeOptions);
}
if (checkoutOpts) {
revertOpts.checkoutOpts =
normalizeOptions(checkoutOpts, NodeGit.CheckoutOptions);
}
return _revert.call(this, repo, commit, revertOpts);
};
......@@ -61,7 +61,14 @@ describe("Revert", function() {
});
});
it("RevertOptions is optional", function() {
it("RevertOptions is optional (unspecified)", function() {
return Revert.revert(test.repository, test.firstCommit)
.catch(function(error) {
throw error;
});
});
it("RevertOptions is optional (null)", function() {
return Revert.revert(test.repository, test.firstCommit, null)
.catch(function(error) {
throw error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment