@ -405,13 +405,14 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
. call ( ) ;
. call ( ) ;
} catch ( StashApplyFailureException e ) {
} catch ( StashApplyFailureException e ) {
conflicts = true ;
conflicts = true ;
RevWalk rw = new RevWalk ( repo ) ;
try ( RevWalk rw = new RevWalk ( repo ) ) {
ObjectId stashId = repo . resolve ( stash ) ;
ObjectId stashId = repo . resolve ( stash ) ;
RevCommit commit = rw . parseCommit ( stashId ) ;
RevCommit commit = rw . parseCommit ( stashId ) ;
updateStashRef ( commit , commit . getAuthorIdent ( ) ,
updateStashRef ( commit , commit . getAuthorIdent ( ) ,
commit . getShortMessage ( ) ) ;
commit . getShortMessage ( ) ) ;
}
}
}
}
}
return conflicts ;
return conflicts ;
}
}
@ -518,15 +519,16 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
// here we should skip this step in order to avoid
// here we should skip this step in order to avoid
// confusing pseudo-changed
// confusing pseudo-changed
String ourCommitName = getOurCommitName ( ) ;
String ourCommitName = getOurCommitName ( ) ;
CherryPickResult cherryPickResult = new Git ( repo ) . cherryPick ( )
try ( Git git = new Git ( repo ) ) {
CherryPickResult cherryPickResult = git . cherryPick ( )
. include ( commitToPick ) . setOurCommitName ( ourCommitName )
. include ( commitToPick ) . setOurCommitName ( ourCommitName )
. setReflogPrefix ( REFLOG_PREFIX ) . setStrategy ( strategy )
. setReflogPrefix ( REFLOG_PREFIX ) . setStrategy ( strategy )
. call ( ) ;
. call ( ) ;
switch ( cherryPickResult . getStatus ( ) ) {
switch ( cherryPickResult . getStatus ( ) ) {
case FAILED :
case FAILED :
if ( operation = = Operation . BEGIN )
if ( operation = = Operation . BEGIN )
return abort ( RebaseResult . failed ( cherryPick Result
return abort ( RebaseResult
. getFailingPaths ( ) ) ) ;
. failed ( cherryPickResult . getFailingPaths ( ) ) ) ;
else
else
return stop ( commitToPick , Status . STOPPED ) ;
return stop ( commitToPick , Status . STOPPED ) ;
case CONFLICTING :
case CONFLICTING :
@ -535,6 +537,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
newHead = cherryPickResult . getNewHead ( ) ;
newHead = cherryPickResult . getNewHead ( ) ;
}
}
}
}
}
return null ;
return null ;
}
}
@ -563,12 +566,15 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
// Use the cherry-pick strategy if all non-first parents did not
// Use the cherry-pick strategy if all non-first parents did not
// change. This is different from C Git, which always uses the merge
// change. This is different from C Git, which always uses the merge
// strategy (see below).
// strategy (see below).
try ( Git git = new Git ( repo ) ) {
if ( otherParentsUnchanged ) {
if ( otherParentsUnchanged ) {
boolean isMerge = commitToPick . getParentCount ( ) > 1 ;
boolean isMerge = commitToPick . getParentCount ( ) > 1 ;
String ourCommitName = getOurCommitName ( ) ;
String ourCommitName = getOurCommitName ( ) ;
CherryPickCommand pickCommand = new Git ( repo ) . cherryPick ( )
CherryPickCommand pickCommand = git . cherryPick ( )
. include ( commitToPick ) . setOurCommitName ( ourCommitName )
. include ( commitToPick )
. setReflogPrefix ( REFLOG_PREFIX ) . setStrategy ( strategy ) ;
. setOurCommitName ( ourCommitName )
. setReflogPrefix ( REFLOG_PREFIX )
. setStrategy ( strategy ) ;
if ( isMerge ) {
if ( isMerge ) {
pickCommand . setMainlineParentNumber ( 1 ) ;
pickCommand . setMainlineParentNumber ( 1 ) ;
// We write a MERGE_HEAD and later commit explicitly
// We write a MERGE_HEAD and later commit explicitly
@ -579,16 +585,17 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
switch ( cherryPickResult . getStatus ( ) ) {
switch ( cherryPickResult . getStatus ( ) ) {
case FAILED :
case FAILED :
if ( operation = = Operation . BEGIN )
if ( operation = = Operation . BEGIN )
return abort ( RebaseResult . failed ( cherryPickResult
return abort ( RebaseResult . failed (
. getFailingPaths ( ) ) ) ;
cherryPickResult . getFailingPaths ( ) ) ) ;
else
else
return stop ( commitToPick , Status . STOPPED ) ;
return stop ( commitToPick , Status . STOPPED ) ;
case CONFLICTING :
case CONFLICTING :
return stop ( commitToPick , Status . STOPPED ) ;
return stop ( commitToPick , Status . STOPPED ) ;
case OK :
case OK :
if ( isMerge ) {
if ( isMerge ) {
// Commit the merge (setup above using writeMergeInfo())
// Commit the merge (setup above using
CommitCommand commit = new Git ( repo ) . commit ( ) ;
// writeMergeInfo())
CommitCommand commit = git . commit ( ) ;
commit . setAuthor ( commitToPick . getAuthorIdent ( ) ) ;
commit . setAuthor ( commitToPick . getAuthorIdent ( ) ) ;
commit . setReflogComment ( REFLOG_PREFIX + " " //$NON-NLS-1$
commit . setReflogComment ( REFLOG_PREFIX + " " //$NON-NLS-1$
+ commitToPick . getShortMessage ( ) ) ;
+ commitToPick . getShortMessage ( ) ) ;
@ -600,28 +607,29 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
} else {
} else {
// Use the merge strategy to redo merges, which had some of
// Use the merge strategy to redo merges, which had some of
// their non-first parents rewritten
// their non-first parents rewritten
MergeCommand merge = new Git ( repo ) . merge ( )
MergeCommand merge = git . merge ( )
. setFastForward ( MergeCommand . FastForwardMode . NO_FF )
. setFastForward ( MergeCommand . FastForwardMode . NO_FF )
. setCommit ( false ) ;
. setCommit ( false ) ;
for ( int i = 1 ; i < commitToPick . getParentCount ( ) ; i + + )
for ( int i = 1 ; i < commitToPick . getParentCount ( ) ; i + + )
merge . include ( newParents . get ( i ) ) ;
merge . include ( newParents . get ( i ) ) ;
MergeResult mergeResult = merge . call ( ) ;
MergeResult mergeResult = merge . call ( ) ;
if ( mergeResult . getMergeStatus ( ) . isSuccessful ( ) ) {
if ( mergeResult . getMergeStatus ( ) . isSuccessful ( ) ) {
CommitCommand commit = new Git ( repo ) . commit ( ) ;
CommitCommand commit = git . commit ( ) ;
commit . setAuthor ( commitToPick . getAuthorIdent ( ) ) ;
commit . setAuthor ( commitToPick . getAuthorIdent ( ) ) ;
commit . setMessage ( commitToPick . getFullMessage ( ) ) ;
commit . setMessage ( commitToPick . getFullMessage ( ) ) ;
commit . setReflogComment ( REFLOG_PREFIX + " " //$NON-NLS-1$
commit . setReflogComment ( REFLOG_PREFIX + " " //$NON-NLS-1$
+ commitToPick . getShortMessage ( ) ) ;
+ commitToPick . getShortMessage ( ) ) ;
newHead = commit . call ( ) ;
newHead = commit . call ( ) ;
} else {
} else {
if ( operation = = Operation . BEGIN
if ( operation = = Operation . BEGIN & & mergeResult
& & mergeResult . getMergeStatus ( ) = = MergeResult . MergeStatus . FAILED )
. getMergeStatus ( ) = = MergeResult . MergeStatus . FAILED )
return abort ( RebaseResult . failed ( merg eResult
return abort ( RebaseResult
. getFailingPaths ( ) ) ) ;
. failed ( mergeResult . getFailingPaths ( ) ) ) ;
return stop ( commitToPick , Status . STOPPED ) ;
return stop ( commitToPick , Status . STOPPED ) ;
}
}
}
}
}
}
}
return null ;
return null ;
}
}
@ -758,15 +766,15 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
String commitMessage = rebaseState
String commitMessage = rebaseState
. readFile ( MESSAGE_SQUASH ) ;
. readFile ( MESSAGE_SQUASH ) ;
if ( nextStep = = null
try ( Git git = new Git ( repo ) ) {
| | ( ( nextStep . getAction ( ) ! = Action . FIXUP ) & & ( nextStep
if ( nextStep = = null | | ( ( nextStep . getAction ( ) ! = Action . FIXUP )
. getAction ( ) ! = Action . SQUASH ) ) ) {
& & ( nextStep . getAction ( ) ! = Action . SQUASH ) ) ) {
// this is the last step in this sequence
// this is the last step in this sequence
if ( sequenceContainsSquash ) {
if ( sequenceContainsSquash ) {
commitMessage = interactiveHandler
commitMessage = interactiveHandler
. modifyCommitMessage ( commitMessage ) ;
. modifyCommitMessage ( commitMessage ) ;
}
}
retNewHead = new Git ( repo ) . commit ( )
retNewHead = git . commit ( )
. setMessage ( stripCommentLines ( commitMessage ) )
. setMessage ( stripCommentLines ( commitMessage ) )
. setAmend ( true ) . setNoVerify ( true ) . call ( ) ;
. setAmend ( true ) . setNoVerify ( true ) . call ( ) ;
rebaseState . getFile ( MESSAGE_SQUASH ) . delete ( ) ;
rebaseState . getFile ( MESSAGE_SQUASH ) . delete ( ) ;
@ -774,9 +782,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
} else {
} else {
// Next step is either Squash or Fixup
// Next step is either Squash or Fixup
retNewHead = new Git ( repo ) . commit ( ) . setMessage ( commitMessage )
retNewHead = git . commit ( ) . setMessage ( commitMessage )
. setAmend ( true ) . setNoVerify ( true ) . call ( ) ;
. setAmend ( true ) . setNoVerify ( true ) . call ( ) ;
}
}
}
return retNewHead ;
return retNewHead ;
}
}
@ -917,11 +926,11 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
} finally {
} finally {
dc . unlock ( ) ;
dc . unlock ( ) ;
}
}
RevWalk rw = new RevWalk ( repo ) ;
try ( RevWalk rw = new RevWalk ( repo ) ) {
RevCommit commit = rw . parseCommit ( repo . resolve ( Constants . HEAD ) ) ;
RevCommit commit = rw . parseCommit ( repo . resolve ( Constants . HEAD ) ) ;
rw . release ( ) ;
return commit ;
return commit ;
}
}
}
/ * *
/ * *
* @return the commit if we had to do a commit , otherwise null
* @return the commit if we had to do a commit , otherwise null
@ -936,7 +945,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
throw new UnmergedPathsException ( ) ;
throw new UnmergedPathsException ( ) ;
// determine whether we need to commit
// determine whether we need to commit
TreeWalk treeWalk = new TreeWalk ( repo ) ;
boolean needsCommit ;
try ( TreeWalk treeWalk = new TreeWalk ( repo ) ) {
treeWalk . reset ( ) ;
treeWalk . reset ( ) ;
treeWalk . setRecursive ( true ) ;
treeWalk . setRecursive ( true ) ;
treeWalk . addTree ( new DirCacheIterator ( dc ) ) ;
treeWalk . addTree ( new DirCacheIterator ( dc ) ) ;
@ -949,15 +959,16 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
treeWalk . setFilter ( TreeFilter . ANY_DIFF ) ;
treeWalk . setFilter ( TreeFilter . ANY_DIFF ) ;
boolean needsCommit = treeWalk . next ( ) ;
needsCommit = treeWalk . next ( ) ;
treeWalk . release ( ) ;
}
if ( needsCommit ) {
if ( needsCommit ) {
CommitCommand commit = new Git ( repo ) . commit ( ) ;
try ( Git git = new Git ( repo ) ) {
CommitCommand commit = git . commit ( ) ;
commit . setMessage ( rebaseState . readFile ( MESSAGE ) ) ;
commit . setMessage ( rebaseState . readFile ( MESSAGE ) ) ;
commit . setAuthor ( parseAuthor ( ) ) ;
commit . setAuthor ( parseAuthor ( ) ) ;
return commit . call ( ) ;
return commit . call ( ) ;
}
}
}
return null ;
return null ;
}
}
@ -979,9 +990,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
rebaseState . createFile ( AUTHOR_SCRIPT , authorScript ) ;
rebaseState . createFile ( AUTHOR_SCRIPT , authorScript ) ;
rebaseState . createFile ( MESSAGE , commitToPick . getFullMessage ( ) ) ;
rebaseState . createFile ( MESSAGE , commitToPick . getFullMessage ( ) ) ;
ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ;
ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ;
DiffFormatter df = new DiffFormatter ( bos ) ;
try ( DiffFormatter df = new DiffFormatter ( bos ) ) {
df . setRepository ( repo ) ;
df . setRepository ( repo ) ;
df . format ( commitToPick . getParent ( 0 ) , commitToPick ) ;
df . format ( commitToPick . getParent ( 0 ) , commitToPick ) ;
}
rebaseState . createFile ( PATCH , new String ( bos . toByteArray ( ) ,
rebaseState . createFile ( PATCH , new String ( bos . toByteArray ( ) ,
Constants . CHARACTER_ENCODING ) ) ;
Constants . CHARACTER_ENCODING ) ) ;
rebaseState . createFile ( STOPPED_SHA ,
rebaseState . createFile ( STOPPED_SHA ,
@ -1124,9 +1136,11 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
private List < RevCommit > calculatePickList ( RevCommit headCommit )
private List < RevCommit > calculatePickList ( RevCommit headCommit )
throws GitAPIException , NoHeadException , IOException {
throws GitAPIException , NoHeadException , IOException {
LogCommand cmd = new Git ( repo ) . log ( ) . addRange ( upstreamCommit ,
Iterable < RevCommit > commitsToUse ;
headCommit ) ;
try ( Git git = new Git ( repo ) ) {
Iterable < RevCommit > commitsToUse = cmd . call ( ) ;
LogCommand cmd = git . log ( ) . addRange ( upstreamCommit , headCommit ) ;
commitsToUse = cmd . call ( ) ;
}
List < RevCommit > cherryPickList = new ArrayList < RevCommit > ( ) ;
List < RevCommit > cherryPickList = new ArrayList < RevCommit > ( ) ;
for ( RevCommit commit : commitsToUse ) {
for ( RevCommit commit : commitsToUse ) {
if ( preserveMerges | | commit . getParentCount ( ) = = 1 )
if ( preserveMerges | | commit . getParentCount ( ) = = 1 )
@ -1312,7 +1326,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
}
}
dco . setFailOnConflict ( false ) ;
dco . setFailOnConflict ( false ) ;
dco . checkout ( ) ;
dco . checkout ( ) ;
walk . relea se( ) ;
walk . clo se( ) ;
} finally {
} finally {
monitor . endTask ( ) ;
monitor . endTask ( ) ;
}
}
@ -1387,7 +1401,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
throw new IOException ( "Could not rewind to upstream commit" ) ;
throw new IOException ( "Could not rewind to upstream commit" ) ;
}
}
} finally {
} finally {
walk . relea se( ) ;
walk . clo se( ) ;
monitor . endTask ( ) ;
monitor . endTask ( ) ;
}
}
return true ;
return true ;