Unverified Commit 4d91e113 authored by Tyler Wanek's avatar Tyler Wanek Committed by GitHub

Merge pull request #1404 from rcjsuen/revert-defaults

Generate default options for Revert.revert to prevent an exception
parents 6ff67a88 e8f8141b
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