Top Description Inners Fields Constructors Methods
org.eclipse.jgit.api

public Class MergeCommand

extends GitCommand<MergeResult>
Class Inheritance
Imports
java.io.IOException, java.text.MessageFormat, java.util.ArrayList, .Arrays, .Collections, .List, .Locale, .Map, org.eclipse.jgit.annotations.Nullable, org.eclipse.jgit.api.MergeResult.MergeStatus, org.eclipse.jgit.api.errors.CheckoutConflictException, .ConcurrentRefUpdateException, .GitAPIException, .InvalidMergeHeadsException, .JGitInternalException, .NoHeadException, .NoMessageException, .WrongRepositoryStateException, org.eclipse.jgit.dircache.DirCacheCheckout, org.eclipse.jgit.events.WorkingTreeModifiedEvent, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.AnyObjectId, .CommitConfig, .Config.ConfigEnum, .Constants, .NullProgressMonitor, .ObjectId, .ObjectIdRef, .ProgressMonitor, .Ref, .Ref.Storage, .RefUpdate, .RefUpdate.Result, .Repository, org.eclipse.jgit.merge.ContentMergeStrategy, .MergeConfig, .MergeMessageFormatter, .MergeStrategy, .Merger, .ResolveMerger, .ResolveMerger.MergeFailureReason, .SquashMessageFormatter, org.eclipse.jgit.revwalk.RevCommit, .RevWalk, .RevWalkUtils, org.eclipse.jgit.treewalk.FileTreeIterator, org.eclipse.jgit.util.StringUtils

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
Git documentation about Merge

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
MergeCommand.ConflictStyle

Values for the "merge.conflictStyle" git config.

public static enum
MergeCommand.FastForwardMode

The modes available for fast forward merges corresponding to the --ff, --no-ff and --ff-only options under branch.

Field Summary

Modifier and TypeField and Description
private Boolean
private List<Ref>
private ContentMergeStrategy
private MergeCommand.FastForwardMode
private boolean
private MergeStrategy
private String
private ProgressMonitor
private Boolean
Inherited from org.eclipse.jgit.api.GitCommand:
repo

Constructor Summary

AccessConstructor and Description
protected
MergeCommand(Repository repo)

Constructor for MergeCommand.

Method Summary

Modifier and TypeMethod and Description
public MergeResult
call()

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

private void
private void
fallBackToConfiguration()

Use values from the configuration if they have not been explicitly defined via the setters

public MergeCommand

Returns:

this
include
(Ref
a reference to a commit which is merged with the current head
aCommit
)

Reference to a commit to be merged with the current head

public MergeCommand

Returns:

this
include
(AnyObjectId
the Id of a commit which is merged with the current head
aCommit
)

Id of a commit which is to be merged with the current head

public MergeCommand

Returns:

this
include
(String
a name of a Ref pointing to the commit
name
,
AnyObjectId
the Id of a commit which is merged with the current head
aCommit
)

Include a commit

public MergeCommand

Returns:

this
setCommit
(boolean
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 to false a org.eclipse.jgit.api.MergeResult with type org.eclipse.jgit.api.MergeResult with status org.eclipse.jgit.api.MergeResult.MergeStatus#MERGED_NOT_COMMITTED is returned
commit
)

Controls whether the merge command should automatically commit after a successful merge

public MergeCommand

Returns:

this
setContentMergeStrategy
(ContentMergeStrategy
the ContentMergeStrategy to be used
strategy
)

Sets the content merge strategy to use if the merge strategy is "resolve" or "recursive".

public MergeCommand

Returns:

this
setFastForward
(MergeCommand.FastForwardMode
corresponds to the --ff/--no-ff/--ff-only options. If null use the value of the merge.ff option configured in git config. If this option is not configured --ff is the built-in default.
fastForwardMode
)

Sets the fast forward mode.

public MergeCommand

Returns:

