From cb93c2fdca47d25232289ad70e37e24d0f102b7d Mon Sep 17 00:00:00 2001 From: Aleksandr Mashchenko Date: Tue, 21 Dec 2021 14:54:52 +0200 Subject: [PATCH] Allow to add push-options to git push - closes #319 --- .../plugin/gitflow/AbstractGitFlowMojo.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 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 9e53b0c4..c571aece 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -175,6 +175,15 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { @Parameter(property = "updateOutputTimestamp", defaultValue = "true") private boolean updateOutputTimestamp = true; + /** + * Options to pass to Git push command using --push-option. + * Multiple options can be added separated with a space e.g. + * -DgitPushOptions="merge_request.create merge_request.target=develop + * merge_request.label='Super feature'" + */ + @Parameter(property = "gitPushOptions") + private String gitPushOptions; + /** * The path to the Maven executable. Defaults to "mvn". */ @@ -1042,19 +1051,33 @@ private boolean gitFetchRemote(final String branchName) * @throws CommandLineException * If command line execution fails. */ - protected void gitPush(final String branchName, boolean pushTags) - throws MojoFailureException, CommandLineException { - getLog().info( - "Pushing '" + branchName + "' branch" + " to '" - + gitFlowConfig.getOrigin() + "'."); + protected void gitPush(final String branchName, boolean pushTags) throws MojoFailureException, CommandLineException { + getLog().info("Pushing '" + branchName + "' branch to '" + gitFlowConfig.getOrigin() + "'."); + + List args = new ArrayList<>(); + args.add("push"); + args.add("--quiet"); + args.add("-u"); if (pushTags) { - executeGitCommand("push", "--quiet", "-u", "--follow-tags", - gitFlowConfig.getOrigin(), branchName); - } else { - executeGitCommand("push", "--quiet", "-u", - gitFlowConfig.getOrigin(), branchName); + args.add("--follow-tags"); } + + if (StringUtils.isNotBlank(gitPushOptions)) { + try { + String[] opts = CommandLineUtils.translateCommandline(gitPushOptions); + for (String opt : opts) { + args.add("--push-option=" + opt); + } + } catch (Exception e) { + throw new CommandLineException(e.getMessage(), e); + } + } + + args.add(gitFlowConfig.getOrigin()); + args.add(branchName); + + executeGitCommand(args.toArray(new String[0])); } protected void gitPushDelete(final String branchName)