Skip to content

Commit 246f109

Browse files
support for --atomic
1 parent ee25056 commit 246f109

9 files changed

+55
-33
lines changed

src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java

+26-11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.text.DateFormat;
1919
import java.text.SimpleDateFormat;
2020
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.Collections;
2123
import java.util.Date;
2224
import java.util.List;
2325
import java.util.Map;
@@ -75,6 +77,14 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
7577
@Parameter(defaultValue = "${gitFlowConfig}")
7678
protected GitFlowConfig gitFlowConfig;
7779

80+
/**
81+
* Whether to use --atomic option on push.
82+
*
83+
* @since 1.6.1
84+
*/
85+
@Parameter(property = "verbose", defaultValue = "false")
86+
private boolean atomicPush = false;
87+
7888
/**
7989
* Git commit messages.
8090
*
@@ -93,7 +103,7 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
93103

94104
/**
95105
* Whether to call Maven install goal during the mojo execution.
96-
*
106+
*
97107
* @since 1.0.5
98108
*/
99109
@Parameter(property = "installProject", defaultValue = "false")
@@ -190,6 +200,8 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
190200
@Parameter(defaultValue = "${settings}", readonly = true)
191201
protected Settings settings;
192202

203+
204+
193205
/**
194206
* Initializes command line executables.
195207
*
@@ -965,28 +977,31 @@ private boolean gitFetchRemote(final String branchName)
965977
/**
966978
* Executes git push, optionally with the <code>--follow-tags</code>
967979
* argument.
968-
*
969-
* @param branchName
970-
* Branch name to push.
980+
*
981+
* @param branchNames
982+
* Branch names to push. Names proceeded by : will be deleted
971983
* @param pushTags
972984
* If <code>true</code> adds <code>--follow-tags</code> argument
973985
* to the git <code>push</code> command.
974986
* @throws MojoFailureException
975987
* @throws CommandLineException
976988
*/
977-
protected void gitPush(final String branchName, boolean pushTags)
989+
protected void gitPush(boolean pushTags, final String... branchNames)
978990
throws MojoFailureException, CommandLineException {
979991
getLog().info(
980-
"Pushing '" + branchName + "' branch" + " to '"
992+
"Pushing '" + Arrays.toString(branchNames) + "' branch" + " to '"
981993
+ gitFlowConfig.getOrigin() + "'.");
982994

995+
List<String> argsList = Arrays.asList("push", "--quiet", "-u", gitFlowConfig.getOrigin());
996+
if(atomicPush){
997+
argsList.add("--atomic");
998+
}
999+
Collections.addAll(argsList, branchNames);
9831000
if (pushTags) {
984-
executeGitCommand("push", "--quiet", "-u", "--follow-tags",
985-
gitFlowConfig.getOrigin(), branchName);
986-
} else {
987-
executeGitCommand("push", "--quiet", "-u",
988-
gitFlowConfig.getOrigin(), branchName);
1001+
argsList.add("--follow-tags");
9891002
}
1003+
String[] argsArray = argsList.toArray(new String[0]);
1004+
executeGitCommand(argsArray);
9901005
}
9911006

9921007
protected void gitPushDelete(final String branchName)

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.amashchenko.maven.plugin.gitflow;
1717

1818
import java.util.ArrayList;
19+
import java.util.Arrays;
1920
import java.util.HashMap;
2021
import java.util.List;
2122
import java.util.Map;
@@ -241,13 +242,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
241242
}
242243

243244
if (pushRemote) {
244-
gitPush(gitFlowConfig.getDevelopmentBranch(), false);
245-
245+
List<String> branchesToPush = Arrays.asList(gitFlowConfig.getDevelopmentBranch());
246246
if (keepBranch) {
247-
gitPush(featureBranchName, false);
247+
branchesToPush.add(featureBranchName);
248248
} else {
249-
gitPushDelete(featureBranchName);
249+
branchesToPush.add(":" + featureBranchName);
250250
}
251+
gitPush(false, branchesToPush.toArray(new String[0]));
251252
}
252253

253254
if (!keepBranch) {

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureStartMojo.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
154154
}
155155

