Package sonia.scm.repository.api
Class MergeCommandBuilder
java.lang.Object
sonia.scm.repository.api.MergeCommandBuilder
Use this
MergeCommandBuilder
to merge two branches of a repository (executeMerge()
) or to check if
the branches could be merged without conflicts (dryRun()
). To do so, you have to specify the name of
the target branch (setTargetBranch(String)
) and the name of the branch that should be merged
(setBranchToMerge(String)
). Additionally you can specify an author that should be used for the commit
(setAuthor(Person)
) and a message template (setMessageTemplate(String)
) if you are not doing a dry
run only. If no author is specified, the logged in user and a default message will be used instead.
To actually merge feature_branch
into integration_branch
do this:
repositoryService.getMergeCommand()
.setBranchToMerge("feature_branch")
.setTargetBranch("integration_branch")
.executeMerge();
If the merge is successful, the result will look like this:
O <- Merge result (new head of integration_branch)
|\
| \
old integration_branch -> O O <- feature_branch
| |
O O
To check whether they can be merged without conflicts beforehand do this:
repositoryService.getMergeCommand()
.setBranchToMerge("feature_branch")
.setTargetBranch("integration_branch")
.dryRun()
.isMergeable();
Keep in mind that you should always check the result of a merge even though you may have done a dry run
beforehand, because the branches can change between the dry run and the actual merge.- Since:
- 2.0.0
-
Method Summary
Modifier and TypeMethodDescriptionUse this to compute concrete conflicts for a merge.Disables adding a verifiable signature to the merge commit.dryRun()
Use this to check whether the given branches can be merged automatically.Use this to actually do the merge.Use this to get a Set of all supported merge strategies by merge command.boolean
isSupported
(MergeStrategy strategy) Use this to check if merge-strategy is supported by mergeCommand.reset()
Use this to reset the command.Deprecated.setAuthor
(DisplayUser author) Use this to set the author of the merge commit manually.setBranchToMerge
(String branchToMerge) Use this to set the branch that should be merged into the target branch.setMergeStrategy
(MergeStrategy strategy) Use this to set the strategy of the merge commit manually.setMessage
(String message) Use this to set the commit message.setMessageTemplate
(String messageTemplate) Use this to set a template for the commit message.setTargetBranch
(String targetBranch) Use this to set the target branch the other branch should be merged into.
-
Method Details
-
isSupported
Use this to check if merge-strategy is supported by mergeCommand.- Returns:
- boolean.
-
getSupportedMergeStrategies
Use this to get a Set of all supported merge strategies by merge command.- Returns:
- boolean.
-
setBranchToMerge
Use this to set the branch that should be merged into the target branch. This is mandatory.- Returns:
- This builder instance.
-
setTargetBranch
Use this to set the target branch the other branch should be merged into. This is mandatory.- Returns:
- This builder instance.
-
setAuthor
Deprecated.UsesetAuthor(DisplayUser)
instead to enable fallback email computation.Use this to set the author of the merge commit manually. If this is omitted, the currently logged-in user will be used instead. This is optional and forexecuteMerge()
only.- Returns:
- This builder instance.
-
setAuthor
Use this to set the author of the merge commit manually. If this is omitted, the currently logged-in user will be used instead. If the given user object does not have an email address, we will useEMail
to compute a fallback address. This is optional and forexecuteMerge()
only.- Returns:
- This builder instance.
-
disableSigning
Disables adding a verifiable signature to the merge commit.- Returns:
- This builder instance.
- Since:
- 2.4.0
-
setMergeStrategy
Use this to set the strategy of the merge commit manually. This is optional and forexecuteMerge()
only.- Returns:
- This builder instance.
-
setMessageTemplate
Use this to set a template for the commit message. If no message is set, a default message will be used. You can use the placeholder{0}
for the branch to be merged and{1}
for the target branch, eg.:
This is optional and for...setMessageTemplate("Merge of {0} into {1}")...
executeMerge()
only.- Returns:
- This builder instance.
-
setMessage
Use this to set the commit message. If no message is set, the message template will be used. This is optional and forexecuteMerge()
only.- Returns:
- This builder instance.
-
reset
Use this to reset the command.- Returns:
- This builder instance.
-
executeMerge
Use this to actually do the merge. If an automatic merge is not possible,MergeCommandResult.isSuccess()
will returnfalse
.- Returns:
- The result of the merge.
-
dryRun
Use this to check whether the given branches can be merged automatically. If this is possible,MergeDryRunCommandResult.isMergeable()
will returntrue
.- Returns:
- The result whether the given branches can be merged automatically.
-
conflicts
Use this to compute concrete conflicts for a merge.- Returns:
- A result containing all conflicts for the merge.
-
setAuthor(DisplayUser)
instead to enable fallback email computation.