this
setInsertChangeId
(boolean
whether to insert a change id
insertChangeId
)

If set to true a change id will be inserted into the commit message An existing change id is not replaced.

public MergeCommand

Returns:

this
setMessage
(String
the message to be used for the merge commit
message
)

Set the commit message to be used for the merge commit (in case one is created)

public MergeCommand

Returns:

this instance
setProgressMonitor
(ProgressMonitor
A progress monitor
monitor
)

The progress monitor associated with the diff operation.

public MergeCommand

Returns:

this
setSquash
(boolean
whether to squash commits or not
squash
)

If true, 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.

public MergeCommand

Returns:

this
setStrategy
(MergeStrategy mergeStrategy)

Set merge strategy

private void
updateHead(StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID)

Inherited from org.eclipse.jgit.api.GitCommand:
checkCallablegetRepositorysetCallable

Field Detail

commitback to summary
private Boolean commit
commitsback to summary
private List<Ref> commits
contentStrategyback to summary
private ContentMergeStrategy contentStrategy
fastForwardModeback to summary
private MergeCommand.FastForwardMode fastForwardMode
insertChangeIdback to summary
private boolean insertChangeId
mergeStrategyback to summary
private MergeStrategy mergeStrategy
messageback to summary
private String message
monitorback to summary
private ProgressMonitor monitor
squashback to summary
private Boolean squash

Constructor Detail

MergeCommandback to summary
protected MergeCommand(Repository repo)

Constructor for MergeCommand.

Parameters
repo:Repository

the org.eclipse.jgit.lib.Repository

Method Detail

callback to summary
public MergeResult call() throws GitAPIException, NoHeadException, ConcurrentRefUpdateException, CheckoutConflictException, InvalidMergeHeadsException, WrongRepositoryStateException, NoMessageException

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Doc from org.eclipse.jgit.api.GitCommand.call.

Computes a result, or throws an exception if unable to do so.

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.

Returns:MergeResult

Doc from java.util.concurrent.Callable.call.

computed result

Annotations
@Override
@SuppressWarnings:boxing
checkParametersback to summary
private void checkParameters() throws InvalidMergeHeadsException
fallBackToConfigurationback to summary
private void fallBackToConfiguration()

Use values from the configuration if they have not been explicitly defined via the setters

includeback to summary
public MergeCommand include(Ref aCommit)

Reference to a commit to be merged with the current head

Parameters
aCommit:Ref

a reference to a commit which is merged with the current head

Returns:MergeCommand

this

includeback to summary
public MergeCommand include(AnyObjectId aCommit)

Id of a commit which is to be merged with the current head

Parameters
aCommit:AnyObjectId

the Id of a commit which is merged with the current head

Returns:MergeCommand

this

includeback to summary
public MergeCommand include(String name, AnyObjectId aCommit)

Include a commit

Parameters
name:String

a name of a Ref pointing to the commit

aCommit:AnyObjectId

the Id of a commit which is merged with the current head

Returns:MergeCommand

this

setCommitback to summary
public MergeCommand setCommit(boolean commit)

Controls whether the merge command should automatically commit after a successful merge

Parameters
commit:boolean

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 to false a org.eclipse.jgit.api.MergeResult with type org.eclipse.jgit.api.MergeResult with status org.eclipse.jgit.api.MergeResult.MergeStatus#MERGED_NOT_COMMITTED is returned

Returns:MergeCommand

this

Since
3.0
setContentMergeStrategyback to summary
public MergeCommand setContentMergeStrategy(ContentMergeStrategy strategy)

Sets the content merge strategy to use if the merge strategy is "resolve" or "recursive".

Parameters
strategy:ContentMergeStrategy

the ContentMergeStrategy to be used

Returns:MergeCommand

this

Since
5.12
setFastForwardback to summary
public MergeCommand setFastForward(MergeCommand.FastForwardMode fastForwardMode)

Sets the fast forward mode.

Parameters
fastForwardMode:MergeCommand.FastForwardMode

