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); 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..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)) { @@ -248,6 +256,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 +280,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 shouldIncrementDevVersion = true; GitFlowVersionInfo developVersionInfo = new GitFlowVersionInfo( currentVersion); if (notSameProdDevName()) { @@ -281,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); @@ -293,18 +309,24 @@ public void execute() throws MojoExecutionException, MojoFailureException { GitFlowVersionInfo hotfixVersionInfo = new GitFlowVersionInfo( currentVersion); if (developVersionInfo - .compareTo(hotfixVersionInfo) < 0) { + .compareTo(hotfixVersionInfo) <= 0) { developVersionInfo = hotfixVersionInfo; + } else { + shouldIncrementDevVersion = false; } } - - // get next snapshot version - final String nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); - - if (StringUtils.isBlank(nextSnapshotVersion)) { - throw new MojoFailureException( + + String nextSnapshotVersion = developVersionInfo.getSnapshotVersionString(); + if (shouldIncrementDevVersion) { + // get next snapshot version + nextSnapshotVersion = developVersionInfo.nextSnapshotVersion(); + + if (StringUtils.isBlank(nextSnapshotVersion)) { + throw new MojoFailureException( "Next snapshot version is blank."); + } } + // mvn versions:set -DnewVersion=... // -DgenerateBackupPoms=false @@ -315,12 +337,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { // git commit -a -m updating for next development version gitCommit(commitMessages.getHotfixFinishMessage(), - properties); + properties); } } if (installProject) { - // mvn clean install + // mvn clean install mvnCleanInstall(); }