@ -137,6 +137,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
private static final String ONTO = "onto" ;
private static final String ONTO = "onto" ;
private static final String ONTO_NAME = "onto-name" ;
private static final String PATCH = "patch" ;
private static final String PATCH = "patch" ;
private static final String REBASE_HEAD = "head" ;
private static final String REBASE_HEAD = "head" ;
@ -167,6 +169,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
private RevCommit upstreamCommit ;
private RevCommit upstreamCommit ;
private String upstreamCommitName ;
private ProgressMonitor monitor = NullProgressMonitor . INSTANCE ;
private ProgressMonitor monitor = NullProgressMonitor . INSTANCE ;
private final RevWalk walk ;
private final RevWalk walk ;
@ -211,9 +215,16 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
case SKIP :
case SKIP :
// fall through
// fall through
case CONTINUE :
case CONTINUE :
String upstreamCommitName = readFile ( rebaseDir , ONTO ) ;
String upstreamCommitId = readFile ( rebaseDir , ONTO ) ;
try {
upstreamCommitName = readFile ( rebaseDir , ONTO_NAME ) ;
} catch ( FileNotFoundException e ) {
// Fall back to commit ID if file doesn't exist (e.g. rebase
// was started by C Git)
upstreamCommitName = upstreamCommitId ;
}
this . upstreamCommit = walk . parseCommit ( repo
this . upstreamCommit = walk . parseCommit ( repo
. resolve ( upstreamCommitName ) ) ;
. resolve ( upstreamCommitId ) ) ;
break ;
break ;
case BEGIN :
case BEGIN :
RebaseResult res = initFilesAndRewind ( ) ;
RebaseResult res = initFilesAndRewind ( ) ;
@ -267,8 +278,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
// TODO if the content of this commit is already merged
// TODO if the content of this commit is already merged
// 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 ( ) ;
CherryPickResult cherryPickResult = new Git ( repo )
CherryPickResult cherryPickResult = new Git ( repo )
. cherryPick ( ) . include ( commitToPick ) . call ( ) ;
. cherryPick ( ) . include ( commitToPick )
. setOurCommitName ( ourCommitName ) . call ( ) ;
switch ( cherryPickResult . getStatus ( ) ) {
switch ( cherryPickResult . getStatus ( ) ) {
case FAILED :
case FAILED :
if ( operation = = Operation . BEGIN )
if ( operation = = Operation . BEGIN )
@ -300,6 +313,14 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
}
}
}
}
private String getOurCommitName ( ) {
// If onto is different from upstream, this should say "onto", but
// RebaseCommand doesn't support a different "onto" at the moment.
String ourCommitName = "Upstream, based on "
+ Repository . shortenRefName ( upstreamCommitName ) ;
return ourCommitName ;
}
private void updateHead ( String headName , RevCommit newHead )
private void updateHead ( String headName , RevCommit newHead )
throws IOException {
throws IOException {
// point the previous head (if any) to the new commit
// point the previous head (if any) to the new commit
@ -584,6 +605,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
createFile ( rebaseDir , REBASE_HEAD , headId . name ( ) ) ;
createFile ( rebaseDir , REBASE_HEAD , headId . name ( ) ) ;
createFile ( rebaseDir , HEAD_NAME , headName ) ;
createFile ( rebaseDir , HEAD_NAME , headName ) ;
createFile ( rebaseDir , ONTO , upstreamCommit . name ( ) ) ;
createFile ( rebaseDir , ONTO , upstreamCommit . name ( ) ) ;
createFile ( rebaseDir , ONTO_NAME , upstreamCommitName ) ;
createFile ( rebaseDir , INTERACTIVE , "" ) ;
createFile ( rebaseDir , INTERACTIVE , "" ) ;
BufferedWriter fw = new BufferedWriter ( new OutputStreamWriter (
BufferedWriter fw = new BufferedWriter ( new OutputStreamWriter (
new FileOutputStream ( new File ( rebaseDir , GIT_REBASE_TODO ) ) ,
new FileOutputStream ( new File ( rebaseDir , GIT_REBASE_TODO ) ) ,
@ -884,6 +906,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
* /
* /
public RebaseCommand setUpstream ( RevCommit upstream ) {
public RebaseCommand setUpstream ( RevCommit upstream ) {
this . upstreamCommit = upstream ;
this . upstreamCommit = upstream ;
this . upstreamCommitName = upstream . name ( ) ;
return this ;
return this ;
}
}
@ -895,6 +918,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
public RebaseCommand setUpstream ( AnyObjectId upstream ) {
public RebaseCommand setUpstream ( AnyObjectId upstream ) {
try {
try {
this . upstreamCommit = walk . parseCommit ( upstream ) ;
this . upstreamCommit = walk . parseCommit ( upstream ) ;
this . upstreamCommitName = upstream . name ( ) ;
} catch ( IOException e ) {
} catch ( IOException e ) {
throw new JGitInternalException ( MessageFormat . format (
throw new JGitInternalException ( MessageFormat . format (
JGitText . get ( ) . couldNotReadObjectWhileParsingCommit ,
JGitText . get ( ) . couldNotReadObjectWhileParsingCommit ,
@ -917,12 +941,30 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
throw new RefNotFoundException ( MessageFormat . format ( JGitText
throw new RefNotFoundException ( MessageFormat . format ( JGitText
. get ( ) . refNotResolved , upstream ) ) ;
. get ( ) . refNotResolved , upstream ) ) ;
upstreamCommit = walk . parseCommit ( repo . resolve ( upstream ) ) ;
upstreamCommit = walk . parseCommit ( repo . resolve ( upstream ) ) ;
upstreamCommitName = upstream ;
return this ;
return this ;
} catch ( IOException ioe ) {
} catch ( IOException ioe ) {
throw new JGitInternalException ( ioe . getMessage ( ) , ioe ) ;
throw new JGitInternalException ( ioe . getMessage ( ) , ioe ) ;
}
}
}
}
/ * *
* Optionally override the name of the upstream . If this is used , it has to
* come after any { @link # setUpstream } call .
*
* @param upstreamName
* the name which will be used to refer to upstream in conflicts
* @return { @code this }
* /
public RebaseCommand setUpstreamName ( String upstreamName ) {
if ( upstreamCommit = = null ) {
throw new IllegalStateException (
"setUpstreamName must be called after setUpstream." ) ;
}
this . upstreamCommitName = upstreamName ;
return this ;
}
/ * *
/ * *
* @param operation
* @param operation
* the operation to perform
* the operation to perform