Package org.eclipse.jgit.api
Class RebaseCommand
- All Implemented Interfaces:
Callable<RebaseResult>
A class used to execute a
Rebase
command. It has setters for all
supported options and arguments of this command and a call()
method
to finally execute the command. Each instance of this class should only be
used for one invocation of the command (means: one call to call()
)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Allows to configure the interactive rebase process steps and to modify commit messages.static interface
ExtendsRebaseCommand.InteractiveHandler
with an enhanced callback for editing commit messages.static enum
The available operationsprivate static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static final String
private static final String
private static final String
private CommitConfig
private ContentMergeStrategy
private static final String
File containing the current commit(s) to cherry pick when --preserve-merges is used.private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private RebaseCommand.InteractiveHandler
private boolean
private static final String
private static final String
private static final String
private ProgressMonitor
private RevCommit
private static final String
private static final String
private RebaseCommand.Operation
private static final String
private boolean
private static final String
private static final String
The name of the "rebase-apply" folder for non-interactive rebases.private static final String
private static final String
Pre git 1.7.6 file name forREBASE_HEAD
.static final String
The name of the "rebase-merge" folder for interactive rebases.private final RebaseCommand.RebaseState
private static final String
private static final String
The folder containing the hashes of (potentially) rewritten commits when --preserve-merges is used.private boolean
static final String
The name of the "stopped-sha" fileprivate MergeStrategy
private RevCommit
private String
private final RevWalk
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
RebaseCommand
(Repository repo) Constructor for RebaseCommand. -
Method Summary
Modifier and TypeMethodDescriptionprivate RebaseResult
abort
(RebaseResult result) private void
private boolean
calculatePickList
(RevCommit headCommit) call()
private boolean
checkoutCommit
(String headName, RevCommit commit) private RevCommit
private void
private void
checkSteps
(List<RebaseTodoLine> steps) private RebaseResult
cherryPickCommit
(RevCommit commitToPick) private RebaseResult
cherryPickCommitFlattening
(RevCommit commitToPick) private RebaseResult
cherryPickCommitPreservingMerges
(RevCommit commitToPick) private static String
composeSquashMessage
(boolean isSquash, RevCommit commitToPick, String currSquashMessage, int count) private RevCommit
private RevCommit
doSquashFixup
(boolean isSquash, RevCommit commitToPick, boolean isLast, File messageFixup, File messageSquash) private String
editCommitMessage
(boolean[] doChangeId, String message, CommitConfig.CleanupMode mode) private RebaseResult
finishRebase
(RevCommit finalHead, boolean lastStepIsForward) private Ref
getHead()
private static String
getHeadName
(Ref head) getNewParents
(RevCommit commitToPick) private static String
getOrdinal
(int count) private ObjectId
private String
private RebaseResult
private void
initializeSquashFixupFile
(String messageFile, String fullMessage) private boolean
private PersonIdent
(package private) PersonIdent
parseAuthor
(byte[] raw) (package private) static int
parseSquashFixupSequenceCount
(String currSquashMessage) Parse the count from squashed commit messagesprivate void
popSteps
(int numSteps) Removes the number of lines given in the parameter from thegit-rebase-todo
file but preserves comments and other lines that can not be parsed as stepsprivate RebaseResult
processStep
(RebaseTodoLine step, boolean shouldPick) private void
Enable interactive rebaserunInteractively
(RebaseCommand.InteractiveHandler handler, boolean stopAfterRebaseInteractiveInitialization) Enable interactive rebasesetContentMergeStrategy
(ContentMergeStrategy strategy) Sets the content merge strategy to use if themerge strategy
is "resolve" or "recursive".setOperation
(RebaseCommand.Operation operation) Set the operation to execute during rebasesetPreserveMerges
(boolean preserve) Whether to preserve merges during rebasesetProgressMonitor
(ProgressMonitor monitor) Set progress monitorsetStrategy
(MergeStrategy strategy) Set theMergeStrategy
.setUpstream
(String upstream) Set the upstream branchsetUpstream
(AnyObjectId upstream) Set the upstream commitsetUpstream
(RevCommit upstream) Set upstreamRevCommit
setUpstreamName
(String upstreamName) Optionally override the name of the upstream.private RevCommit
squashIntoPrevious
(boolean sequenceContainsSquash, boolean isLast) private RebaseResult
stop
(RevCommit commitToPick, RebaseResult.Status status) (package private) String
toAuthorScript
(PersonIdent author) private RevCommit
tryFastForward
(String headName, RevCommit oldCommit, RevCommit newCommit) tryFastForward
(RevCommit newCommit) Check if we can fast-forward and returns the new head if it is possibleprivate void
updateHead
(String headName, RevCommit aNewHead, RevCommit onto) private void
updateStashRef
(ObjectId commitId, PersonIdent refLogIdent, String refLogMessage) private void
writeCurrentCommit
(RevCommit commit) private void
writeMergeInfo
(RevCommit commitToPick, List<RevCommit> newParents) private void
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
Field Details
-
REBASE_MERGE
The name of the "rebase-merge" folder for interactive rebases.- See Also:
-
REBASE_APPLY
The name of the "rebase-apply" folder for non-interactive rebases.- See Also:
-
STOPPED_SHA
The name of the "stopped-sha" file- See Also:
-
AUTHOR_SCRIPT
- See Also:
-
DONE
- See Also:
-
GIT_AUTHOR_DATE
- See Also:
-
GIT_AUTHOR_EMAIL
- See Also:
-
GIT_AUTHOR_NAME
- See Also:
-
GIT_REBASE_TODO
- See Also:
-
HEAD_NAME
- See Also:
-
INTERACTIVE
- See Also:
-
QUIET
- See Also:
-
MESSAGE
- See Also:
-
ONTO
- See Also:
-
ONTO_NAME
- See Also:
-
PATCH
- See Also:
-
REBASE_HEAD
- See Also:
-
REBASE_HEAD_LEGACY
Pre git 1.7.6 file name forREBASE_HEAD
.- See Also:
-
AMEND
- See Also:
-
MESSAGE_FIXUP
- See Also:
-
MESSAGE_SQUASH
- See Also:
-
AUTOSTASH
- See Also:
-
AUTOSTASH_MSG
- See Also:
-
REWRITTEN
The folder containing the hashes of (potentially) rewritten commits when --preserve-merges is used.Native git rebase --merge uses a file of that name to record commits to copy notes at the end of the whole rebase.
- See Also:
-
CURRENT_COMMIT
File containing the current commit(s) to cherry pick when --preserve-merges is used.- See Also:
-
REFLOG_PREFIX
- See Also:
-
operation
-
upstreamCommit
-
upstreamCommitName
-
monitor
-
walk
-
rebaseState
-
interactiveHandler
-
commitConfig
-
stopAfterInitialization
private boolean stopAfterInitialization -
newHead
-
lastStepWasForward
private boolean lastStepWasForward -
strategy
-
contentStrategy
-
preserveMerges
private boolean preserveMerges
-
-
Constructor Details
-
RebaseCommand
Constructor for RebaseCommand.
- Parameters:
repo
- theRepository
-
-
Method Details
-
call
public RebaseResult call() throws GitAPIException, NoHeadException, RefNotFoundException, WrongRepositoryStateExceptionExecute the command
Executes the
Rebase
command with all the options and parameters collected by the setter methods of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an instance.- Specified by:
call
in interfaceCallable<RebaseResult>
- Specified by:
call
in classGitCommand<RebaseResult>
- Throws:
GitAPIException
NoHeadException
RefNotFoundException
WrongRepositoryStateException
-
autoStash
- Throws:
GitAPIException
IOException
-
autoStashApply
- Throws:
IOException
GitAPIException
-
updateStashRef
private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, String refLogMessage) throws IOException - Throws:
IOException
-
processStep
private RebaseResult processStep(RebaseTodoLine step, boolean shouldPick) throws IOException, GitAPIException - Throws:
IOException
GitAPIException
-
editCommitMessage
private String editCommitMessage(boolean[] doChangeId, String message, @NonNull CommitConfig.CleanupMode mode) -
cherryPickCommit
private RebaseResult cherryPickCommit(RevCommit commitToPick) throws IOException, GitAPIException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, NoHeadException -
cherryPickCommitFlattening
private RebaseResult cherryPickCommitFlattening(RevCommit commitToPick) throws IOException, GitAPIException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, NoHeadException -
cherryPickCommitPreservingMerges
private RebaseResult cherryPickCommitPreservingMerges(RevCommit commitToPick) throws IOException, GitAPIException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, NoHeadException -
writeMergeInfo
- Throws:
IOException
-
getNewParents
- Throws:
IOException
-
writeCurrentCommit
- Throws:
IOException
-
writeRewrittenHashes
private void writeRewrittenHashes() throws RevisionSyntaxException, IOException, RefNotFoundException -
finishRebase
private RebaseResult finishRebase(RevCommit finalHead, boolean lastStepIsForward) throws IOException, GitAPIException - Throws:
IOException
GitAPIException
-
checkSteps
-
doSquashFixup
private RevCommit doSquashFixup(boolean isSquash, RevCommit commitToPick, boolean isLast, File messageFixup, File messageSquash) throws IOException, GitAPIException - Throws:
IOException
GitAPIException
-
resetSoftToParent
-
squashIntoPrevious
private RevCommit squashIntoPrevious(boolean sequenceContainsSquash, boolean isLast) throws IOException, GitAPIException - Throws:
IOException
GitAPIException
-
composeSquashMessage
-
getOrdinal
-
parseSquashFixupSequenceCount
Parse the count from squashed commit messages- Parameters:
currSquashMessage
- the squashed commit message to be parsed- Returns:
- the count of squashed messages in the given string
-
initializeSquashFixupFile
- Throws:
IOException
-
getOurCommitName
-
updateHead
- Throws:
IOException
-
checkoutCurrentHead
- Throws:
IOException
NoHeadException
-
continueRebase
- Returns:
- the commit if we had to do a commit, otherwise null
- Throws:
GitAPIException
IOException
-
parseAuthor
- Throws:
IOException
-
stop
- Throws:
IOException
-
toAuthorScript
-
popSteps
Removes the number of lines given in the parameter from thegit-rebase-todo
file but preserves comments and other lines that can not be parsed as steps- Parameters:
numSteps
-- Throws:
IOException
-
initFilesAndRewind
- Throws:
IOException
GitAPIException
-
calculatePickList
- Throws:
IOException
-
getHeadName
-
getHead
- Throws:
IOException
RefNotFoundException
-
isInteractive
private boolean isInteractive() -
tryFastForward
Check if we can fast-forward and returns the new head if it is possible- Parameters:
newCommit
- aRevCommit
object to check if we can fast-forward to.- Returns:
- the new head, or null
- Throws:
IOException
GitAPIException
-
tryFastForward
private RevCommit tryFastForward(String headName, RevCommit oldCommit, RevCommit newCommit) throws IOException, GitAPIException - Throws:
IOException
GitAPIException
-
checkParameters
- Throws:
WrongRepositoryStateException
-
abort
- Throws:
IOException
GitAPIException
-
getOriginalHead
- Throws:
IOException
-
checkoutCommit
private boolean checkoutCommit(String headName, RevCommit commit) throws IOException, CheckoutConflictException - Throws:
IOException
CheckoutConflictException
-
setUpstream
Set upstreamRevCommit
- Parameters:
upstream
- the upstream commit- Returns:
this
-
setUpstream
Set the upstream commit- Parameters:
upstream
- id of the upstream commit- Returns:
this
-
setUpstream
Set the upstream branch- Parameters:
upstream
- the name of the upstream branch- Returns:
this
- Throws:
RefNotFoundException
-
setUpstreamName
Optionally override the name of the upstream. If this is used, it has to come after anysetUpstream(org.eclipse.jgit.revwalk.RevCommit)
call.- Parameters:
upstreamName
- the name which will be used to refer to upstream in conflicts- Returns:
this
-
setOperation
Set the operation to execute during rebase- Parameters:
operation
- the operation to perform- Returns:
this
-
setProgressMonitor
Set progress monitor- Parameters:
monitor
- a progress monitor- Returns:
- this instance
-
runInteractively
Enable interactive rebaseDoes not stop after initialization of interactive rebase. This is equivalent to
runInteractively(handler, false)
;- Parameters:
handler
- theRebaseCommand.InteractiveHandler
to use- Returns:
- this
-
runInteractively
public RebaseCommand runInteractively(RebaseCommand.InteractiveHandler handler, boolean stopAfterRebaseInteractiveInitialization) Enable interactive rebaseIf stopAfterRebaseInteractiveInitialization is
true
the rebase stops after initialization of interactive rebase returningRebaseResult.INTERACTIVE_PREPARED_RESULT
- Parameters:
handler
- theRebaseCommand.InteractiveHandler
to usestopAfterRebaseInteractiveInitialization
- iftrue
the rebase stops after initialization- Returns:
- this instance
- Since:
- 3.2
-
setStrategy
Set theMergeStrategy
.- Parameters:
strategy
- The merge strategy to use during this rebase operation.- Returns:
this
- Since:
- 3.4
-
setContentMergeStrategy
Sets the content merge strategy to use if themerge strategy
is "resolve" or "recursive".- Parameters:
strategy
- theContentMergeStrategy
to be used- Returns:
this
- Since:
- 5.12
-
setPreserveMerges
Whether to preserve merges during rebase- Parameters:
preserve
-true
to re-create merges during rebase. Defaults tofalse
, a flattening rebase.- Returns:
this
- Since:
- 3.5
-
parseAuthor
-