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