Skip to content

Commit

Permalink
Allow to add push-options to git push - closes #319
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-m committed Dec 21, 2021
1 parent 461b8fa commit cb93c2f
Showing 1 changed file with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>--push-option</code>.
* Multiple options can be added separated with a space e.g.
* <code>-DgitPushOptions="merge_request.create merge_request.target=develop
* merge_request.label='Super feature'"</code>
*/
@Parameter(property = "gitPushOptions")
private String gitPushOptions;

/**
* The path to the Maven executable. Defaults to "mvn".
*/
Expand Down Expand Up @@ -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<String> 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)
Expand Down

0 comments on commit cb93c2f

Please sign in to comment.