From 35e4fbc32caef2949a1df3089baeda23081a8f6e Mon Sep 17 00:00:00 2001 From: Rastislav Graus Date: Tue, 18 May 2021 17:36:44 +0200 Subject: [PATCH 1/4] Create next development version in release branch before merge with development branch #282 --- .../gitflow/GitFlowReleaseFinishMojo.java | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) 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 03c684a8..67e2e146 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java @@ -24,7 +24,9 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.shared.release.versions.VersionParseException; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.cli.CommandLineException; /** * The git flow release finish mojo. @@ -167,6 +169,15 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "skipReleaseMergeProdBranch", defaultValue = "false") private boolean skipReleaseMergeProdBranch = false; + /** + * Whether to merge development or release version to development branch.
+ * Will have no effect if the commitDevelopmentVersionAtStart parameter is set to true. + * + * @since 1.16.1 + */ + @Parameter(property = "mergeDevelopmentVersion", defaultValue = "false") + private boolean mergeDevelopmentVersion; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -291,6 +302,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (notSameProdDevName()) { + if (!commitDevelopmentVersionAtStart && mergeDevelopmentVersion) { + gitCheckout(releaseBranch); + commitSnapshotVersion(currentVersion); + } + // git checkout develop gitCheckout(gitFlowConfig.getDevelopmentBranch()); @@ -325,34 +341,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (!commitDevelopmentVersionAtStart) { - // get next snapshot version - final String nextSnapshotVersion; - if (!settings.isInteractiveMode() - && StringUtils.isNotBlank(developmentVersion)) { - nextSnapshotVersion = developmentVersion; - } else { - GitFlowVersionInfo versionInfo = new GitFlowVersionInfo( - currentVersion); - if (digitsOnlyDevVersion) { - versionInfo = versionInfo.digitsVersionInfo(); - } - - nextSnapshotVersion = versionInfo - .nextSnapshotVersion(versionDigitToIncrement); - } - - if (StringUtils.isBlank(nextSnapshotVersion)) { - throw new MojoFailureException( - "Next snapshot version is blank."); - } - - // mvn versions:set -DnewVersion=... -DgenerateBackupPoms=false - mvnSetVersions(nextSnapshotVersion); - - messageProperties.put("version", nextSnapshotVersion); - - // git commit -a -m updating for next development version - gitCommit(commitMessages.getReleaseFinishMessage(), messageProperties); + commitSnapshotVersion(currentVersion); } if (installProject) { @@ -379,4 +368,32 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoFailureException("release-finish", e); } } + + private void commitSnapshotVersion(final String currentVersion) throws MojoFailureException, VersionParseException, CommandLineException { + // get next snapshot version + final String nextSnapshotVersion; + if (!settings.isInteractiveMode() && StringUtils.isNotBlank(developmentVersion)) { + nextSnapshotVersion = developmentVersion; + } else { + GitFlowVersionInfo versionInfo = new GitFlowVersionInfo(currentVersion); + if (digitsOnlyDevVersion) { + versionInfo = versionInfo.digitsVersionInfo(); + } + + nextSnapshotVersion = versionInfo.nextSnapshotVersion(versionDigitToIncrement); + } + + if (StringUtils.isBlank(nextSnapshotVersion)) { + throw new MojoFailureException("Next snapshot version is blank."); + } + + // mvn versions:set -DnewVersion=... -DgenerateBackupPoms=false + mvnSetVersions(nextSnapshotVersion); + + final Map messageProperties = new HashMap<>(); + messageProperties.put("version", nextSnapshotVersion); + + // git commit -a -m updating for next development version + gitCommit(commitMessages.getReleaseFinishMessage(), messageProperties); + } } From 3510dab5805e929420f33f246c1c331f36c22dfe Mon Sep 17 00:00:00 2001 From: Rastislav Graus Date: Tue, 18 May 2021 17:42:04 +0200 Subject: [PATCH 2/4] Adding space between message prefix and message in commit --- .../amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 24f1ff86..e18ce23c 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -686,7 +686,7 @@ protected void gitCommit(final String message) throws MojoFailureException, protected void gitCommit(String message, Map messageProperties) throws MojoFailureException, CommandLineException { if (StringUtils.isNotBlank(commitMessagePrefix)) { - message = commitMessagePrefix + message; + message = commitMessagePrefix + " " + message; } message = replaceProperties(message, messageProperties); @@ -731,7 +731,7 @@ protected void gitMerge(final String branchName, boolean rebase, boolean noff, b String msg = ""; if (StringUtils.isNotBlank(message)) { if (StringUtils.isNotBlank(commitMessagePrefix)) { - message = commitMessagePrefix + message; + message = commitMessagePrefix + " " + message; } msgParam = "-m"; From 816043c4b824377d312fcc6fb6166c98862e0564 Mon Sep 17 00:00:00 2001 From: Rastislav Graus Date: Thu, 20 May 2021 08:43:01 +0200 Subject: [PATCH 3/4] Revert "Adding space between message prefix and message in commit" This reverts commit 3510dab5805e929420f33f246c1c331f36c22dfe. --- .../amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e18ce23c..24f1ff86 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -686,7 +686,7 @@ protected void gitCommit(final String message) throws MojoFailureException, protected void gitCommit(String message, Map messageProperties) throws MojoFailureException, CommandLineException { if (StringUtils.isNotBlank(commitMessagePrefix)) { - message = commitMessagePrefix + " " + message; + message = commitMessagePrefix + message; } message = replaceProperties(message, messageProperties); @@ -731,7 +731,7 @@ protected void gitMerge(final String branchName, boolean rebase, boolean noff, b String msg = ""; if (StringUtils.isNotBlank(message)) { if (StringUtils.isNotBlank(commitMessagePrefix)) { - message = commitMessagePrefix + " " + message; + message = commitMessagePrefix + message; } msgParam = "-m"; From aa6e60ce77c6086fa540036ddcc8a5f66a777624 Mon Sep 17 00:00:00 2001 From: Rastislav Graus Date: Thu, 20 May 2021 09:29:25 +0200 Subject: [PATCH 4/4] Introducing new parameter in documentation --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 46205443..c64f2f78 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,12 @@ Then the development branch is set to the next development version. This allows the development branch to continue immediately with a new version and helps avoid any future merge conflicts related to project versioning. Has effect only when there are separate development and production branches. +The `gitflow:release-finish` goal has `mergeDevelopmentVersion` parameter which controls whether the release version or next development version will be merged from release branch into develop branch. +By default the value is `false` which means that the next development version is set on the development branch after the release branch has been merged onto the development branch when finishing the release. +If the value is `true` then the released version from release branch is merged to master branch and then is the next development version set on the release branch and merged into develop branch. +This preserve ability to continue immediately with a new version in the development branch and any future merge conflicts related to project versioning are still avoided. Moreover no release version is committed to develop branch so continuous build and deploy tools can save work on development branch. +Has effect only when there are separate development and production branches and the `commitDevelopmentVersionAtStart` parameter is not set to true. + The `gitflow:release-start` goal has `sameBranchName` parameter which can be used to use the same name for the release branch. The default value is `false`. By itself the default `releaseBranchPrefix` is not a valid branch name. You must change it when setting `sameBranchName` to `true`. Will have no effect if the `branchName` parameter is set.