@@ -149,7 +149,7 @@ describe("Rebase", function() {
149149 } ) ;
150150 } ) ;
151151
152- it ( "can cleanly rebase a branch onto another branch " , function ( ) {
152+ it ( "can cleanly rebase a branch in-memory " , function ( ) {
153153 var baseFileName = "baseNewFile.txt" ;
154154 var ourFileName = "ourNewFile.txt" ;
155155 var theirFileName = "theirNewFile.txt" ;
@@ -266,6 +266,187 @@ describe("Rebase", function() {
266266 var ourAnnotatedCommit = annotatedCommits [ 0 ] ;
267267 var theirAnnotatedCommit = annotatedCommits [ 1 ] ;
268268
269+ assert . equal ( ourAnnotatedCommit . id ( ) . toString ( ) ,
270+ "e7f37ee070837052937e24ad8ba66f6d83ae7941" ) ;
271+ assert . equal ( theirAnnotatedCommit . id ( ) . toString ( ) ,
272+ "e9ebd92f2f4778baf6fa8e92f0c68642f931a554" ) ;
273+
274+ var rebaseOptions = new NodeGit . RebaseOptions ( ) ;
275+ rebaseOptions . inmemory = 1 ;
276+
277+ return NodeGit . Rebase . init ( repository , ourAnnotatedCommit ,
278+ theirAnnotatedCommit , undefined , rebaseOptions ) ;
279+ } )
280+ . then ( function ( newRebase ) {
281+ rebase = newRebase ;
282+
283+ // there should only be 1 rebase operation to perform
284+ assert . equal ( rebase . operationEntrycount ( ) , 1 ) ;
285+
286+ return rebase . next ( ) ;
287+ } )
288+ . then ( function ( rebaseOperation ) {
289+ assert . equal ( rebaseOperation . type ( ) ,
290+ NodeGit . RebaseOperation . REBASE_OPERATION . PICK ) ;
291+ assert . equal ( rebaseOperation . id ( ) . toString ( ) ,
292+ "e7f37ee070837052937e24ad8ba66f6d83ae7941" ) ;
293+
294+ return rebase . commit ( null , ourSignature ) ;
295+ } )
296+ . then ( function ( commitOid ) {
297+ assert . equal ( commitOid . toString ( ) ,
298+ "b937100ee0ea17ef20525306763505a7fe2be29e" ) ;
299+
300+ // git_rebase_operation_current returns the index of the rebase
301+ // operation that was last applied, so after the first operation, it
302+ // should be 0.
303+ assert . equal ( rebase . operationCurrent ( ) , 0 ) ;
304+
305+ return rebase . finish ( ourSignature , { } ) ;
306+ } )
307+ . then ( function ( result ) {
308+ assert . equal ( result , 0 ) ;
309+
310+ return repository . getBranchCommit ( ourBranchName ) ;
311+ } )
312+ . then ( function ( commit ) {
313+ // verify that the "ours" branch has NOT moved.
314+ // In-memory rebase does not touch refs.
315+ assert . equal ( commit . id ( ) . toString ( ) ,
316+ "e7f37ee070837052937e24ad8ba66f6d83ae7941" ) ;
317+
318+ // Lookup the new commit
319+ return NodeGit . Commit . lookup ( repository ,
320+ "b937100ee0ea17ef20525306763505a7fe2be29e" ) ;
321+ } )
322+ . then ( function ( commit ) {
323+ // Lookup the parent of our new commit
324+ return commit . parent ( 0 ) ;
325+ } )
326+ . then ( function ( commit ) {
327+ // verify that we are on top of "their commit"
328+ assert . equal ( commit . id ( ) . toString ( ) ,
329+ "e9ebd92f2f4778baf6fa8e92f0c68642f931a554" ) ;
330+ } ) ;
331+ } ) ;
332+
333+ it ( "can cleanly rebase a branch onto another branch" , function ( ) {
334+ var baseFileName = "baseNewFile.txt" ;
335+ var ourFileName = "ourNewFile.txt" ;
336+ var theirFileName = "theirNewFile.txt" ;
337+
338+ var baseFileContent = "How do you feel about Toll Roads?" ;
339+ var ourFileContent = "I like Toll Roads. I have an EZ-Pass!" ;
340+ var theirFileContent = "I'm skeptical about Toll Roads" ;
341+
342+ var ourSignature = NodeGit . Signature . create
343+ ( "Ron Paul" , "RonPaul@TollRoadsRBest.info" , 123456789 , 60 ) ;
344+ var theirSignature = NodeGit . Signature . create
345+ ( "Greg Abbott" , "Gregggg@IllTollYourFace.us" , 123456789 , 60 ) ;
346+
347+ var repository = this . repository ;
348+ var ourCommit ;
349+ var ourBranch ;
350+ var theirBranch ;
351+ var rebase ;
352+
353+ return fse . writeFile ( path . join ( repository . workdir ( ) , baseFileName ) ,
354+ baseFileContent )
355+ // Load up the repository index and make our initial commit to HEAD
356+ . then ( function ( ) {
357+ return RepoUtils . addFileToIndex ( repository , baseFileName ) ;
358+ } )
359+ . then ( function ( oid ) {
360+ assert . equal ( oid . toString ( ) ,
361+ "b5cdc109d437c4541a13fb7509116b5f03d5039a" ) ;
362+
363+ return repository . createCommit ( "HEAD" , ourSignature ,
364+ ourSignature , "initial commit" , oid , [ ] ) ;
365+ } )
366+ . then ( function ( commitOid ) {
367+ assert . equal ( commitOid . toString ( ) ,
368+ "be03abdf0353d05924c53bebeb0e5bb129cda44a" ) ;
369+
370+ return repository . getCommit ( commitOid ) . then ( function ( commit ) {
371+ ourCommit = commit ;
372+ } ) . then ( function ( ) {
373+ return repository . createBranch ( ourBranchName , commitOid )
374+ . then ( function ( branch ) {
375+ ourBranch = branch ;
376+ return repository . createBranch ( theirBranchName , commitOid ) ;
377+ } ) ;
378+ } ) ;
379+ } )
380+ . then ( function ( branch ) {
381+ theirBranch = branch ;
382+ return fse . writeFile ( path . join ( repository . workdir ( ) , theirFileName ) ,
383+ theirFileContent ) ;
384+ } )
385+ . then ( function ( ) {
386+ return RepoUtils . addFileToIndex ( repository , theirFileName ) ;
387+ } )
388+ . then ( function ( oid ) {
389+ assert . equal ( oid . toString ( ) ,
390+ "be5f0fd38a39a67135ad68921c93cd5c17fefb3d" ) ;
391+
392+ return repository . createCommit ( theirBranch . name ( ) , theirSignature ,
393+ theirSignature , "they made a commit" , oid , [ ourCommit ] ) ;
394+ } )
395+ . then ( function ( commitOid ) {
396+ assert . equal ( commitOid . toString ( ) ,
397+ "e9ebd92f2f4778baf6fa8e92f0c68642f931a554" ) ;
398+
399+ return removeFileFromIndex ( repository , theirFileName ) ;
400+ } )
401+ . then ( function ( ) {
402+ return fse . remove ( path . join ( repository . workdir ( ) , theirFileName ) ) ;
403+ } )
404+ . then ( function ( ) {
405+ return fse . writeFile ( path . join ( repository . workdir ( ) , ourFileName ) ,
406+ ourFileContent ) ;
407+ } )
408+ . then ( function ( ) {
409+ return RepoUtils . addFileToIndex ( repository , ourFileName ) ;
410+ } )
411+ . then ( function ( oid ) {
412+ assert . equal ( oid . toString ( ) ,
413+ "77867fc0bfeb3f80ab18a78c8d53aa3a06207047" ) ;
414+
415+ return repository . createCommit ( ourBranch . name ( ) , ourSignature ,
416+ ourSignature , "we made a commit" , oid , [ ourCommit ] ) ;
417+ } )
418+ . then ( function ( commitOid ) {
419+ assert . equal ( commitOid . toString ( ) ,
420+ "e7f37ee070837052937e24ad8ba66f6d83ae7941" ) ;
421+
422+ return removeFileFromIndex ( repository , ourFileName ) ;
423+ } )
424+ . then ( function ( ) {
425+ return fse . remove ( path . join ( repository . workdir ( ) , ourFileName ) ) ;
426+ } )
427+ . then ( function ( ) {
428+ return repository . checkoutBranch ( ourBranchName ) ;
429+ } )
430+ . then ( function ( ) {
431+ return Promise . all ( [
432+ repository . getReference ( ourBranchName ) ,
433+ repository . getReference ( theirBranchName )
434+ ] ) ;
435+ } )
436+ . then ( function ( refs ) {
437+ assert . equal ( refs . length , 2 ) ;
438+
439+ return Promise . all ( [
440+ NodeGit . AnnotatedCommit . fromRef ( repository , refs [ 0 ] ) ,
441+ NodeGit . AnnotatedCommit . fromRef ( repository , refs [ 1 ] )
442+ ] ) ;
443+ } )
444+ . then ( function ( annotatedCommits ) {
445+ assert . equal ( annotatedCommits . length , 2 ) ;
446+
447+ var ourAnnotatedCommit = annotatedCommits [ 0 ] ;
448+ var theirAnnotatedCommit = annotatedCommits [ 1 ] ;
449+
269450 assert . equal ( ourAnnotatedCommit . id ( ) . toString ( ) ,
270451 "e7f37ee070837052937e24ad8ba66f6d83ae7941" ) ;
271452 assert . equal ( theirAnnotatedCommit . id ( ) . toString ( ) ,
0 commit comments