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 39dc022b..faaf7f45 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -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; @@ -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; @@ -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". */ @@ -253,6 +266,10 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { @Component protected Map versionPolicies; + public AbstractGitFlowMojo() { + gitModulesExists = FileUtils.fileExists(".gitmodules"); + } + /** * Initializes command line executables. * @@ -807,6 +824,11 @@ protected void gitCommit(final String message) throws MojoFailureException, Comm */ protected void gitCommit(String message, Map 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; }