Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create next development version in release branch before merge with develop #300

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.<br/>
* Will have no effect if the <code>commitDevelopmentVersionAtStart</code> 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 {
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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) {
Expand All @@ -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<String, String> messageProperties = new HashMap<>();
messageProperties.put("version", nextSnapshotVersion);

// git commit -a -m updating for next development version
gitCommit(commitMessages.getReleaseFinishMessage(), messageProperties);
}
}