Skip to content

Commit

Permalink
lib/rebase.js: async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
samuela committed Oct 17, 2021
1 parent 7b91482 commit 6aca353
Showing 1 changed file with 30 additions and 38 deletions.
68 changes: 30 additions & 38 deletions lib/rebase.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var NodeGit = require("../");
var Rebase = NodeGit.Rebase;
const NodeGit = require("../");
const Rebase = NodeGit.Rebase;

var _init = Rebase.init;
var _open = Rebase.open;
const _init = Rebase.init;
const _open = Rebase.open;

function defaultRebaseOptions(options, checkoutStrategy) {
if (options) {
// Ensure we don't modify the passed-in options object.
// This could lead to us recursing signingCb if the same
// options object is later re-used.
// Ensure we don't modify the passed-in options object.
// This could lead to us recursing signingCb if the same
// options object is later re-used.
options = Object.assign({}, options);

if (options.signingCb) {
Expand All @@ -19,25 +19,14 @@ function defaultRebaseOptions(options, checkoutStrategy) {
commitContent
) {
try {
const signingCbResult = signingCb(commitContent);

return Promise.resolve(signingCbResult)
.then(function({ code, field, signedData }) {
if (code === NodeGit.Error.CODE.OK) {
signatureBuf.setString(signedData);
if (field) {
signatureFieldBuf.setString(field);
}
}

return code;
})
.catch(function(error) {
if (error && error.code) {
return error.code;
}
return NodeGit.Error.CODE.ERROR;
});
const { code, field, signedData } = signingCb(commitContent);
if (code === NodeGit.Error.CODE.OK) {
signatureBuf.setString(signedData);
if (field) {
signatureFieldBuf.setString(field);
}
}
return code;
} catch (error) {
if (error && error.code) {
return error.code;
Expand All @@ -49,8 +38,8 @@ function defaultRebaseOptions(options, checkoutStrategy) {
} else if (checkoutStrategy) {
options = {
checkoutOptions: {
checkoutStrategy: checkoutStrategy
}
checkoutStrategy: checkoutStrategy,
},
};
}

Expand All @@ -71,11 +60,14 @@ function defaultRebaseOptions(options, checkoutStrategy) {
* or NULL
* @return {Remote}
*/
Rebase.init = function(repository, branch, upstream, onto, options) {
return _init(repository, branch, upstream, onto, defaultRebaseOptions(
options,
NodeGit.Checkout.STRATEGY.FORCE
));
Rebase.init = function (repository, branch, upstream, onto, options) {
return _init(
repository,
branch,
upstream,
onto,
defaultRebaseOptions(options, NodeGit.Checkout.STRATEGY.FORCE)
);
};

/**
Expand All @@ -86,9 +78,9 @@ Rebase.init = function(repository, branch, upstream, onto, options) {
* @param {RebaseOptions} options Options to specify how rebase is performed
* @return {Remote}
*/
Rebase.open = function(repository, options) {
return _open(repository, defaultRebaseOptions(
options,
NodeGit.Checkout.STRATEGY.SAFE
));
Rebase.open = function (repository, options) {
return _open(
repository,
defaultRebaseOptions(options, NodeGit.Checkout.STRATEGY.SAFE)
);
};

0 comments on commit 6aca353

Please sign in to comment.