@@ -177,7 +177,6 @@ describe("Rebase", function() {
177177
178178 var repository = this . repository ;
179179 var ourCommit ;
180- var theirCommitOid ;
181180 var ourBranch ;
182181 var theirBranch ;
183182 var rebase ;
@@ -225,11 +224,9 @@ describe("Rebase", function() {
225224 theirSignature , "they made a commit" , oid , [ ourCommit ] ) ;
226225 } )
227226 . then ( function ( commitOid ) {
228- theirCommitOid = commitOid ;
229227 assert . equal ( commitOid . toString ( ) ,
230228 "e9ebd92f2f4778baf6fa8e92f0c68642f931a554" ) ;
231- } )
232- . then ( function ( ) {
229+
233230 return removeFileFromIndex ( repository , theirFileName ) ;
234231 } )
235232 . then ( function ( ) {
@@ -252,8 +249,7 @@ describe("Rebase", function() {
252249 . then ( function ( commitOid ) {
253250 assert . equal ( commitOid . toString ( ) ,
254251 "e7f37ee070837052937e24ad8ba66f6d83ae7941" ) ;
255- } )
256- . then ( function ( ) {
252+
257253 return removeFileFromIndex ( repository , ourFileName ) ;
258254 } )
259255 . then ( function ( ) {
@@ -326,6 +322,7 @@ describe("Rebase", function() {
326322 return repository . getBranchCommit ( ourBranchName ) ;
327323 } )
328324 . then ( function ( commit ) {
325+ // verify that the "ours" branch has moved to the correct place
329326 assert . equal ( commit . id ( ) . toString ( ) ,
330327 "b937100ee0ea17ef20525306763505a7fe2be29e" ) ;
331328
@@ -337,4 +334,198 @@ describe("Rebase", function() {
337334 "e9ebd92f2f4778baf6fa8e92f0c68642f931a554" ) ;
338335 } ) ;
339336 } ) ;
337+
338+ it ( "can rebase 2 branches with conflicts on a single file" , function ( ) {
339+ var fileName = "everyonesFile.txt" ;
340+
341+ var baseFileContent = "How do you feel about Toll Roads?\n" ;
342+ var ourFileContent = "I like Toll Roads. I have an EZ-Pass!\n" ;
343+ var theirFileContent = "I'm skeptical about Toll Roads\n" ;
344+
345+ var expectedConflictedFileContent =
346+ "How do you feel about Toll Roads?\n" +
347+ "<<<<<<< theirs\n" +
348+ "I'm skeptical about Toll Roads\n" +
349+ "=======\n" +
350+ "I like Toll Roads. I have an EZ-Pass!\n" +
351+ ">>>>>>> we made a commit\n" ;
352+
353+ var conflictSolvedFileContent =
354+ "How do you feel about Toll Roads?\n" +
355+ "He's skeptical about Toll Roads,\n" +
356+ "but I like Toll Roads. I have an EZ-Pass!\n" ;
357+
358+ var ourSignature = NodeGit . Signature . create
359+ ( "Ron Paul" , "RonPaul@TollRoadsRBest.info" , 123456789 , 60 ) ;
360+ var theirSignature = NodeGit . Signature . create
361+ ( "Greg Abbott" , "Gregggg@IllTollYourFace.us" , 123456789 , 60 ) ;
362+
363+ var repository = this . repository ;
364+ var ourCommit ;
365+ var ourBranch ;
366+ var theirBranch ;
367+ var rebase ;
368+
369+ return fse . writeFile ( path . join ( repository . workdir ( ) , fileName ) ,
370+ baseFileContent )
371+ . then ( function ( ) {
372+ return addFileToIndex ( repository , fileName ) ;
373+ } )
374+ . then ( function ( oid ) {
375+ assert . equal ( oid . toString ( ) ,
376+ "044704f62399fecbe22da6d7d47b14e52625630e" ) ;
377+
378+ return repository . createCommit ( "HEAD" , ourSignature ,
379+ ourSignature , "initial commit" , oid , [ ] ) ;
380+ } )
381+ . then ( function ( commitOid ) {
382+ assert . equal ( commitOid . toString ( ) ,
383+ "80111c46ac73b857a3493b24c81df08639b5de99" ) ;
384+
385+ return repository . getCommit ( commitOid ) . then ( function ( commit ) {
386+ ourCommit = commit ;
387+ } ) . then ( function ( ) {
388+ return repository . createBranch ( ourBranchName , commitOid )
389+ . then ( function ( branch ) {
390+ ourBranch = branch ;
391+ return repository . createBranch ( theirBranchName , commitOid ) ;
392+ } ) ;
393+ } ) ;
394+ } )
395+ . then ( function ( branch ) {
396+ theirBranch = branch ;
397+ return fse . writeFile ( path . join ( repository . workdir ( ) , fileName ) ,
398+ baseFileContent + theirFileContent ) ;
399+ } )
400+ . then ( function ( ) {
401+ return addFileToIndex ( repository , fileName ) ;
402+ } )
403+ . then ( function ( oid ) {
404+ assert . equal ( oid . toString ( ) ,
405+ "b826e989aca7647bea64810f0a2a38acbbdd4c1a" ) ;
406+
407+ return repository . createCommit ( theirBranch . name ( ) , theirSignature ,
408+ theirSignature , "they made a commit" , oid , [ ourCommit ] ) ;
409+ } )
410+ . then ( function ( commitOid ) {
411+ assert . equal ( commitOid . toString ( ) ,
412+ "b3c355bb606ec7da87174dfa1a0b0c0e3dc97bc0" ) ;
413+
414+ return fse . writeFile ( path . join ( repository . workdir ( ) , fileName ) ,
415+ baseFileContent + ourFileContent ) ;
416+ } )
417+ . then ( function ( ) {
418+ return addFileToIndex ( repository , fileName ) ;
419+ } )
420+ . then ( function ( oid ) {
421+ assert . equal ( oid . toString ( ) ,
422+ "e7fe41bf7c0c28766887a63ffe2f03f624276fbe" ) ;
423+
424+ return repository . createCommit ( ourBranch . name ( ) , ourSignature ,
425+ ourSignature , "we made a commit" , oid , [ ourCommit ] ) ;
426+ } )
427+ . then ( function ( commitOid ) {
428+ assert . equal ( commitOid . toString ( ) ,
429+ "28cfeb17f66132edb3c4dacb7ff38e8dd48a1844" ) ;
430+
431+ var opts = {
432+ checkoutStrategy : NodeGit . Checkout . STRATEGY . FORCE
433+ } ;
434+
435+ return NodeGit . Checkout . head ( repository , opts ) ;
436+ } )
437+ . then ( function ( ) {
438+ return Promise . all ( [
439+ repository . getReference ( ourBranchName ) ,
440+ repository . getReference ( theirBranchName )
441+ ] ) ;
442+ } )
443+ . then ( function ( refs ) {
444+ assert . equal ( refs . length , 2 ) ;
445+
446+ return Promise . all ( [
447+ NodeGit . AnnotatedCommit . fromRef ( repository , refs [ 0 ] ) ,
448+ NodeGit . AnnotatedCommit . fromRef ( repository , refs [ 1 ] )
449+ ] ) ;
450+ } )
451+ . then ( function ( annotatedCommits ) {
452+ assert . equal ( annotatedCommits . length , 2 ) ;
453+
454+ var ourAnnotatedCommit = annotatedCommits [ 0 ] ;
455+ var theirAnnotatedCommit = annotatedCommits [ 1 ] ;
456+
457+ assert . equal ( ourAnnotatedCommit . id ( ) . toString ( ) ,
458+ "28cfeb17f66132edb3c4dacb7ff38e8dd48a1844" ) ;
459+ assert . equal ( theirAnnotatedCommit . id ( ) . toString ( ) ,
460+ "b3c355bb606ec7da87174dfa1a0b0c0e3dc97bc0" ) ;
461+
462+ return NodeGit . Rebase . init ( repository , ourAnnotatedCommit ,
463+ theirAnnotatedCommit , null , ourSignature , null ) ;
464+ } )
465+ . then ( function ( newRebase ) {
466+ rebase = newRebase ;
467+
468+ // there should only be 1 rebase operation to perform
469+ assert . equal ( rebase . operationEntrycount ( ) , 1 ) ;
470+
471+ var opts = new NodeGit . CheckoutOptions ( ) ;
472+ opts . checkoutStrategy = NodeGit . Checkout . STRATEGY . SAFE_CREATE ;
473+
474+ return rebase . next ( opts ) ;
475+ } )
476+ . then ( function ( rebaseOperation ) {
477+ assert . equal ( rebaseOperation . type ( ) ,
478+ NodeGit . RebaseOperation . REBASE_OPERATION . PICK ) ;
479+ assert . equal ( rebaseOperation . id ( ) . toString ( ) ,
480+ "28cfeb17f66132edb3c4dacb7ff38e8dd48a1844" ) ;
481+
482+ return repository . openIndex ( )
483+ . then ( function ( index ) {
484+ assert . ok ( index . hasConflicts ( ) ) ;
485+ } ) ;
486+ } )
487+ . then ( function ( ) {
488+ return fse . readFile ( path . join ( repository . workdir ( ) , fileName ) , "utf8" )
489+ . then ( function ( fileContent ) {
490+ assert . equal ( fileContent , expectedConflictedFileContent ) ;
491+
492+ return fse . writeFile ( path . join ( repository . workdir ( ) , fileName ) ,
493+ conflictSolvedFileContent ) ;
494+ } ) ;
495+ } )
496+ . then ( function ( ) {
497+ return addFileToIndex ( repository , fileName ) ;
498+ } )
499+ . then ( function ( oid ) {
500+ return repository . openIndex ( )
501+ . then ( function ( index ) {
502+ assert . ok ( ! index . hasConflicts ( ) ) ;
503+
504+ return rebase . commit ( null , ourSignature ) ;
505+ } ) ;
506+ } )
507+ . then ( function ( commitOid ) {
508+ assert . equal ( commitOid . toString ( ) ,
509+ "ef6d0e95167435b3d58f51ab165948c72f6f94b6" ) ;
510+
511+ return rebase . finish ( ourSignature , new NodeGit . RebaseOptions ( ) ) ;
512+ } )
513+ . then ( function ( result ) {
514+ assert . equal ( result , 0 ) ;
515+
516+ return repository . getBranchCommit ( ourBranchName ) ;
517+ } )
518+ . then ( function ( commit ) {
519+ // verify that the "ours" branch has moved to the correct place
520+ assert . equal ( commit . id ( ) . toString ( ) ,
521+ "ef6d0e95167435b3d58f51ab165948c72f6f94b6" ) ;
522+
523+ return commit . parent ( 0 ) ;
524+ } )
525+ . then ( function ( commit ) {
526+ // verify that we are on top of "their commit"
527+ assert . equal ( commit . id ( ) . toString ( ) ,
528+ "b3c355bb606ec7da87174dfa1a0b0c0e3dc97bc0" ) ;
529+ } ) ;
530+ } ) ;
340531} ) ;
0 commit comments