public class RebaseCommand extends GitCommand<RebaseResult>
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())
| Modifier and Type | Class and Description |
|---|---|
static interface |
RebaseCommand.InteractiveHandler
Allows configure rebase interactive process and modify commit message
|
static class |
RebaseCommand.Operation
The available operations
|
private static class |
RebaseCommand.RebaseState |
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
AMEND |
private static java.lang.String |
AUTHOR_SCRIPT |
private static java.lang.String |
AUTOSTASH |
private static java.lang.String |
AUTOSTASH_MSG |
private static java.lang.String |
CURRENT_COMMIT
File containing the current commit(s) to cherry pick when --preserve-merges
is used.
|
private static java.lang.String |
DONE |
private static java.lang.String |
GIT_AUTHOR_DATE |
private static java.lang.String |
GIT_AUTHOR_EMAIL |
private static java.lang.String |
GIT_AUTHOR_NAME |
private static java.lang.String |
GIT_REBASE_TODO |
private static java.lang.String |
HEAD_NAME |
private static java.lang.String |
INTERACTIVE |
private RebaseCommand.InteractiveHandler |
interactiveHandler |
private boolean |
lastStepWasForward |
private static java.lang.String |
MESSAGE |
private static java.lang.String |
MESSAGE_FIXUP |
private static java.lang.String |
MESSAGE_SQUASH |
private ProgressMonitor |
monitor |
private RevCommit |
newHead |
private static java.lang.String |
ONTO |
private static java.lang.String |
ONTO_NAME |
private RebaseCommand.Operation |
operation |
private static java.lang.String |
PATCH |
private boolean |
preserveMerges |
private static java.lang.String |
QUIET |
private static java.lang.String |
REBASE_APPLY
The name of the "rebase-apply" folder for non-interactive rebases.
|
private static java.lang.String |
REBASE_HEAD |
static java.lang.String |
REBASE_MERGE
The name of the "rebase-merge" folder for interactive rebases.
|
private RebaseCommand.RebaseState |
rebaseState |
private static java.lang.String |
REFLOG_PREFIX |
private static java.lang.String |
REWRITTEN
The folder containing the hashes of (potentially) rewritten commits when
--preserve-merges is used.
|
private boolean |
stopAfterInitialization |
static java.lang.String |
STOPPED_SHA
The name of the "stopped-sha" file
|
private MergeStrategy |
strategy |
private RevCommit |
upstreamCommit |
private java.lang.String |
upstreamCommitName |
private RevWalk |
walk |
repo| Modifier | Constructor and Description |
|---|---|
protected |
RebaseCommand(Repository repo)
Constructor for RebaseCommand.
|
| Modifier and Type | Method and Description |
|---|---|
private RebaseResult |
abort(RebaseResult result) |
private void |
autoStash() |
private boolean |
autoStashApply() |
private java.util.List<RevCommit> |
calculatePickList(RevCommit headCommit) |
RebaseResult |
call() |
private boolean |
checkoutCommit(java.lang.String headName,
RevCommit commit) |
private RevCommit |
checkoutCurrentHead() |
private void |
checkParameters() |
private void |
checkSteps(java.util.List<RebaseTodoLine> steps) |
private RebaseResult |
cherryPickCommit(RevCommit commitToPick) |
private RebaseResult |
cherryPickCommitFlattening(RevCommit commitToPick) |
private RebaseResult |
cherryPickCommitPreservingMerges(RevCommit commitToPick) |
private static java.lang.String |
composeSquashMessage(boolean isSquash,
RevCommit commitToPick,
java.lang.String currSquashMessage,
int count) |
private RevCommit |
continueRebase() |
private RevCommit |
doSquashFixup(boolean isSquash,
RevCommit commitToPick,
RebaseTodoLine nextStep,
java.io.File messageFixup,
java.io.File messageSquash) |
private RebaseResult |
finishRebase(RevCommit finalHead,
boolean lastStepIsForward) |
private Ref |
getHead() |
private static java.lang.String |
getHeadName(Ref head) |
private java.util.List<RevCommit> |
getNewParents(RevCommit commitToPick) |
private static java.lang.String |
getOrdinal(int count) |
private java.lang.String |
getOurCommitName() |
private RebaseResult |
initFilesAndRewind() |
private void |
initializeSquashFixupFile(java.lang.String messageFile,
java.lang.String fullMessage) |
private boolean |
isInteractive() |
private PersonIdent |
parseAuthor() |
(package private) PersonIdent |
parseAuthor(byte[] raw) |
(package private) static int |
parseSquashFixupSequenceCount(java.lang.String currSquashMessage)
Parse the count from squashed commit messages
|
private void |
popSteps(int numSteps)
Removes the number of lines given in the parameter from the
git-rebase-todo file but preserves comments and other lines
that can not be parsed as steps |
private RebaseResult |
processStep(RebaseTodoLine step,
boolean shouldPick) |
private void |
resetSoftToParent() |
RebaseCommand |
runInteractively(RebaseCommand.InteractiveHandler handler)
Enable interactive rebase
|
RebaseCommand |
runInteractively(RebaseCommand.InteractiveHandler handler,
boolean stopAfterRebaseInteractiveInitialization)
Enable interactive rebase
|
RebaseCommand |
setOperation(RebaseCommand.Operation operation)
Set the operation to execute during rebase
|
RebaseCommand |
setPreserveMerges(boolean preserve)
Whether to preserve merges during rebase
|
RebaseCommand |
setProgressMonitor(ProgressMonitor monitor)
Set progress monitor
|
RebaseCommand |
setStrategy(MergeStrategy strategy)
Set the
MergeStrategy. |
RebaseCommand |
setUpstream(AnyObjectId upstream)
Set the upstream commit
|
RebaseCommand |
setUpstream(RevCommit upstream)
Set upstream
RevCommit |
RebaseCommand |
setUpstream(java.lang.String upstream)
Set the upstream branch
|
RebaseCommand |
setUpstreamName(java.lang.String upstreamName)
Optionally override the name of the upstream.
|
private RevCommit |
squashIntoPrevious(boolean sequenceContainsSquash,
RebaseTodoLine nextStep) |
private RebaseResult |
stop(RevCommit commitToPick,
RebaseResult.Status status) |
private static java.lang.String |
stripCommentLines(java.lang.String commitMessage) |
(package private) java.lang.String |
toAuthorScript(PersonIdent author) |
RevCommit |
tryFastForward(RevCommit newCommit)
Check if we can fast-forward and returns the new head if it is possible
|
private RevCommit |
tryFastForward(java.lang.String headName,
RevCommit oldCommit,
RevCommit newCommit) |
private void |
updateHead(java.lang.String headName,
RevCommit aNewHead,
RevCommit onto) |
private void |
updateStashRef(ObjectId commitId,
PersonIdent refLogIdent,
java.lang.String refLogMessage) |
private void |
writeCurrentCommit(RevCommit commit) |
private void |
writeMergeInfo(RevCommit commitToPick,
java.util.List<RevCommit> newParents) |
private void |
writeRewrittenHashes() |
checkCallable, getRepository, setCallablepublic static final java.lang.String REBASE_MERGE
private static final java.lang.String REBASE_APPLY
public static final java.lang.String STOPPED_SHA
private static final java.lang.String AUTHOR_SCRIPT
private static final java.lang.String DONE
private static final java.lang.String GIT_AUTHOR_DATE
private static final java.lang.String GIT_AUTHOR_EMAIL
private static final java.lang.String GIT_AUTHOR_NAME
private static final java.lang.String GIT_REBASE_TODO
private static final java.lang.String HEAD_NAME
private static final java.lang.String INTERACTIVE
private static final java.lang.String QUIET
private static final java.lang.String MESSAGE
private static final java.lang.String ONTO
private static final java.lang.String ONTO_NAME
private static final java.lang.String PATCH
private static final java.lang.String REBASE_HEAD
private static final java.lang.String AMEND
private static final java.lang.String MESSAGE_FIXUP
private static final java.lang.String MESSAGE_SQUASH
private static final java.lang.String AUTOSTASH
private static final java.lang.String AUTOSTASH_MSG
private static final java.lang.String REWRITTEN
private static final java.lang.String CURRENT_COMMIT
private static final java.lang.String REFLOG_PREFIX
private RebaseCommand.Operation operation
private RevCommit upstreamCommit
private java.lang.String upstreamCommitName
private ProgressMonitor monitor
private final RevWalk walk
private final RebaseCommand.RebaseState rebaseState
private RebaseCommand.InteractiveHandler interactiveHandler
private boolean stopAfterInitialization
private RevCommit newHead
private boolean lastStepWasForward
private MergeStrategy strategy
private boolean preserveMerges
protected RebaseCommand(Repository repo)
Constructor for RebaseCommand.
repo - the Repositorypublic RebaseResult call() throws GitAPIException, NoHeadException, RefNotFoundException, WrongRepositoryStateException
Execute 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.
call in interface java.util.concurrent.Callable<RebaseResult>call in class GitCommand<RebaseResult>GitAPIExceptionNoHeadExceptionRefNotFoundExceptionWrongRepositoryStateExceptionprivate void autoStash()
throws GitAPIException,
java.io.IOException
GitAPIExceptionjava.io.IOExceptionprivate boolean autoStashApply()
throws java.io.IOException,
GitAPIException
java.io.IOExceptionGitAPIExceptionprivate void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, java.lang.String refLogMessage) throws java.io.IOException
java.io.IOExceptionprivate RebaseResult processStep(RebaseTodoLine step, boolean shouldPick) throws java.io.IOException, GitAPIException
java.io.IOExceptionGitAPIExceptionprivate RebaseResult cherryPickCommit(RevCommit commitToPick) throws java.io.IOException, GitAPIException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, NoHeadException
java.io.IOExceptionGitAPIExceptionNoMessageExceptionUnmergedPathsExceptionConcurrentRefUpdateExceptionWrongRepositoryStateExceptionNoHeadExceptionprivate RebaseResult cherryPickCommitFlattening(RevCommit commitToPick) throws java.io.IOException, GitAPIException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, NoHeadException
java.io.IOExceptionGitAPIExceptionNoMessageExceptionUnmergedPathsExceptionConcurrentRefUpdateExceptionWrongRepositoryStateExceptionNoHeadExceptionprivate RebaseResult cherryPickCommitPreservingMerges(RevCommit commitToPick) throws java.io.IOException, GitAPIException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, NoHeadException
java.io.IOExceptionGitAPIExceptionNoMessageExceptionUnmergedPathsExceptionConcurrentRefUpdateExceptionWrongRepositoryStateExceptionNoHeadExceptionprivate void writeMergeInfo(RevCommit commitToPick, java.util.List<RevCommit> newParents) throws java.io.IOException
java.io.IOExceptionprivate java.util.List<RevCommit> getNewParents(RevCommit commitToPick) throws java.io.IOException
java.io.IOExceptionprivate void writeCurrentCommit(RevCommit commit) throws java.io.IOException
java.io.IOExceptionprivate void writeRewrittenHashes()
throws RevisionSyntaxException,
java.io.IOException,
RefNotFoundException
RevisionSyntaxExceptionjava.io.IOExceptionRefNotFoundExceptionprivate RebaseResult finishRebase(RevCommit finalHead, boolean lastStepIsForward) throws java.io.IOException, GitAPIException
java.io.IOExceptionGitAPIExceptionprivate void checkSteps(java.util.List<RebaseTodoLine> steps) throws InvalidRebaseStepException, java.io.IOException
InvalidRebaseStepExceptionjava.io.IOExceptionprivate RevCommit doSquashFixup(boolean isSquash, RevCommit commitToPick, RebaseTodoLine nextStep, java.io.File messageFixup, java.io.File messageSquash) throws java.io.IOException, GitAPIException
java.io.IOExceptionGitAPIExceptionprivate void resetSoftToParent()
throws java.io.IOException,
GitAPIException,
CheckoutConflictException
java.io.IOExceptionGitAPIExceptionCheckoutConflictExceptionprivate RevCommit squashIntoPrevious(boolean sequenceContainsSquash, RebaseTodoLine nextStep) throws java.io.IOException, GitAPIException
java.io.IOExceptionGitAPIExceptionprivate static java.lang.String stripCommentLines(java.lang.String commitMessage)
private static java.lang.String composeSquashMessage(boolean isSquash,
RevCommit commitToPick,
java.lang.String currSquashMessage,
int count)
private static java.lang.String getOrdinal(int count)
static int parseSquashFixupSequenceCount(java.lang.String currSquashMessage)
currSquashMessage - the squashed commit message to be parsedprivate void initializeSquashFixupFile(java.lang.String messageFile,
java.lang.String fullMessage)
throws java.io.IOException
java.io.IOExceptionprivate java.lang.String getOurCommitName()
private void updateHead(java.lang.String headName,
RevCommit aNewHead,
RevCommit onto)
throws java.io.IOException
java.io.IOExceptionprivate RevCommit checkoutCurrentHead() throws java.io.IOException, NoHeadException
java.io.IOExceptionNoHeadExceptionprivate RevCommit continueRebase() throws GitAPIException, java.io.IOException
GitAPIExceptionjava.io.IOExceptionprivate PersonIdent parseAuthor() throws java.io.IOException
java.io.IOExceptionprivate RebaseResult stop(RevCommit commitToPick, RebaseResult.Status status) throws java.io.IOException
java.io.IOExceptionjava.lang.String toAuthorScript(PersonIdent author)
private void popSteps(int numSteps)
throws java.io.IOException
git-rebase-todo file but preserves comments and other lines
that can not be parsed as stepsnumSteps - java.io.IOExceptionprivate RebaseResult initFilesAndRewind() throws java.io.IOException, GitAPIException
java.io.IOExceptionGitAPIExceptionprivate java.util.List<RevCommit> calculatePickList(RevCommit headCommit) throws GitAPIException, NoHeadException, java.io.IOException
GitAPIExceptionNoHeadExceptionjava.io.IOExceptionprivate static java.lang.String getHeadName(Ref head)
private Ref getHead() throws java.io.IOException, RefNotFoundException
java.io.IOExceptionRefNotFoundExceptionprivate boolean isInteractive()
public RevCommit tryFastForward(RevCommit newCommit) throws java.io.IOException, GitAPIException
newCommit - a RevCommit object to check
if we can fast-forward to.java.io.IOExceptionGitAPIExceptionprivate RevCommit tryFastForward(java.lang.String headName, RevCommit oldCommit, RevCommit newCommit) throws java.io.IOException, GitAPIException
java.io.IOExceptionGitAPIExceptionprivate void checkParameters()
throws WrongRepositoryStateException
WrongRepositoryStateExceptionprivate RebaseResult abort(RebaseResult result) throws java.io.IOException, GitAPIException
java.io.IOExceptionGitAPIExceptionprivate boolean checkoutCommit(java.lang.String headName,
RevCommit commit)
throws java.io.IOException,
CheckoutConflictException
java.io.IOExceptionCheckoutConflictExceptionpublic RebaseCommand setUpstream(RevCommit upstream)
RevCommitupstream - the upstream committhispublic RebaseCommand setUpstream(AnyObjectId upstream)
upstream - id of the upstream committhispublic RebaseCommand setUpstream(java.lang.String upstream) throws RefNotFoundException
upstream - the name of the upstream branchthisRefNotFoundExceptionpublic RebaseCommand setUpstreamName(java.lang.String upstreamName)
setUpstream(org.eclipse.jgit.revwalk.RevCommit) call.upstreamName - the name which will be used to refer to upstream in conflictsthispublic RebaseCommand setOperation(RebaseCommand.Operation operation)
operation - the operation to performthispublic RebaseCommand setProgressMonitor(ProgressMonitor monitor)
monitor - a progress monitorpublic RebaseCommand runInteractively(RebaseCommand.InteractiveHandler handler)
Does not stop after initialization of interactive rebase. This is
equivalent to
runInteractively(handler, false);
handler - the
RebaseCommand.InteractiveHandler
to usepublic RebaseCommand runInteractively(RebaseCommand.InteractiveHandler handler, boolean stopAfterRebaseInteractiveInitialization)
If stopAfterRebaseInteractiveInitialization is true the rebase
stops after initialization of interactive rebase returning
RebaseResult.INTERACTIVE_PREPARED_RESULT
handler - the
RebaseCommand.InteractiveHandler
to usestopAfterRebaseInteractiveInitialization - if true the rebase stops after initializationpublic RebaseCommand setStrategy(MergeStrategy strategy)
MergeStrategy.strategy - The merge strategy to use during this rebase operation.thispublic RebaseCommand setPreserveMerges(boolean preserve)
preserve - true to re-create merges during rebase. Defaults to
false, a flattening rebase.thisPersonIdent parseAuthor(byte[] raw)