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 enumValues for the "merge.conflictStyle" git config.static enumThe modes available for fast forward merges corresponding to the--ff,--no-ffand--ff-onlyoptions underbranch.<name>.mergeoptions. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Booleanprivate ContentMergeStrategyprivate MergeCommand.FastForwardModeprivate booleanprivate MergeStrategyprivate Stringprivate ProgressMonitorprivate BooleanFields inherited from class org.eclipse.jgit.api.GitCommand
repo -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMergeCommand(Repository repo) Constructor for MergeCommand. -
Method Summary
Modifier and TypeMethodDescriptioncall()private voidprivate voidUse 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 mergesetContentMergeStrategy(ContentMergeStrategy strategy) Sets the content merge strategy to use if themerge strategyis "resolve" or "recursive".setFastForward(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 voidupdateHead(StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID) Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
Field Details
-
mergeStrategy
-
contentStrategy
-
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
Mergecommand 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:
callin interfaceCallable<MergeResult>- Specified by:
callin classGitCommand<MergeResult>- Throws:
GitAPIExceptionNoHeadExceptionConcurrentRefUpdateExceptionCheckoutConflictExceptionInvalidMergeHeadsExceptionWrongRepositoryStateExceptionNoMessageException
-
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- theMergeStrategyto be used- Returns:
this
-
setContentMergeStrategy
Sets the content merge strategy to use if themerge strategyis "resolve" or "recursive".- Parameters:
strategy- theContentMergeStrategyto be used- Returns:
this- Since:
- 5.12
-
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 aRefpointing 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
trueaMergeResultwith statusMergeResult.MergeStatus.MERGED_SQUASHEDorMergeResult.MergeStatus.FAST_FORWARD_SQUASHEDis 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. Ifnulluse the value of themerge.ffoption 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-trueif this command should commit (this is the default behavior).falseif this command should not commit. In case the merge was successful but this flag was set tofalseaMergeResultwith typeMergeResultwith statusMergeResult.MergeStatus.MERGED_NOT_COMMITTEDis 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:
-