corresponds to the --ff/--no-ff/--ff-only options. If null use the value of the merge.ff option configured in git config. If this option is not configured --ff is the built-in default.

Returns:MergeCommand

this

Since
2.2
setInsertChangeIdback to summary
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:boolean

whether to insert a change id

Returns:MergeCommand

this

Since
5.0
setMessageback to summary
public MergeCommand setMessage(String message)

Set the commit message to be used for the merge commit (in case one is created)

Parameters
message:String

the message to be used for the merge commit

Returns:MergeCommand

this

Since
3.5
setProgressMonitorback to summary
public MergeCommand setProgressMonitor(ProgressMonitor monitor)

The progress monitor associated with the diff operation. By default, this is set to NullProgressMonitor

Parameters
monitor:ProgressMonitor

A progress monitor

Returns:MergeCommand

this instance

Since
4.2
See Also
NullProgressMonitor
setSquashback to summary
public MergeCommand setSquash(boolean squash)

If true, 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 a org.eclipse.jgit.api.MergeResult with status org.eclipse.jgit.api.MergeResult.MergeStatus#MERGED_SQUASHED or org.eclipse.jgit.api.MergeResult.MergeStatus#FAST_FORWARD_SQUASHED is returned.

Parameters
squash:boolean

whether to squash commits or not

Returns:MergeCommand

this

Since
2.0
setStrategyback to summary
public MergeCommand setStrategy(MergeStrategy mergeStrategy)

Set merge strategy

Parameters
mergeStrategy:MergeStrategy

the org.eclipse.jgit.merge.MergeStrategy to be used

Returns:MergeCommand

this

updateHeadback to summary
private void updateHead(StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID) throws IOException, ConcurrentRefUpdateException
org.eclipse.jgit.api back to summary

public final Enum MergeCommand.ConflictStyle

extends Enum<MergeCommand.ConflictStyle>
Class Inheritance

Values for the "merge.conflictStyle" git config.
Since
5.12

Field Summary

Modifier and TypeField and Description
public static final MergeCommand.ConflictStyle
DIFF3

"diff3" style: ours/base/theirs.

public static final MergeCommand.ConflictStyle
MERGE

