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 c6c93513..eb3a3104 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -425,6 +425,20 @@ protected void gitMergeNoff(final String branchName) gitMerge(branchName, false, true); } + /** + * Executes git merge --squash. + * + * @param branchName + * Branch name to merge. + * @throws MojoFailureException + * @throws CommandLineException + */ + protected void gitMergeSquash(final String branchName) + throws MojoFailureException, CommandLineException { + getLog().info("Squashing '" + branchName + "' branch."); + executeGitCommand("merge", "--squash", branchName); + } + /** * Executes git tag -a -m. * @@ -457,6 +471,21 @@ protected void gitBranchDelete(final String branchName) executeGitCommand("branch", "-d", branchName); } + /** + * Executes git branch -D. + * + * @param branchName + * Branch name to delete. + * @throws MojoFailureException + * @throws CommandLineException + */ + protected void gitBranchDeleteForce(final String branchName) + throws MojoFailureException, CommandLineException { + getLog().info("Deleting (-D) '" + branchName + "' branch."); + + executeGitCommand("branch", "-D", branchName); + } + /** * Executes 'set' goal of versions-maven-plugin or 'set-version' of * tycho-versions-plugin in case it is tycho build. diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java index 541bccc2..c9a7a2c9 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java @@ -47,6 +47,15 @@ public class GitFlowFeatureFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "skipTestProject", defaultValue = "false") private boolean skipTestProject = false; + /** + * Whether to squash feature branch commits into a single commit upon + * merging. + * + * @since 1.2.3 + */ + @Parameter(property = "featureSquash", defaultValue = "false") + private boolean featureSquash = false; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -105,8 +114,14 @@ public void execute() throws MojoExecutionException, MojoFailureException { // git checkout develop gitCheckout(gitFlowConfig.getDevelopmentBranch()); - // git merge --no-ff feature/... - gitMergeNoff(featureBranchName); + if (featureSquash) { + // git merge --squash feature/... + gitMergeSquash(featureBranchName); + gitCommit(featureBranchName); + } else { + // git merge --no-ff feature/... + gitMergeNoff(featureBranchName); + } // get current project version from pom final String currentVersion = getCurrentProjectVersion(); @@ -131,8 +146,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (!keepBranch) { - // git branch -d feature/... - gitBranchDelete(featureBranchName); + if (featureSquash) { + // git branch -D feature/... + gitBranchDeleteForce(featureBranchName); + } else { + // git branch -d feature/... + gitBranchDelete(featureBranchName); + } } } catch (CommandLineException e) { getLog().error(e);