Skip to content

Commit

Permalink
Update git submodules before commit - closes #348
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-m committed Oct 2, 2022
1 parent ea7841d commit 231ebb6
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.maven.settings.Settings;
import org.apache.maven.shared.release.policy.version.VersionPolicy;
import org.codehaus.plexus.components.interactivity.Prompter;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
Expand Down Expand Up @@ -83,6 +84,9 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
/** Command line for Maven executable. */
private final Commandline cmdMvn = new Commandline();

/** Whether .gitmodules file exists in project. */
private final boolean gitModulesExists;

/** Git flow configuration. */
@Parameter(defaultValue = "${gitFlowConfig}")
protected GitFlowConfig gitFlowConfig;
Expand Down Expand Up @@ -225,6 +229,15 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
@Parameter(property = "gitPushOptions")
private String gitPushOptions;

/**
* Explicitly enable or disable executing submodule update before commit. By
* default plugin tries to automatically determine if update of the Git
* submodules is needed.
*
*/
@Parameter(property = "updateGitSubmodules")
private Boolean updateGitSubmodules;

/**
* The path to the Maven executable. Defaults to "mvn".
*/
Expand Down Expand Up @@ -253,6 +266,10 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
@Component
protected Map<String, VersionPolicy> versionPolicies;

public AbstractGitFlowMojo() {
gitModulesExists = FileUtils.fileExists(".gitmodules");
}

/**
* Initializes command line executables.
*
Expand Down Expand Up @@ -807,6 +824,11 @@ protected void gitCommit(final String message) throws MojoFailureException, Comm
*/
protected void gitCommit(String message, Map<String, String> messageProperties)
throws MojoFailureException, CommandLineException {
if ((gitModulesExists && updateGitSubmodules == null) || Boolean.TRUE.equals(updateGitSubmodules)) {
getLog().info("Updating git submodules before commit.");
executeGitCommand("submodule", "update");
}

if (StringUtils.isNotBlank(commitMessagePrefix)) {
message = commitMessagePrefix + message;
}
Expand Down

0 comments on commit 231ebb6

Please sign in to comment.