Skip to content

Commit 4ed584d

Browse files
committed
test: abort rebase
1 parent 889025d commit 4ed584d

1 file changed

Lines changed: 184 additions & 0 deletions

File tree

test/tests/rebase.js

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,4 +528,188 @@ describe("Rebase", function() {
528528
"b3c355bb606ec7da87174dfa1a0b0c0e3dc97bc0");
529529
});
530530
});
531+
532+
it("can abort an in-progress rebase", function() {
533+
var baseFileName = "baseNewFile.txt";
534+
var ourFileName = "ourNewFile.txt";
535+
var theirFileName = "theirNewFile.txt";
536+
537+
var baseFileContent = "How do you feel about Toll Roads?";
538+
var ourFileContent = "I like Toll Roads. I have an EZ-Pass!";
539+
var theirFileContent = "I'm skeptical about Toll Roads";
540+
541+
var ourSignature = NodeGit.Signature.create
542+
("Ron Paul", "RonPaul@TollRoadsRBest.info", 123456789, 60);
543+
var theirSignature = NodeGit.Signature.create
544+
("Greg Abbott", "Gregggg@IllTollYourFace.us", 123456789, 60);
545+
546+
var repository = this.repository;
547+
var ourCommit;
548+
var ourBranch;
549+
var theirBranch;
550+
var rebase;
551+
552+
return fse.writeFile(path.join(repository.workdir(), baseFileName),
553+
baseFileContent)
554+
// Load up the repository index and make our initial commit to HEAD
555+
.then(function() {
556+
return addFileToIndex(repository, baseFileName);
557+
})
558+
.then(function(oid) {
559+
assert.equal(oid.toString(),
560+
"b5cdc109d437c4541a13fb7509116b5f03d5039a");
561+
562+
return repository.createCommit("HEAD", ourSignature,
563+
ourSignature, "initial commit", oid, []);
564+
})
565+
.then(function(commitOid) {
566+
assert.equal(commitOid.toString(),
567+
"be03abdf0353d05924c53bebeb0e5bb129cda44a");
568+
569+
return repository.getCommit(commitOid).then(function(commit) {
570+
ourCommit = commit;
571+
}).then(function() {
572+
return repository.createBranch(ourBranchName, commitOid)
573+
.then(function(branch) {
574+
ourBranch = branch;
575+
return repository.createBranch(theirBranchName, commitOid);
576+
});
577+
});
578+
})
579+
.then(function(branch) {
580+
theirBranch = branch;
581+
return fse.writeFile(path.join(repository.workdir(), theirFileName),
582+
theirFileContent);
583+
})
584+
.then(function() {
585+
return addFileToIndex(repository, theirFileName);
586+
})
587+
.then(function(oid) {
588+
assert.equal(oid.toString(),
589+
"be5f0fd38a39a67135ad68921c93cd5c17fefb3d");
590+
591+
return repository.createCommit(theirBranch.name(), theirSignature,
592+
theirSignature, "they made a commit", oid, [ourCommit]);
593+
})
594+
.then(function(commitOid) {
595+
assert.equal(commitOid.toString(),
596+
"e9ebd92f2f4778baf6fa8e92f0c68642f931a554");
597+
598+
return removeFileFromIndex(repository, theirFileName);
599+
})
600+
.then(function() {
601+
return fse.remove(path.join(repository.workdir(), theirFileName));
602+
})
603+
.then(function() {
604+
return fse.writeFile(path.join(repository.workdir(), ourFileName),
605+
ourFileContent);
606+
})
607+
.then(function() {
608+
return addFileToIndex(repository, ourFileName);
609+
})
610+
.then(function(oid) {
611+
assert.equal(oid.toString(),
612+
"77867fc0bfeb3f80ab18a78c8d53aa3a06207047");
613+
614+
return repository.createCommit(ourBranch.name(), ourSignature,
615+
ourSignature, "we made a commit", oid, [ourCommit]);
616+
})
617+
.then(function(commitOid) {
618+
assert.equal(commitOid.toString(),
619+
"e7f37ee070837052937e24ad8ba66f6d83ae7941");
620+
621+
return removeFileFromIndex(repository, ourFileName);
622+
})
623+
.then(function() {
624+
return fse.remove(path.join(repository.workdir(), ourFileName));
625+
})
626+
.then(function() {
627+
return repository.checkoutBranch(ourBranchName);
628+
})
629+
.then(function() {
630+
return Promise.all([
631+
repository.getReference(ourBranchName),
632+
repository.getReference(theirBranchName)
633+
]);
634+
})
635+
.then(function(refs) {
636+
assert.equal(refs.length, 2);
637+
638+
return Promise.all([
639+
NodeGit.AnnotatedCommit.fromRef(repository, refs[0]),
640+
NodeGit.AnnotatedCommit.fromRef(repository, refs[1])
641+
]);
642+
})
643+
.then(function(annotatedCommits) {
644+
assert.equal(annotatedCommits.length, 2);
645+
646+
var ourAnnotatedCommit = annotatedCommits[0];
647+
var theirAnnotatedCommit = annotatedCommits[1];
648+
649+
assert.equal(ourAnnotatedCommit.id().toString(),
650+
"e7f37ee070837052937e24ad8ba66f6d83ae7941");
651+
assert.equal(theirAnnotatedCommit.id().toString(),
652+
"e9ebd92f2f4778baf6fa8e92f0c68642f931a554");
653+
654+
return NodeGit.Rebase.init(repository, ourAnnotatedCommit,
655+
theirAnnotatedCommit, null, ourSignature, null);
656+
})
657+
.then(function(newRebase) {
658+
rebase = newRebase;
659+
660+
// there should only be 1 rebase operation to perform
661+
assert.equal(rebase.operationEntrycount(), 1);
662+
663+
var opts = new NodeGit.CheckoutOptions();
664+
opts.checkoutStrategy = NodeGit.Checkout.STRATEGY.SAFE_CREATE;
665+
666+
return rebase.next(opts);
667+
})
668+
.then(function(rebaseOperation) {
669+
assert.equal(rebaseOperation.type(),
670+
NodeGit.RebaseOperation.REBASE_OPERATION.PICK);
671+
assert.equal(rebaseOperation.id().toString(),
672+
"e7f37ee070837052937e24ad8ba66f6d83ae7941");
673+
674+
return rebase.commit(null, ourSignature);
675+
})
676+
.then(function(commitOid) {
677+
assert.equal(commitOid.toString(),
678+
"b937100ee0ea17ef20525306763505a7fe2be29e");
679+
680+
return repository.getBranchCommit("HEAD")
681+
.then(function(commit) {
682+
// verify that HEAD is on the rebased commit
683+
assert.equal(commit.id().toString(), commitOid.toString());
684+
});
685+
})
686+
.then(function() {
687+
return rebase.abort(ourSignature);
688+
})
689+
.then(function() {
690+
return NodeGit.Rebase.open(repository)
691+
.then(function(existingRebase) {
692+
assert.fail(existingRebase, undefined,
693+
"There should not be a rebase in progress");
694+
})
695+
.catch(function(e) {
696+
assert.equal(e.message, "There is no rebase in progress");
697+
});
698+
})
699+
.then(function() {
700+
return Promise.all([
701+
repository.getBranchCommit("HEAD"),
702+
repository.getBranchCommit(ourBranchName)
703+
]);
704+
})
705+
.then(function(commits) {
706+
assert.equal(commits.length, 2);
707+
708+
// verify that 'HEAD' and 'ours' are back to their pre-rebase state
709+
assert.equal(commits[0].id().toString(),
710+
"e7f37ee070837052937e24ad8ba66f6d83ae7941");
711+
assert.equal(commits[1].id().toString(),
712+
"e7f37ee070837052937e24ad8ba66f6d83ae7941");
713+
});
714+
});
531715
});

0 commit comments

Comments
 (0)