From c4e65b14df7cd5f8aa3a9143d68ad15fb3e9116d Mon Sep 17 00:00:00 2001 From: AF090536 Date: Thu, 30 Apr 2020 12:52:09 +0200 Subject: [PATCH 1/5] Feature finish should not fail on already merged feature branch. #228 --- .../maven/plugin/gitflow/AbstractGitFlowMojo.java | 2 +- .../maven/plugin/gitflow/GitFlowFeatureFinishMojo.java | 6 +++++- 2 files changed, 6 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 ee1756fc..e695d4d5 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -342,7 +342,7 @@ protected boolean validBranchName(final String branchName) * @throws CommandLineException * @throws MojoFailureException */ - private boolean executeGitHasUncommitted() throws MojoFailureException, + protected boolean executeGitHasUncommitted() throws MojoFailureException, CommandLineException { boolean uncommited = false; 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 dadf2a15..0cfcbdf7 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java @@ -144,7 +144,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { if (featureSquash) { // git merge --squash feature/... gitMergeSquash(featureBranchName); - gitCommit(featureBranchName); + if (executeGitHasUncommitted()) { + gitCommit(featureBranchName); + } else { + getLog().info("No changes detected. Did you manually merge '" + featureBranchName + "' branch into '"+gitFlowConfig.getDevelopmentBranch()+"'?"); + } } else { // git merge --no-ff feature/... gitMergeNoff(featureBranchName, commitMessages.getFeatureFinishDevMergeMessage(), null); From 15e3ed148cfae970cb54850e874e75a7e4f1ffe3 Mon Sep 17 00:00:00 2001 From: AF090536 Date: Thu, 30 Apr 2020 18:55:38 +0200 Subject: [PATCH 2/5] #230: Hotfix finish should not bump to next development version. --- .../gitflow/GitFlowHotfixFinishMojo.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) 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 225efdf7..02b7c168 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -248,6 +248,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { gitFlowConfig.getReleaseBranchPrefix(), true); if (supportBranchName == null) { + // if release branch exists merge hotfix changes into it if (StringUtils.isNotBlank(releaseBranch)) { // git checkout release @@ -271,6 +272,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { gitCommit(commitMessages.getUpdateReleaseBackPreMergeStateMessage()); } } else if (!skipMergeDevBranch) { + // I should update the DEV version only if the hotfix + // version is superior to the DEV version + boolean shouldUpdateDevVersion = true; GitFlowVersionInfo developVersionInfo = new GitFlowVersionInfo( currentVersion); if (notSameProdDevName()) { @@ -295,32 +299,36 @@ public void execute() throws MojoExecutionException, MojoFailureException { if (developVersionInfo .compareTo(hotfixVersionInfo) < 0) { developVersionInfo = hotfixVersionInfo; + } else { + shouldUpdateDevVersion = false; } } + + if (shouldUpdateDevVersion) { + // get next snapshot version + final String nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); - // get next snapshot version - final String nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); - - if (StringUtils.isBlank(nextSnapshotVersion)) { - throw new MojoFailureException( + if (StringUtils.isBlank(nextSnapshotVersion)) { + throw new MojoFailureException( "Next snapshot version is blank."); - } + } - // mvn versions:set -DnewVersion=... - // -DgenerateBackupPoms=false - mvnSetVersions(nextSnapshotVersion); + // mvn versions:set -DnewVersion=... + // -DgenerateBackupPoms=false + mvnSetVersions(nextSnapshotVersion); - Map properties = new HashMap(); - properties.put("version", nextSnapshotVersion); + Map properties = new HashMap(); + properties.put("version", nextSnapshotVersion); - // git commit -a -m updating for next development version - gitCommit(commitMessages.getHotfixFinishMessage(), - properties); + // git commit -a -m updating for next development version + gitCommit(commitMessages.getHotfixFinishMessage(), + properties); + } } } if (installProject) { - // mvn clean install + // mvn clean install mvnCleanInstall(); } From 942f080d3f79eb8f937749d2ce6ba32ef126e3b5 Mon Sep 17 00:00:00 2001 From: AF090536 Date: Thu, 30 Apr 2020 19:13:11 +0200 Subject: [PATCH 3/5] #230 The DEV version should still be set --- .../gitflow/GitFlowHotfixFinishMojo.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) 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 02b7c168..e58590aa 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -274,7 +274,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } else if (!skipMergeDevBranch) { // I should update the DEV version only if the hotfix // version is superior to the DEV version - boolean shouldUpdateDevVersion = true; + boolean shouldIncrementDevVersion = true; GitFlowVersionInfo developVersionInfo = new GitFlowVersionInfo( currentVersion); if (notSameProdDevName()) { @@ -300,30 +300,32 @@ public void execute() throws MojoExecutionException, MojoFailureException { .compareTo(hotfixVersionInfo) < 0) { developVersionInfo = hotfixVersionInfo; } else { - shouldUpdateDevVersion = false; + shouldIncrementDevVersion = false; } } - if (shouldUpdateDevVersion) { + String nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); + if (shouldIncrementDevVersion) { // get next snapshot version - final String nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); + nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); if (StringUtils.isBlank(nextSnapshotVersion)) { throw new MojoFailureException( "Next snapshot version is blank."); } + } + - // mvn versions:set -DnewVersion=... - // -DgenerateBackupPoms=false - mvnSetVersions(nextSnapshotVersion); + // mvn versions:set -DnewVersion=... + // -DgenerateBackupPoms=false + mvnSetVersions(nextSnapshotVersion); - Map properties = new HashMap(); - properties.put("version", nextSnapshotVersion); + Map properties = new HashMap(); + properties.put("version", nextSnapshotVersion); - // git commit -a -m updating for next development version - gitCommit(commitMessages.getHotfixFinishMessage(), - properties); - } + // git commit -a -m updating for next development version + gitCommit(commitMessages.getHotfixFinishMessage(), + properties); } } From c08efe153c135987563d268b9abee937757e1815 Mon Sep 17 00:00:00 2001 From: AF090536 Date: Thu, 30 Apr 2020 19:35:59 +0200 Subject: [PATCH 4/5] #230: Use the correct version for DEV branch --- .../maven/plugin/gitflow/GitFlowHotfixFinishMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e58590aa..ec76e1fd 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -304,7 +304,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } - String nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); + String nextSnapshotVersion = developVersionInfo.getSnapshotVersionString(); if (shouldIncrementDevVersion) { // get next snapshot version nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); From 863aea2c0ffeb29da0b30d36d1735fcccbe87bc8 Mon Sep 17 00:00:00 2001 From: AF090536 Date: Fri, 1 May 2020 12:07:42 +0200 Subject: [PATCH 5/5] #230 After conflict solved should not fail on tagging or POM commit After the user has solved the conflicts that appeared during the first hotfix-finish, it should be possible to restart the hotfix-finish without failing. The first fix is that if we are tagging (skipTag=false) we should allow the user to avoid failing. Since the tagging happened on master before possible merge fail on develop, we would fail when tagging the second time around. The second failure fix is to make sure that the development version is not incremented indiscriminately. There is one last problem, which is not solved yet: the fact that if we have a conflict when merging on develop, we should backtrack the commit were we set the version to hotfix branch... --- .../gitflow/GitFlowHotfixFinishMojo.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 ec76e1fd..d59ced25 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -41,6 +41,10 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "skipTag", defaultValue = "false") private boolean skipTag = false; + /** Whether to fail if tag exists the hotfix in Git (such as when already merged). */ + @Parameter(property = "failIfTagExists", defaultValue = "true") + private boolean failIfTagExists = true; + /** Whether to keep hotfix branch after finish. */ @Parameter(property = "keepBranch", defaultValue = "false") private boolean keepBranch = false; @@ -227,8 +231,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { properties.put("version", tagVersion); // git tag -a ... - gitTag(gitFlowConfig.getVersionTagPrefix() + tagVersion, - commitMessages.getTagHotfixMessage(), gpgSignTag, properties); + String tagName = gitFlowConfig.getVersionTagPrefix() + tagVersion; + if (! gitCheckTagExists(tagName) || failIfTagExists) { + gitTag(tagName, commitMessages.getTagHotfixMessage(), gpgSignTag, properties); + } else if (! failIfTagExists) { + getLog().warn("Tag '" + tagName + "' already exists, But '-DfailIfTagExists' set to false."); + } } if (skipMergeProdBranch && (supportBranchName == null)) { @@ -285,7 +293,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { // set version to avoid merge conflict mvnSetVersions(currentVersion); - gitCommit(commitMessages.getHotfixVersionUpdateMessage()); + if (executeGitHasUncommitted()) { + gitCommit(commitMessages.getHotfixVersionUpdateMessage()); + } else { + getLog().info("No changes detected. Did you manually merge '" + currentVersion + "' branch into '"+gitFlowConfig.getDevelopmentBranch()+"'?"); + } messageProperties.put("version", currentVersion); @@ -297,7 +309,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { GitFlowVersionInfo hotfixVersionInfo = new GitFlowVersionInfo( currentVersion); if (developVersionInfo - .compareTo(hotfixVersionInfo) < 0) { + .compareTo(hotfixVersionInfo) <= 0) { developVersionInfo = hotfixVersionInfo; } else { shouldIncrementDevVersion = false;