Skip to content

Commit

Permalink
support for --atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-belina-nes committed Jul 15, 2021
1 parent ee25056 commit e1c1f0d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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")
Expand Down Expand Up @@ -190,6 +200,8 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
@Parameter(defaultValue = "${settings}", readonly = true)
protected Settings settings;



/**
* Initializes command line executables.
*
Expand Down Expand Up @@ -965,28 +977,32 @@ private boolean gitFetchRemote(final String branchName)
/**
* Executes git push, optionally with the <code>--follow-tags</code>
* argument.
*
* @param branchName
* Branch name to push.
*
* @param branchNames
* Branch names to push. Names proceeded by : will be deleted
* @param pushTags
* If <code>true</code> adds <code>--follow-tags</code> argument
* to the git <code>push</code> 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<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -241,13 +242,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

if (pushRemote) {
gitPush(gitFlowConfig.getDevelopmentBranch(), false);

List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,24 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

if (pushRemote) {
List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -361,14 +363,15 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

if (pushRemote) {
gitPush(gitFlowConfig.getProductionBranch(), !skipTag);
List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e1c1f0d

Please sign in to comment.