diff --git a/README.md b/README.md index 8dd35bc1..6c096e85 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,11 @@ Release branch can be merged with `--ff-only` option by setting `releaseMergeFFO Feature branch can be squashed before merging by setting `featureSquash` parameter to `true`. The default value is `false` (i.e. merge w/o squash will be performed). +You can also specify the optional parameter `additionalMergeOptions` for goals with merge-operations. It takes an arbitrary string, that will be appended to the merge-command. This is useful when in need for advanced options like `-Xtheirs`. + +For the `gitflow:hotfix-finish` and `gitflow:release-finish` goals it is also possible to specify different merge-options for merging into master and development-branch: +`productionBranchMergeOptions` and `devBranchMergeOptions`. + ### Running custom Maven goals The `preReleaseGoals` parameter can be used in `gitflow:release-finish` and `gitflow:release` goals to run defined Maven goals before the release. diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java index d85c23e1..21109011 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -154,6 +154,9 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { @Parameter(defaultValue = "${settings}", readonly = true) protected Settings settings; + @Parameter(property = "additionalMergeOptions") + protected String additionalMergeOptions; + /** * Initializes command line executables. * @@ -622,7 +625,7 @@ protected void gitCommit(String message, Map messageProperties) /** * Executes git rebase or git merge --ff-only or git merge --no-ff or git merge. - * + * * @param branchName * Branch name to merge. * @param rebase @@ -641,6 +644,31 @@ protected void gitCommit(String message, Map messageProperties) protected void gitMerge(final String branchName, boolean rebase, boolean noff, boolean ffonly, String message, Map messageProperties) throws MojoFailureException, CommandLineException { + gitMerge(branchName, rebase, noff, ffonly, message, messageProperties, additionalMergeOptions); + } + + /** + * Executes git rebase or git merge --ff-only or git merge --no-ff or git merge. + * + * @param branchName + * Branch name to merge. + * @param rebase + * Do rebase. + * @param noff + * Merge with --no-ff. + * @param ffonly + * Merge with --ff-only. + * @param message + * Merge commit message. + * @param additionalMergeOptions + * additional commandline options for the merge e.g. "-Xtheirs" + * + * @throws MojoFailureException + * @throws CommandLineException + */ + protected void gitMerge(final String branchName, boolean rebase, boolean noff, boolean ffonly, + final String message, Map messageProperties, final String additionalMergeOptions) + throws MojoFailureException, CommandLineException { String sign = ""; if (gpgSignCommit) { sign = "-S"; @@ -653,16 +681,16 @@ protected void gitMerge(final String branchName, boolean rebase, boolean noff, b } if (rebase) { getLog().info("Rebasing '" + branchName + "' branch."); - executeGitCommand("rebase", sign, branchName); + executeGitCommand("rebase", additionalMergeOptions, sign, branchName); } else if (ffonly) { getLog().info("Merging (--ff-only) '" + branchName + "' branch."); - executeGitCommand("merge", "--ff-only", sign, branchName); + executeGitCommand("merge", additionalMergeOptions, "--ff-only", sign, branchName); } else if (noff) { getLog().info("Merging (--no-ff) '" + branchName + "' branch."); - executeGitCommand("merge", "--no-ff", sign, branchName, msgParam, msg); + executeGitCommand("merge", additionalMergeOptions, "--no-ff", sign, branchName, msgParam, msg); } else { getLog().info("Merging '" + branchName + "' branch."); - executeGitCommand("merge", sign, branchName, msgParam, msg); + executeGitCommand("merge", additionalMergeOptions, sign, branchName, msgParam, msg); } } @@ -676,7 +704,24 @@ protected void gitMerge(final String branchName, boolean rebase, boolean noff, b */ protected void gitMergeNoff(final String branchName) throws MojoFailureException, CommandLineException { - gitMerge(branchName, false, true, false, null, null); + gitMergeNoff(branchName, additionalMergeOptions); + } + + /** + * Executes git merge --no-ff. + * + * @param branchName + * Branch name to merge. + * + * @param additionalMergeOptions + * additional commandline options for the merge e.g. "-Xtheirs" + * + * @throws MojoFailureException + * @throws CommandLineException + */ + protected void gitMergeNoff(final String branchName, final String additionalMergeOptions) + throws MojoFailureException, CommandLineException { + gitMerge(branchName, false, true, false, null, null, additionalMergeOptions); } /** diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java index a9896a4f..07c1f43f 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -109,6 +109,12 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "skipMergeDevBranch", defaultValue = "false") private boolean skipMergeDevBranch = false; + @Parameter(property = "productionBranchMergeOptions") + private String productionBranchMergeOptions; + + @Parameter(property = "devBranchMergeOptions") + private String devBranchMergeOptions; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -199,7 +205,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } // git merge --no-ff hotfix/... - gitMergeNoff(hotfixBranchName); + gitMergeNoff(hotfixBranchName, productionBranchMergeOptions); final String currentVersion = getCurrentProjectVersion(); @@ -243,7 +249,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } // git merge --no-ff hotfix/... - gitMergeNoff(hotfixBranchName); + gitMergeNoff(hotfixBranchName, devBranchMergeOptions); if (!currentVersion.equals(releaseBranchVersion)) { mvnSetVersions(releaseBranchVersion); @@ -263,7 +269,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { gitCommit(commitMessages.getHotfixVersionUpdateMessage()); // git merge --no-ff hotfix/... - gitMergeNoff(hotfixBranchName); + gitMergeNoff(hotfixBranchName, devBranchMergeOptions); // which version to increment GitFlowVersionInfo hotfixVersionInfo = new GitFlowVersionInfo( diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java index d389a7d2..601d9494 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java @@ -159,6 +159,12 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "useSnapshotInRelease", defaultValue = "false") private boolean useSnapshotInRelease; + @Parameter(property = "productionBranchMergeOptions") + private String productionBranchMergeOptions; + + @Parameter(property = "devBranchMergeOptions") + private String devBranchMergeOptions; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -239,7 +245,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { gitCheckout(gitFlowConfig.getProductionBranch()); gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF, releaseMergeFFOnly, - commitMessages.getReleaseFinishMergeMessage(), messageProperties); + commitMessages.getReleaseFinishMergeMessage(), messageProperties, productionBranchMergeOptions); // get current project version from pom final String currentVersion = getCurrentProjectVersion(); @@ -278,7 +284,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } // merge branch master into develop - gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF, false, null, null); + gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF, false, null, null, devBranchMergeOptions); if (commitDevelopmentVersionAtStart && useSnapshotInRelease) { // updating develop poms version back to pre merge state