@@ -6,6 +6,8 @@ var fse = promisify(require("fs-extra"));
66
77describe ( "Rebase" , function ( ) {
88 var NodeGit = require ( "../../" ) ;
9+ var Checkout = NodeGit . Checkout ;
10+ var Merge = NodeGit . Merge ;
911 var RepoUtils = require ( "../utils/repository_setup" ) ;
1012
1113 var repoPath = local ( "../repos/rebase" ) ;
@@ -790,6 +792,168 @@ describe("Rebase", function() {
790792 } ) ;
791793 } ) ;
792794
795+ it (
796+ "can fast-forward a merge commit via rebase using the " +
797+ "convenience methods that has a beforeFinishFn" ,
798+ function ( ) {
799+ var ourFileName = "ourNewFile.txt" ;
800+ var theirFileName = "theirNewFile.txt" ;
801+ var theirOtherFileName = "antherNewFile.txt" ;
802+
803+ var ourFileContent = "I like Toll Roads. I have an EZ-Pass!" ;
804+ var theirFileContent = "I'm skeptical about Toll Roads" ;
805+ var theirOtherFileContent = "This is some more content, guys!" ;
806+
807+ var ourSignature = NodeGit . Signature . create
808+ ( "Ron Paul" , "RonPaul@TollRoadsRBest.info" , 123456789 , 60 ) ;
809+ var theirSignature = NodeGit . Signature . create
810+ ( "Greg Abbott" , "Gregggg@IllTollYourFace.us" , 123456789 , 60 ) ;
811+ var theirOtherSignature = NodeGit . Signature . create
812+ ( "Greg Abbott" , "Gregggg@IllTollYourFace.us" , 123456999 , 60 ) ;
813+ var ourMergeSignature = NodeGit . Signature . create
814+ ( "Ron Paul" , "RonPaul@TollRoadsRBest.info" , 123456889 , 60 ) ;
815+
816+ var repository = this . repository ;
817+ var ourCommit ;
818+ var theirCommit ;
819+ var theirBranch ;
820+ var ourBranch ;
821+
822+ return fse . writeFile ( path . join ( repository . workdir ( ) , ourFileName ) ,
823+ ourFileContent )
824+ // Load up the repository index and make our initial commit to HEAD
825+ . then ( function ( ) {
826+ return RepoUtils . addFileToIndex ( repository , ourFileName ) ;
827+ } )
828+ . then ( function ( oid ) {
829+ assert . equal ( oid . toString ( ) ,
830+ "11ead82b1135b8e240fb5d61e703312fb9cc3d6a" ) ;
831+
832+ return repository . createCommit ( "HEAD" , ourSignature ,
833+ ourSignature , "we made a commit" , oid , [ ] ) ;
834+ } )
835+ . then ( function ( commitOid ) {
836+ assert . equal ( commitOid . toString ( ) ,
837+ "91a183f87842ebb7a9b08dad8bc2473985796844" ) ;
838+
839+ return repository . getCommit ( commitOid ) . then ( function ( commit ) {
840+ ourCommit = commit ;
841+ } ) . then ( function ( ) {
842+ return repository . createBranch ( ourBranchName , commitOid )
843+ . then ( function ( branch ) {
844+ ourBranch = branch ;
845+ return repository . createBranch ( theirBranchName , commitOid ) ;
846+ } ) ;
847+ } ) ;
848+ } )
849+ . then ( function ( branch ) {
850+ theirBranch = branch ;
851+ return fse . writeFile ( path . join ( repository . workdir ( ) , theirFileName ) ,
852+ theirFileContent ) ;
853+ } )
854+ . then ( function ( ) {
855+ return RepoUtils . addFileToIndex ( repository , theirFileName ) ;
856+ } )
857+ . then ( function ( oid ) {
858+ assert . equal ( oid . toString ( ) ,
859+ "76631cb5a290dafe2959152626bb90f2a6d8ec94" ) ;
860+
861+ return repository . createCommit ( theirBranch . name ( ) , theirSignature ,
862+ theirSignature , "they made a commit" , oid , [ ourCommit ] ) ;
863+ } )
864+ . then ( function ( commitOid ) {
865+ theirCommit = commitOid ;
866+ assert . equal ( commitOid . toString ( ) ,
867+ "0e9231d489b3f4303635fc4b0397830da095e7e7" ) ;
868+ } )
869+ . then ( function ( ) {
870+ return repository . checkoutBranch (
871+ ourBranch ,
872+ { checkoutStrategy : Checkout . STRATEGY . FORCE }
873+ ) ;
874+ } )
875+ . then ( function ( ) {
876+ return repository . mergeBranches (
877+ ourBranchName ,
878+ theirBranchName ,
879+ ourMergeSignature ,
880+ Merge . PREFERENCE . NO_FASTFORWARD
881+ ) ;
882+ } )
883+ . then ( function ( ) {
884+ return repository . getHeadCommit ( ) ;
885+ } )
886+ . then ( function ( headCommit ) {
887+ assert . notEqual ( ourCommit . id ( ) . toString ( ) , headCommit . id ( ) . toString ( ) ) ;
888+ } )
889+ . then ( function ( ) {
890+ return repository . checkoutBranch (
891+ theirBranch ,
892+ { checkoutStrategy : Checkout . STRATEGY . FORCE }
893+ ) ;
894+ } )
895+ . then ( function ( ) {
896+ return fse . writeFile (
897+ path . join ( repository . workdir ( ) , theirOtherFileName ) ,
898+ theirOtherFileContent
899+ ) ;
900+ } )
901+ . then ( function ( ) {
902+ return RepoUtils . addFileToIndex ( repository , theirOtherFileName ) ;
903+ } )
904+ . then ( function ( oid ) {
905+ assert . equal ( oid . toString ( ) ,
906+ "c242b53f2c9446544cf9bdac7e8ed6ce583226cb" ) ;
907+
908+ return repository . createCommit ( theirBranch . name ( ) , theirOtherSignature ,
909+ theirOtherSignature , "they made another commit" , oid , [ theirCommit ] ) ;
910+ } )
911+ . then ( function ( commitOid ) {
912+ assert . equal ( commitOid . toString ( ) ,
913+ "8fa0ce25a2accf464b004ddeeb63add7b816b627" ) ;
914+ } )
915+ . then ( function ( ) {
916+ return Promise . all ( [
917+ repository . getReference ( ourBranchName ) ,
918+ repository . getReference ( theirBranchName )
919+ ] ) ;
920+ } )
921+ . then ( function ( refs ) {
922+ assert . equal ( refs . length , 2 ) ;
923+
924+ return Promise . all ( [
925+ NodeGit . AnnotatedCommit . fromRef ( repository , refs [ 0 ] ) ,
926+ NodeGit . AnnotatedCommit . fromRef ( repository , refs [ 1 ] )
927+ ] ) ;
928+ } )
929+ . then ( function ( annotatedCommits ) {
930+ assert . equal ( annotatedCommits . length , 2 ) ;
931+
932+ var ourAnnotatedCommit = annotatedCommits [ 0 ] ;
933+ var theirAnnotatedCommit = annotatedCommits [ 1 ] ;
934+
935+ assert . equal ( ourAnnotatedCommit . id ( ) . toString ( ) ,
936+ "0d1d322b59df68bac6eea6a2a189f974cb590368" ) ;
937+ assert . equal ( theirAnnotatedCommit . id ( ) . toString ( ) ,
938+ "8fa0ce25a2accf464b004ddeeb63add7b816b627" ) ;
939+
940+ return repository . rebaseBranches (
941+ ourBranchName ,
942+ theirBranchName ,
943+ null ,
944+ ourSignature ,
945+ null ,
946+ function ( rebaseData ) {
947+ assert . equal ( rebaseData . rewritten , null ) ;
948+ }
949+ ) ;
950+ } )
951+ . then ( function ( commit ) {
952+ assert . equal ( commit . id ( ) . toString ( ) ,
953+ "8fa0ce25a2accf464b004ddeeb63add7b816b627" ) ;
954+ } ) ;
955+ } ) ;
956+
793957 it ( "can rebase using the convenience method" , function ( ) {
794958 var baseFileName = "baseNewFile.txt" ;
795959 var ourFileName = "ourNewFile.txt" ;
0 commit comments