From e1c1f0d941c27193bebc15fae05151e0c53a979a Mon Sep 17 00:00:00 2001 From: Tomasz Belina Date: Thu, 15 Jul 2021 10:01:25 +0200 Subject: [PATCH] support for --atomic --- .../plugin/gitflow/AbstractGitFlowMojo.java | 38 +++++++++++++------ .../gitflow/GitFlowFeatureFinishMojo.java | 9 +++-- .../gitflow/GitFlowFeatureStartMojo.java | 3 +- .../gitflow/GitFlowHotfixFinishMojo.java | 12 +++--- .../gitflow/GitFlowHotfixStartMojo.java | 2 +- .../gitflow/GitFlowReleaseFinishMojo.java | 9 +++-- .../plugin/gitflow/GitFlowReleaseMojo.java | 5 ++- .../gitflow/GitFlowReleaseStartMojo.java | 9 +++-- .../gitflow/GitFlowSupportStartMojo.java | 2 +- 9 files changed, 56 insertions(+), 33 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..93934483 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -18,6 +18,8 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; @@ -75,6 +77,14 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { @Parameter(defaultValue = "${gitFlowConfig}") protected GitFlowConfig gitFlowConfig; + /** + * Whether to use --atomic option on push. + * + * @since 1.6.1 + */ + @Parameter(property = "verbose", defaultValue = "false") + private boolean atomicPush = false; + /** * Git commit messages. * @@ -93,7 +103,7 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { /** * Whether to call Maven install goal during the mojo execution. - * + * * @since 1.0.5 */ @Parameter(property = "installProject", defaultValue = "false") @@ -190,6 +200,8 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { @Parameter(defaultValue = "${settings}", readonly = true) protected Settings settings; + + /** * Initializes command line executables. * @@ -965,28 +977,32 @@ private boolean gitFetchRemote(final String branchName) /** * Executes git push, optionally with the --follow-tags * argument. - * - * @param branchName - * Branch name to push. + * + * @param branchNames + * Branch names to push. Names proceeded by : will be deleted * @param pushTags * If true adds --follow-tags argument * to the git push command. * @throws MojoFailureException * @throws CommandLineException */ - protected void gitPush(final String branchName, boolean pushTags) + protected void gitPush(boolean pushTags, final String... branchNames) throws MojoFailureException, CommandLineException { getLog().info( - "Pushing '" + branchName + "' branch" + " to '" + "Pushing '" + Arrays.toString(branchNames) + "' branch" + " to '" + gitFlowConfig.getOrigin() + "'."); + initGitFlowConfig(); + List argsList = Arrays.asList("push", "--quiet", "-u", gitFlowConfig.getOrigin()); + if(atomicPush){ + argsList.add("--atomic"); + } + Collections.addAll(argsList, branchNames); if (pushTags) { - executeGitCommand("push", "--quiet", "-u", "--follow-tags", - gitFlowConfig.getOrigin(), branchName); - } else { - executeGitCommand("push", "--quiet", "-u", - gitFlowConfig.getOrigin(), branchName); + argsList.add("--follow-tags"); } + String[] argsArray = argsList.toArray(new String[0]); + executeGitCommand(argsArray); } protected void gitPushDelete(final String branchName) 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 a4e16494..0c2cd6d8 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java @@ -16,6 +16,7 @@ package com.amashchenko.maven.plugin.gitflow; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -241,13 +242,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (pushRemote) { - gitPush(gitFlowConfig.getDevelopmentBranch(), false); - + List branchesToPush = Arrays.asList(gitFlowConfig.getDevelopmentBranch()); if (keepBranch) { - gitPush(featureBranchName, false); + branchesToPush.add(featureBranchName); } else { - gitPushDelete(featureBranchName); + branchesToPush.add(":" + featureBranchName); } + gitPush(false, branchesToPush.toArray(new String[0])); } if (!keepBranch) { diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureStartMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureStartMojo.java index 0b08294e..de4ac7ad 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureStartMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureStartMojo.java @@ -154,8 +154,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (pushRemote) { - gitPush(gitFlowConfig.getFeatureBranchPrefix() - + featureBranchName, false); + gitPush(false, gitFlowConfig.getFeatureBranchPrefix() + featureBranchName); } } catch (CommandLineException e) { throw new MojoFailureException("feature-start", e); 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 3ddd1ec9..fd39789c 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -341,22 +341,24 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (pushRemote) { + List branchesToPush = new ArrayList<>(); if (supportBranchName != null) { - gitPush(supportBranchName, !skipTag); + branchesToPush.add(supportBranchName); } else { - gitPush(gitFlowConfig.getProductionBranch(), !skipTag); + branchesToPush.add(gitFlowConfig.getProductionBranch()); if (StringUtils.isNotBlank(releaseBranch)) { - gitPush(releaseBranch, !skipTag); + branchesToPush.add(releaseBranch); } else if (StringUtils.isBlank(releaseBranch) && notSameProdDevName()) { // if no release branch - gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag); + branchesToPush.add(gitFlowConfig.getDevelopmentBranch()); } } if (!keepBranch) { - gitPushDelete(hotfixBranchName); + branchesToPush.add(":" + hotfixBranchName); } + gitPush(!skipTag, branchesToPush.toArray(new String[0])); } if (!keepBranch) { diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java index 83eb3b99..01ac9451 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java @@ -254,7 +254,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (pushRemote) { - gitPush(hotfixBranchName, false); + gitPush(false, hotfixBranchName); } } catch (CommandLineException e) { throw new MojoFailureException("hotfix-start", e); 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..d3beb15c 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java @@ -15,7 +15,9 @@ */ package com.amashchenko.maven.plugin.gitflow; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.maven.artifact.Artifact; @@ -361,14 +363,15 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (pushRemote) { - gitPush(gitFlowConfig.getProductionBranch(), !skipTag); + List branchesToPush = Arrays.asList(gitFlowConfig.getProductionBranch()); if (notSameProdDevName()) { - gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag); + branchesToPush.add(gitFlowConfig.getDevelopmentBranch()); } if (!keepBranch) { - gitPushDelete(releaseBranch); + branchesToPush.add(":" + releaseBranch); } + gitPush(!skipTag, branchesToPush.toArray(new String[0])); } if (!keepBranch) { diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java index 29cdc528..d30e146d 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java @@ -332,9 +332,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (pushRemote) { - gitPush(gitFlowConfig.getProductionBranch(), !skipTag); if (notSameProdDevName()) { - gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag); + gitPush(!skipTag, gitFlowConfig.getDevelopmentBranch(),gitFlowConfig.getProductionBranch()); + }else{ + gitPush(!skipTag, gitFlowConfig.getProductionBranch()); } } } catch (Exception e) { diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java index 899c31b2..16380486 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java @@ -218,7 +218,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // mvn versions:set ... // git commit -a -m ... commitProjectVersion(projectVersion, - commitMessages.getReleaseStartMessage()); + commitMessages.getReleaseStartMessage()); // git branch release/... develop gitCreateBranch(fullBranchName, startPoint); @@ -249,10 +249,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { if (pushRemote) { if (commitDevelopmentVersionAtStart) { - gitPush(gitFlowConfig.getDevelopmentBranch(), false); + gitPush(false, gitFlowConfig.getDevelopmentBranch(), fullBranchName); + } + else { + gitPush( false, fullBranchName); } - - gitPush(fullBranchName, false); } } catch (CommandLineException e) { throw new MojoFailureException("release-start", e); diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowSupportStartMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowSupportStartMojo.java index 20bce91c..64476d73 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowSupportStartMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowSupportStartMojo.java @@ -146,7 +146,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (pushRemote) { - gitPush(gitFlowConfig.getSupportBranchPrefix() + branchName, false); + gitPush(false, gitFlowConfig.getSupportBranchPrefix() + branchName); } } catch (CommandLineException e) { throw new MojoFailureException("support-start", e);