Package org.eclipse.jgit.api
Class MergeCommand
- java.lang.Object
-
- org.eclipse.jgit.api.GitCommand<MergeResult>
-
- org.eclipse.jgit.api.MergeCommand
-
- All Implemented Interfaces:
java.util.concurrent.Callable<MergeResult>
public class MergeCommand extends GitCommand<MergeResult>
A class used to execute aMerge
command. It has setters for all supported options and arguments of this command and acall()
method to finally execute the command. Each instance of this class should only be used for one invocation of the command (means: one call tocall()
)- See Also:
- Git documentation about Merge
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MergeCommand.ConflictStyle
Values for the "merge.conflictStyle" git config.static class
MergeCommand.FastForwardMode
The modes available for fast forward merges corresponding to the--ff
,--no-ff
and--ff-only
options underbranch.<name>.mergeoptions
.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Boolean
commit
private java.util.List<Ref>
commits
private ContentMergeStrategy
contentStrategy
private MergeCommand.FastForwardMode
fastForwardMode
private boolean
insertChangeId
private MergeStrategy
mergeStrategy
private java.lang.String
message
private ProgressMonitor
monitor
private java.lang.Boolean
squash
-
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MergeCommand(Repository repo)
Constructor for MergeCommand.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MergeResult
call()
private void
checkParameters()
private void
fallBackToConfiguration()
Use values from the configuration if they have not been explicitly defined via the settersMergeCommand
include(java.lang.String name, AnyObjectId aCommit)
Include a commitMergeCommand
include(AnyObjectId aCommit)
Id of a commit which is to be merged with the current headMergeCommand
include(Ref aCommit)
Reference to a commit to be merged with the current headMergeCommand
setCommit(boolean commit)
Controls whether the merge command should automatically commit after a successful mergeMergeCommand
setContentMergeStrategy(ContentMergeStrategy strategy)
Sets the content merge strategy to use if themerge strategy
is "resolve" or "recursive".MergeCommand
setFastForward(MergeCommand.FastForwardMode fastForwardMode)
Sets the fast forward mode.MergeCommand
setInsertChangeId(boolean insertChangeId)
If set to true a change id will be inserted into the commit message An existing change id is not replaced.MergeCommand
setMessage(java.lang.String message)
Set the commit message to be used for the merge commit (in case one is created)MergeCommand
setProgressMonitor(ProgressMonitor monitor)
The progress monitor associated with the diff operation.MergeCommand
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.MergeCommand
setStrategy(MergeStrategy mergeStrategy)
Set merge strategyprivate void
updateHead(java.lang.StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID)
-
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
-
-
-
Field Detail
-
mergeStrategy
private MergeStrategy mergeStrategy
-
contentStrategy
private ContentMergeStrategy contentStrategy
-
commits
private java.util.List<Ref> commits
-
squash
private java.lang.Boolean squash
-
fastForwardMode
private MergeCommand.FastForwardMode fastForwardMode
-
message
private java.lang.String message
-
insertChangeId
private boolean insertChangeId
-
monitor
private ProgressMonitor monitor
-
commit
private java.lang.Boolean commit
-
-
Constructor Detail
-
MergeCommand
protected MergeCommand(Repository repo)
Constructor for MergeCommand.- Parameters:
repo
- theRepository
-
-
Method Detail
-
call
public MergeResult call() throws GitAPIException, NoHeadException, ConcurrentRefUpdateException, CheckoutConflictException, InvalidMergeHeadsException, WrongRepositoryStateException, NoMessageException
Execute 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 interfacejava.util.concurrent.Callable<MergeResult>
- Specified by:
call
in classGitCommand<MergeResult>
- Throws:
GitAPIException
NoHeadException
ConcurrentRefUpdateException
CheckoutConflictException
InvalidMergeHeadsException
WrongRepositoryStateException
NoMessageException
-
checkParameters
private void checkParameters() throws InvalidMergeHeadsException
- 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(java.lang.StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID) throws java.io.IOException, ConcurrentRefUpdateException
- Throws:
java.io.IOException
ConcurrentRefUpdateException
-
setStrategy
public MergeCommand setStrategy(MergeStrategy mergeStrategy)
Set merge strategy- Parameters:
mergeStrategy
- theMergeStrategy
to be used- Returns:
this
-
setContentMergeStrategy
public MergeCommand setContentMergeStrategy(ContentMergeStrategy strategy)
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
-
include
public MergeCommand include(Ref aCommit)
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
public MergeCommand include(AnyObjectId aCommit)
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
public MergeCommand include(java.lang.String name, AnyObjectId aCommit)
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
public MergeCommand 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. 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
public MergeCommand setFastForward(@Nullable MergeCommand.FastForwardMode fastForwardMode)
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
public MergeCommand setCommit(boolean commit)
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
public MergeCommand setMessage(java.lang.String message)
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
public MergeCommand setInsertChangeId(boolean insertChangeId)
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
public MergeCommand setProgressMonitor(ProgressMonitor monitor)
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:
NullProgressMonitor
-
-