156156
if (pushRemote) {
157-
gitPush(gitFlowConfig.getFeatureBranchPrefix()
158-
+ featureBranchName, false);
157+
gitPush(false, gitFlowConfig.getFeatureBranchPrefix() + featureBranchName);
159158
}
160159
} catch (CommandLineException e) {
161160
throw new MojoFailureException("feature-start", e);

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -341,22 +341,24 @@ public void execute() throws MojoExecutionException, MojoFailureException {
341341
}
342342

343343
if (pushRemote) {
344+
List<String> branchesToPush = new ArrayList<>();
344345
if (supportBranchName != null) {
345-
gitPush(supportBranchName, !skipTag);
346+
branchesToPush.add(supportBranchName);
346347
} else {
347-
gitPush(gitFlowConfig.getProductionBranch(), !skipTag);
348+
branchesToPush.add(gitFlowConfig.getProductionBranch());
348349

349350
if (StringUtils.isNotBlank(releaseBranch)) {
350-
gitPush(releaseBranch, !skipTag);
351+
branchesToPush.add(releaseBranch);
351352
} else if (StringUtils.isBlank(releaseBranch)
352353
&& notSameProdDevName()) { // if no release branch
353-
gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
354+
branchesToPush.add(gitFlowConfig.getDevelopmentBranch());
354355
}
355356
}
356357

357358
if (!keepBranch) {
358-
gitPushDelete(hotfixBranchName);
359+
branchesToPush.add(":" + hotfixBranchName);
359360
}
361+
gitPush(!skipTag, branchesToPush.toArray(new String[0]));
360362
}
361363

362364
if (!keepBranch) {

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
254254
}
255255

256256
if (pushRemote) {
257-
gitPush(hotfixBranchName, false);
257+
gitPush(false, hotfixBranchName);
258258
}
259259
} catch (CommandLineException e) {
260260
throw new MojoFailureException("hotfix-start", e);

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package com.amashchenko.maven.plugin.gitflow;
1717

18+
import java.util.Arrays;
1819
import java.util.HashMap;
20+
import java.util.List;
1921
import java.util.Map;
2022

2123
import org.apache.maven.artifact.Artifact;
@@ -361,14 +363,15 @@ public void execute() throws MojoExecutionException, MojoFailureException {
361363
}
362364

363365
if (pushRemote) {
364-
gitPush(gitFlowConfig.getProductionBranch(), !skipTag);
366+
List<String> branchesToPush = Arrays.asList(gitFlowConfig.getProductionBranch());
365367
if (notSameProdDevName()) {
366-
gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
368+
branchesToPush.add(gitFlowConfig.getDevelopmentBranch());
367369
}
368370

369371
if (!keepBranch) {
370-
gitPushDelete(releaseBranch);
372+
branchesToPush.add(":" + releaseBranch);
371373
}
374+
gitPush(!skipTag, branchesToPush.toArray(new String[0]));
372375
}
373376

374377
if (!keepBranch) {

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
332332
}
333333

334334
if (pushRemote) {
335-
gitPush(gitFlowConfig.getProductionBranch(), !skipTag);
336335
if (notSameProdDevName()) {
337-
gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
336+
gitPush(!skipTag, gitFlowConfig.getDevelopmentBranch(),gitFlowConfig.getProductionBranch());
337+
}else{
338+
gitPush(!skipTag, gitFlowConfig.getProductionBranch());
338339
}
339340
}
340341
} catch (Exception e) {

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
218218
// mvn versions:set ...
219219
// git commit -a -m ...
220220
commitProjectVersion(projectVersion,
221-
commitMessages.getReleaseStartMessage());
221+
commitMessages.getReleaseStartMessage());
222222

223223
// git branch release/... develop
224224
gitCreateBranch(fullBranchName, startPoint);
@@ -249,10 +249,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
249249

250250
if (pushRemote) {
251251
if (commitDevelopmentVersionAtStart) {
252-
gitPush(gitFlowConfig.getDevelopmentBranch(), false);
252+
gitPush(false, gitFlowConfig.getDevelopmentBranch(), fullBranchName);
253+
}
254+
else {
255+
gitPush( false, fullBranchName);
253256
}
254-
255-
gitPush(fullBranchName, false);
256257
}
257258
} catch (CommandLineException e) {
258259
throw new MojoFailureException("release-start", e);

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowSupportStartMojo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
146146
}
147147

148148
if (pushRemote) {
149-
gitPush(gitFlowConfig.getSupportBranchPrefix() + branchName, false);
149+
gitPush(false, gitFlowConfig.getSupportBranchPrefix() + branchName);
150150
}
151151
} catch (CommandLineException e) {
152152
throw new MojoFailureException("support-start", e);

0 commit comments

Comments
 (0)