"merge" style: only ours/theirs.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static MergeCommand.ConflictStyle
public static MergeCommand.ConflictStyle[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DIFF3back to summary
public static final MergeCommand.ConflictStyle DIFF3

"diff3" style: ours/base/theirs.

MERGEback to summary
public static final MergeCommand.ConflictStyle MERGE

"merge" style: only ours/theirs. This is the default.

Constructor Detail

ConflictStyleback to summary
private ConflictStyle()

Method Detail

valueOfback to summary
public static MergeCommand.ConflictStyle valueOf(String name)
valuesback to summary
public static MergeCommand.ConflictStyle[] values()
org.eclipse.jgit.api back to summary

public final Enum MergeCommand.FastForwardMode

extends Enum<MergeCommand.FastForwardMode>
implements ConfigEnum
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.lib.Config.ConfigEnum

The modes available for fast forward merges corresponding to the --ff, --no-ff and --ff-only options under branch.<name>.mergeoptions.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
MergeCommand.FastForwardMode.Merge

The modes available for fast forward merges corresponding to the options under merge.ff.

Field Summary

Modifier and TypeField and Description
public static final MergeCommand.FastForwardMode
FF

Corresponds to the default --ff option (for a fast forward update the branch pointer only).

public static final MergeCommand.FastForwardMode
FF_ONLY

Corresponds to the --ff-only option (abort unless the merge is a fast forward).

public static final MergeCommand.FastForwardMode
NO_FF

Corresponds to the --no-ff option (create a merge commit even for a fast forward).

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
matchConfigValue(String
the string to match
in
)

Implements org.eclipse.jgit.lib.Config.ConfigEnum.matchConfigValue.

Checks if the given string matches with enum value.

public String
toConfigValue()

Implements org.eclipse.jgit.lib.Config.ConfigEnum.toConfigValue.

Converts enumeration value into a string to be save in config.

public static MergeCommand.FastForwardMode
public static MergeCommand.FastForwardMode

Returns:

the mapped FastForwardMode value
valueOf
(MergeCommand.FastForwardMode.Merge
the FastForwardMode.Merge value to be mapped
ffMode
)

Map from FastForwardMode.Merge to FastForwardMode.

public static MergeCommand.FastForwardMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FFback to summary
public static final MergeCommand.FastForwardMode FF

Corresponds to the default --ff option (for a fast forward update the branch pointer only).

FF_ONLYback to summary
public static final MergeCommand.FastForwardMode FF_ONLY

Corresponds to the --ff-only option (abort unless the merge is a fast forward).

NO_FFback to summary
public static final MergeCommand.FastForwardMode NO_FF

Corresponds to the --no-ff option (create a merge commit even for a fast forward).

Constructor Detail

FastForwardModeback to summary
private FastForwardMode()

Method Detail

matchConfigValueback to summary
public boolean matchConfigValue(String in)

Implements org.eclipse.jgit.lib.Config.ConfigEnum.matchConfigValue.

Doc from org.eclipse.jgit.lib.Config.ConfigEnum.matchConfigValue.

Checks if the given string matches with enum value.

Parameters
in:String

the string to match

Returns:boolean

true if the given string matches enum value, false otherwise

Annotations
@Override
toConfigValueback to summary
public String toConfigValue()

Implements org.eclipse.jgit.lib.Config.ConfigEnum.toConfigValue.

Doc from org.eclipse.jgit.lib.Config.ConfigEnum.toConfigValue.

Converts enumeration value into a string to be save in config.

Returns:String

the enum value as config string

Annotations
@Override
valueOfback to summary
public static MergeCommand.FastForwardMode valueOf(String name)
valueOfback to summary
public static MergeCommand.FastForwardMode valueOf(MergeCommand.FastForwardMode.Merge ffMode)

Map from FastForwardMode.Merge to FastForwardMode.

Parameters
ffMode:MergeCommand.FastForwardMode.Merge

the FastForwardMode.Merge value to be mapped

Returns:MergeCommand.FastForwardMode

the mapped FastForwardMode value

valuesback to summary
public static MergeCommand.FastForwardMode[] values()
org.eclipse.jgit.api back to summary

public final Enum MergeCommand.FastForwardMode.Merge

extends Enum<MergeCommand.FastForwardMode.Merge>
Class Inheritance

The modes available for fast forward merges corresponding to the options under merge.ff.

Field Summary

Modifier and TypeField and Description
public static final MergeCommand.FastForwardMode.Merge
public static final MergeCommand.FastForwardMode.Merge
public static final MergeCommand.FastForwardMode.Merge

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static MergeCommand.FastForwardMode.Merge
public static MergeCommand.FastForwardMode.Merge

Returns:

the mapped FastForwardMode.Merge value
valueOf
(MergeCommand.FastForwardMode
the FastForwardMode value to be mapped
ffMode
)

Map from FastForwardMode to FastForwardMode.Merge.

public static MergeCommand.FastForwardMode.Merge[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Constructor Detail

Mergeback to summary
private Merge()

Method Detail

valueOfback to summary
public static MergeCommand.FastForwardMode.Merge valueOf(String name)
valueOfback to summary
public static MergeCommand.FastForwardMode.Merge valueOf(MergeCommand.FastForwardMode ffMode)

Map from FastForwardMode to FastForwardMode.Merge.

Parameters
ffMode:MergeCommand.FastForwardMode

the FastForwardMode value to be mapped

Returns:MergeCommand.FastForwardMode.Merge

the mapped FastForwardMode.Merge value

valuesback to summary
public static MergeCommand.FastForwardMode.Merge[] values()