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 interfaceAllows to configure the interactive rebase process steps and to modify commit messages.static interfaceExtendsRebaseCommand.InteractiveHandlerwith an enhanced callback for editing commit messages.static enumThe available operationsprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate CommitConfigprivate ContentMergeStrategyprivate static final StringFile containing the current commit(s) to cherry pick when --preserve-merges is used.private static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate RebaseCommand.InteractiveHandlerprivate booleanprivate static final Stringprivate static final Stringprivate static final Stringprivate ProgressMonitorprivate RevCommitprivate static final Stringprivate static final Stringprivate RebaseCommand.Operationprivate static final Stringprivate booleanprivate static final Stringprivate static final StringThe name of the "rebase-apply" folder for non-interactive rebases.private static final Stringprivate static final StringPre git 1.7.6 file name forREBASE_HEAD.static final StringThe name of the "rebase-merge" folder for interactive rebases.private final RebaseCommand.RebaseStateprivate static final Stringprivate static final StringThe folder containing the hashes of (potentially) rewritten commits when --preserve-merges is used.private booleanstatic final StringThe name of the "stopped-sha" fileprivate MergeStrategyprivate RevCommitprivate Stringprivate final RevWalkFields inherited from class org.eclipse.jgit.api.GitCommand
repo -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRebaseCommand(Repository repo) Constructor for RebaseCommand. -
Method Summary
Modifier and TypeMethodDescriptionprivate RebaseResultabort(RebaseResult result) private voidprivate booleancalculatePickList(RevCommit headCommit) call()private booleancheckoutCommit(String headName, RevCommit commit) private RevCommitprivate voidprivate voidcheckSteps(List<RebaseTodoLine> steps) private RebaseResultcherryPickCommit(RevCommit commitToPick) private RebaseResultcherryPickCommitFlattening(RevCommit commitToPick) private RebaseResultcherryPickCommitPreservingMerges(RevCommit commitToPick) private static StringcomposeSquashMessage(boolean isSquash, RevCommit commitToPick, String currSquashMessage, int count) private RevCommitprivate RevCommitdoSquashFixup(boolean isSquash, RevCommit commitToPick, boolean isLast, File messageFixup, File messageSquash) private StringeditCommitMessage(boolean[] doChangeId, String message, CommitConfig.CleanupMode mode) private RebaseResultfinishRebase(RevCommit finalHead, boolean lastStepIsForward) private RefgetHead()private static StringgetHeadName(Ref head) getNewParents(RevCommit commitToPick) private static StringgetOrdinal(int count) private ObjectIdprivate Stringprivate RebaseResultprivate voidinitializeSquashFixupFile(String messageFile, String fullMessage) private booleanprivate PersonIdent(package private) PersonIdentparseAuthor(byte[] raw) (package private) static intparseSquashFixupSequenceCount(String currSquashMessage) Parse the count from squashed commit messagesprivate voidpopSteps(int numSteps) Removes the number of lines given in the parameter from thegit-rebase-todofile but preserves comments and other lines that can not be parsed as stepsprivate RebaseResultprocessStep(RebaseTodoLine step, boolean shouldPick) private voidEnable interactive rebaserunInteractively(RebaseCommand.InteractiveHandler handler, boolean stopAfterRebaseInteractiveInitialization) Enable interactive rebasesetContentMergeStrategy(ContentMergeStrategy strategy) Sets the content merge strategy to use if themerge strategyis "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 upstreamRevCommitsetUpstreamName(String upstreamName) Optionally override the name of the upstream.private RevCommitsquashIntoPrevious(boolean sequenceContainsSquash, boolean isLast) private RebaseResultstop(RevCommit commitToPick, RebaseResult.Status status) (package private) StringtoAuthorScript(PersonIdent author) private RevCommittryFastForward(String headName, RevCommit oldCommit, RevCommit newCommit) tryFastForward(RevCommit newCommit) Check if we can fast-forward and returns the new head if it is possibleprivate voidupdateHead(String headName, RevCommit aNewHead, RevCommit onto) private voidupdateStashRef(ObjectId commitId, PersonIdent refLogIdent, String refLogMessage) private voidwriteCurrentCommit(RevCommit commit) private voidwriteMergeInfo(RevCommit commitToPick, List<RevCommit> newParents) private voidMethods 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
Rebasecommand 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:
callin interfaceCallable<RebaseResult>- Specified by:
callin classGitCommand<RebaseResult>- Throws:
GitAPIExceptionNoHeadExceptionRefNotFoundExceptionWrongRepositoryStateException
-
autoStash
- Throws:
GitAPIExceptionIOException
-
autoStashApply
- Throws:
IOExceptionGitAPIException
-
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:
IOExceptionGitAPIException
-
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:
IOExceptionGitAPIException
-
checkSteps
-
doSquashFixup
private RevCommit doSquashFixup(boolean isSquash, RevCommit commitToPick, boolean isLast, File messageFixup, File messageSquash) throws IOException, GitAPIException - Throws:
IOExceptionGitAPIException
-
resetSoftToParent
-
squashIntoPrevious
private RevCommit squashIntoPrevious(boolean sequenceContainsSquash, boolean isLast) throws IOException, GitAPIException - Throws:
IOExceptionGitAPIException
-
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:
IOExceptionNoHeadException
-
continueRebase
- Returns:
- the commit if we had to do a commit, otherwise null
- Throws:
GitAPIExceptionIOException
-
parseAuthor
- Throws:
IOException
-
stop
- Throws:
IOException
-
toAuthorScript
-
popSteps
Removes the number of lines given in the parameter from thegit-rebase-todofile but preserves comments and other lines that can not be parsed as steps- Parameters:
numSteps-- Throws:
IOException
-
initFilesAndRewind
- Throws:
IOExceptionGitAPIException
-
calculatePickList
- Throws:
IOException
-
getHeadName
-
getHead
- Throws:
IOExceptionRefNotFoundException
-
isInteractive
private boolean isInteractive() -
tryFastForward
Check if we can fast-forward and returns the new head if it is possible- Parameters:
newCommit- aRevCommitobject to check if we can fast-forward to.- Returns:
- the new head, or null
- Throws:
IOExceptionGitAPIException
-
tryFastForward
private RevCommit tryFastForward(String headName, RevCommit oldCommit, RevCommit newCommit) throws IOException, GitAPIException - Throws:
IOExceptionGitAPIException
-
checkParameters
- Throws:
WrongRepositoryStateException
-
abort
- Throws:
IOExceptionGitAPIException
-
getOriginalHead
- Throws:
IOException
-
checkoutCommit
private boolean checkoutCommit(String headName, RevCommit commit) throws IOException, CheckoutConflictException - Throws:
IOExceptionCheckoutConflictException
-
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.InteractiveHandlerto use- Returns:
- this
-
runInteractively
public RebaseCommand runInteractively(RebaseCommand.InteractiveHandler handler, boolean stopAfterRebaseInteractiveInitialization) Enable interactive rebaseIf stopAfterRebaseInteractiveInitialization is
truethe rebase stops after initialization of interactive rebase returningRebaseResult.INTERACTIVE_PREPARED_RESULT- Parameters:
handler- theRebaseCommand.InteractiveHandlerto usestopAfterRebaseInteractiveInitialization- iftruethe 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 strategyis "resolve" or "recursive".- Parameters:
strategy- theContentMergeStrategyto be used- Returns:
this- Since:
- 5.12
-
setPreserveMerges
Whether to preserve merges during rebase- Parameters:
preserve-trueto re-create merges during rebase. Defaults tofalse, a flattening rebase.- Returns:
this- Since:
- 3.5
-
parseAuthor
-