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.FastForwardMode
The modes available for fast forward merges corresponding to the--ff
,--no-ff
and--ff-only
options underbranch.<name>.mergeoptions
.
-
Field Summary
-
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MergeCommand(Repository repo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MergeResult
call()
Executes theMerge
command with all the options and parameters collected by the setter methods (e.g.MergeCommand
include(java.lang.String name, AnyObjectId aCommit)
MergeCommand
include(AnyObjectId aCommit)
MergeCommand
include(Ref aCommit)
MergeCommand
setCommit(boolean commit)
Controls whether the merge command should automatically commit after a successful mergeMergeCommand
setFastForward(MergeCommand.FastForwardMode fastForwardMode)
Sets the fast forward mode.MergeCommand
setMessage(java.lang.String message)
Set the commit message to be used for the merge commit (in case one is created)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)
-
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
-
-
-
Constructor Detail
-
MergeCommand
protected MergeCommand(Repository repo)
- Parameters:
repo
-
-
-
Method Detail
-
call
public MergeResult call() throws GitAPIException, NoHeadException, ConcurrentRefUpdateException, CheckoutConflictException, InvalidMergeHeadsException, WrongRepositoryStateException, NoMessageException
Executes theMerge
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>
- Returns:
- the result of the merge
- Throws:
GitAPIException
- or subclass thereof when an error occursNoHeadException
ConcurrentRefUpdateException
CheckoutConflictException
InvalidMergeHeadsException
WrongRepositoryStateException
NoMessageException
-
setStrategy
public MergeCommand setStrategy(MergeStrategy mergeStrategy)
- Parameters:
mergeStrategy
- theMergeStrategy
to be used- Returns:
this
-
include
public MergeCommand include(Ref aCommit)
- Parameters:
aCommit
- a reference to a commit which is merged with the current head- Returns:
this
-
include
public MergeCommand include(AnyObjectId aCommit)
- 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)
- Parameters:
name
- a name given 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(MergeCommand.FastForwardMode fastForwardMode)
Sets the fast forward mode.- Parameters:
fastForwardMode
- corresponds to the --ff/--no-ff/--ff-only options. --ff is the default option.- 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
-
-