Skip to content

Commit ab50c82

Browse files
committed
convenience methods for normalizing opts
1 parent da808cb commit ab50c82

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

lib/rebase.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var NodeGit = require("../");
2+
var Rebase = NodeGit.Rebase;
3+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
4+
5+
// Override Rebase.prototype.finish to normalize opts
6+
var finish = Rebase.prototype.finish;
7+
Rebase.prototype.finish = function(signature, opts) {
8+
opts = normalizeOptions(opts || {}, NodeGit.RebaseOptions);
9+
return finish.call(this, signature, opts);
10+
};
11+
12+
// Override Rebase.prototype.next to normalize opts and provide good defaults
13+
var next = Rebase.prototype.next;
14+
Rebase.prototype.next = function(checkoutOpts) {
15+
if (!checkoutOpts) {
16+
checkoutOpts = {
17+
checkoutStrategy: NodeGit.Checkout.STRATEGY.SAFE_CREATE
18+
};
19+
}
20+
21+
checkoutOpts = normalizeOptions(checkoutOpts, NodeGit.CheckoutOptions);
22+
return next.call(this, checkoutOpts);
23+
};

test/tests/rebase.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ describe("Rebase", function() {
314314
// should be 0.
315315
assert.equal(rebase.operationCurrent(), 0);
316316

317-
return rebase.finish(ourSignature, new NodeGit.RebaseOptions());
317+
return rebase.finish(ourSignature, {});
318318
})
319319
.then(function(result) {
320320
assert.equal(result, 0);
@@ -468,10 +468,7 @@ describe("Rebase", function() {
468468
// there should only be 1 rebase operation to perform
469469
assert.equal(rebase.operationEntrycount(), 1);
470470

471-
var opts = new NodeGit.CheckoutOptions();
472-
opts.checkoutStrategy = NodeGit.Checkout.STRATEGY.SAFE_CREATE;
473-
474-
return rebase.next(opts);
471+
return rebase.next();
475472
})
476473
.then(function(rebaseOperation) {
477474
assert.equal(rebaseOperation.type(),
@@ -508,7 +505,7 @@ describe("Rebase", function() {
508505
assert.equal(commitOid.toString(),
509506
"ef6d0e95167435b3d58f51ab165948c72f6f94b6");
510507

511-
return rebase.finish(ourSignature, new NodeGit.RebaseOptions());
508+
return rebase.finish(ourSignature);
512509
})
513510
.then(function(result) {
514511
assert.equal(result, 0);
@@ -660,10 +657,7 @@ describe("Rebase", function() {
660657
// there should only be 1 rebase operation to perform
661658
assert.equal(rebase.operationEntrycount(), 1);
662659

663-
var opts = new NodeGit.CheckoutOptions();
664-
opts.checkoutStrategy = NodeGit.Checkout.STRATEGY.SAFE_CREATE;
665-
666-
return rebase.next(opts);
660+
return rebase.next();
667661
})
668662
.then(function(rebaseOperation) {
669663
assert.equal(rebaseOperation.type(),

0 commit comments

Comments
 (0)