Package org.eclipse.jgit.api
Class MergeCommand
- All Implemented Interfaces:
Callable<MergeResult>
A class used to execute a
Merge
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 enum
The modes available for fast forward merges corresponding to the--ff
,--no-ff
and--ff-only
options underbranch.<name>.mergeoptions
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Boolean
private MergeCommand.FastForwardMode
private boolean
private MergeStrategy
private String
private ProgressMonitor
private Boolean
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
MergeCommand
(Repository repo) Constructor for MergeCommand. -
Method Summary
Modifier and TypeMethodDescriptioncall()
private void
private void
Use values from the configuration if they have not been explicitly defined via the settersinclude
(String name, AnyObjectId aCommit) Include a commitinclude
(AnyObjectId aCommit) Id of a commit which is to be merged with the current headReference to a commit to be merged with the current headsetCommit
(boolean commit) Controls whether the merge command should automatically commit after a successful mergesetFastForward
(MergeCommand.FastForwardMode fastForwardMode) Sets the fast forward mode.setInsertChangeId
(boolean insertChangeId) If set to true a change id will be inserted into the commit message An existing change id is not replaced.setMessage
(String message) Set the commit message to be used for the merge commit (in case one is created)setProgressMonitor
(ProgressMonitor monitor) The progress monitor associated with the diff operation.setSquash
(boolean squash) Iftrue
, will prepare the next commit in working tree and index as if a real merge happened, but do not make the commit or move the HEAD.setStrategy
(MergeStrategy mergeStrategy) Set merge strategyprivate void
updateHead
(StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID) Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
Field Details
-
mergeStrategy
-
commits
-
squash
-
fastForwardMode
-
message
-
insertChangeId
private boolean insertChangeId -
monitor
-
commit
-
-
Constructor Details
-
MergeCommand
Constructor for MergeCommand.- Parameters:
repo
- theRepository
-
-
Method Details
-
call
public MergeResult call() throws GitAPIException, NoHeadException, ConcurrentRefUpdateException, CheckoutConflictException, InvalidMergeHeadsException, WrongRepositoryStateException, NoMessageExceptionExecute the command
Execute the
Merge
command with all the options and parameters collected by the setter methods (e.g.include(Ref)
) 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<MergeResult>
- Specified by:
call
in classGitCommand<MergeResult>
- Throws:
GitAPIException
NoHeadException
ConcurrentRefUpdateException
CheckoutConflictException
InvalidMergeHeadsException
WrongRepositoryStateException
NoMessageException
-
checkParameters
- Throws:
InvalidMergeHeadsException
-
fallBackToConfiguration
private void fallBackToConfiguration()Use values from the configuration if they have not been explicitly defined via the setters -
updateHead
private void updateHead(StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID) throws IOException, ConcurrentRefUpdateException -
setStrategy
Set merge strategy- Parameters:
mergeStrategy
- theMergeStrategy
to be used- Returns:
this
-
include
Reference to a commit to be merged with the current head- Parameters:
aCommit
- a reference to a commit which is merged with the current head- Returns:
this
-
include
Id of a commit which is to be merged with the current head- Parameters:
aCommit
- the Id of a commit which is merged with the current head- Returns:
this
-
include
Include a commit- Parameters:
name
- a name of aRef
pointing to the commitaCommit
- the Id of a commit which is merged with the current head- Returns:
this
-
setSquash
Iftrue
, will prepare the next commit in working tree and index as if a real merge happened, but do not make the commit or move the HEAD. Otherwise, perform the merge and commit the result.In case the merge was successful but this flag was set to
true
aMergeResult
with statusMergeResult.MergeStatus.MERGED_SQUASHED
orMergeResult.MergeStatus.FAST_FORWARD_SQUASHED
is returned.- Parameters:
squash
- whether to squash commits or not- Returns:
this
- Since:
- 2.0
-
setFastForward
Sets the fast forward mode.- Parameters:
fastForwardMode
- corresponds to the --ff/--no-ff/--ff-only options. Ifnull
use the value of themerge.ff
option configured in git config. If this option is not configured --ff is the built-in default.- Returns:
this
- Since:
- 2.2
-
setCommit
Controls whether the merge command should automatically commit after a successful merge- Parameters:
commit
-true
if this command should commit (this is the default behavior).false
if this command should not commit. In case the merge was successful but this flag was set tofalse
aMergeResult
with typeMergeResult
with statusMergeResult.MergeStatus.MERGED_NOT_COMMITTED
is returned- Returns:
this
- Since:
- 3.0
-
setMessage
Set the commit message to be used for the merge commit (in case one is created)- Parameters:
message
- the message to be used for the merge commit- Returns:
this
- Since:
- 3.5
-
setInsertChangeId
If set to true a change id will be inserted into the commit message An existing change id is not replaced. An initial change id (I000...) will be replaced by the change id.- Parameters:
insertChangeId
- whether to insert a change id- Returns:
this
- Since:
- 5.0
-
setProgressMonitor
The progress monitor associated with the diff operation. By default, this is set toNullProgressMonitor
- Parameters:
monitor
- A progress monitor- Returns:
- this instance
- Since:
- 4.2
- See Also:
-