Skip to content

Commit cb93c2f

Browse files
committed
Allow to add push-options to git push - closes #319
1 parent 461b8fa commit cb93c2f

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
175175
@Parameter(property = "updateOutputTimestamp", defaultValue = "true")
176176
private boolean updateOutputTimestamp = true;
177177

178+
/**
179+
* Options to pass to Git push command using <code>--push-option</code>.
180+
* Multiple options can be added separated with a space e.g.
181+
* <code>-DgitPushOptions="merge_request.create merge_request.target=develop
182+
* merge_request.label='Super feature'"</code>
183+
*/
184+
@Parameter(property = "gitPushOptions")
185+
private String gitPushOptions;
186+
178187
/**
179188
* The path to the Maven executable. Defaults to "mvn".
180189
*/
@@ -1042,19 +1051,33 @@ private boolean gitFetchRemote(final String branchName)
10421051
* @throws CommandLineException
10431052
* If command line execution fails.
10441053
*/
1045-
protected void gitPush(final String branchName, boolean pushTags)
1046-
throws MojoFailureException, CommandLineException {
1047-
getLog().info(
1048-
"Pushing '" + branchName + "' branch" + " to '"
1049-
+ gitFlowConfig.getOrigin() + "'.");
1054+
protected void gitPush(final String branchName, boolean pushTags) throws MojoFailureException, CommandLineException {
1055+
getLog().info("Pushing '" + branchName + "' branch to '" + gitFlowConfig.getOrigin() + "'.");
1056+
1057+
List<String> args = new ArrayList<>();
1058+
args.add("push");
1059+
args.add("--quiet");
1060+
args.add("-u");
10501061

10511062
if (pushTags) {
1052-
executeGitCommand("push", "--quiet", "-u", "--follow-tags",
1053-
gitFlowConfig.getOrigin(), branchName);
1054-
} else {
1055-
executeGitCommand("push", "--quiet", "-u",
1056-
gitFlowConfig.getOrigin(), branchName);
1063+
args.add("--follow-tags");
10571064
}
1065+
1066+
if (StringUtils.isNotBlank(gitPushOptions)) {
1067+
try {
1068+
String[] opts = CommandLineUtils.translateCommandline(gitPushOptions);
1069+
for (String opt : opts) {
1070+
args.add("--push-option=" + opt);
1071+
}
1072+
} catch (Exception e) {
1073+
throw new CommandLineException(e.getMessage(), e);
1074+
}
1075+
}
1076+
1077+
args.add(gitFlowConfig.getOrigin());
1078+
args.add(branchName);
1079+
1080+
executeGitCommand(args.toArray(new String[0]));
10581081
}
10591082

10601083
protected void gitPushDelete(final String branchName)

0 commit comments

Comments
 (0)