Skip to content

Commit 231ebb6

Browse files
committed
Update git submodules before commit - closes #348
1 parent ea7841d commit 231ebb6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.maven.settings.Settings;
4444
import org.apache.maven.shared.release.policy.version.VersionPolicy;
4545
import org.codehaus.plexus.components.interactivity.Prompter;
46+
import org.codehaus.plexus.util.FileUtils;
4647
import org.codehaus.plexus.util.StringUtils;
4748
import org.codehaus.plexus.util.cli.CommandLineException;
4849
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -83,6 +84,9 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
8384
/** Command line for Maven executable. */
8485
private final Commandline cmdMvn = new Commandline();
8586

87+
/** Whether .gitmodules file exists in project. */
88+
private final boolean gitModulesExists;
89+
8690
/** Git flow configuration. */
8791
@Parameter(defaultValue = "${gitFlowConfig}")
8892
protected GitFlowConfig gitFlowConfig;
@@ -225,6 +229,15 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
225229
@Parameter(property = "gitPushOptions")
226230
private String gitPushOptions;
227231

232+
/**
233+
* Explicitly enable or disable executing submodule update before commit. By
234+
* default plugin tries to automatically determine if update of the Git
235+
* submodules is needed.
236+
*
237+
*/
238+
@Parameter(property = "updateGitSubmodules")
239+
private Boolean updateGitSubmodules;
240+
228241
/**
229242
* The path to the Maven executable. Defaults to "mvn".
230243
*/
@@ -253,6 +266,10 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
253266
@Component
254267
protected Map<String, VersionPolicy> versionPolicies;
255268

269+
public AbstractGitFlowMojo() {
270+
gitModulesExists = FileUtils.fileExists(".gitmodules");
271+
}
272+
256273
/**
257274
* Initializes command line executables.
258275
*
@@ -807,6 +824,11 @@ protected void gitCommit(final String message) throws MojoFailureException, Comm
807824
*/
808825
protected void gitCommit(String message, Map<String, String> messageProperties)
809826
throws MojoFailureException, CommandLineException {
827+
if ((gitModulesExists && updateGitSubmodules == null) || Boolean.TRUE.equals(updateGitSubmodules)) {
828+
getLog().info("Updating git submodules before commit.");
829+
executeGitCommand("submodule", "update");
830+
}
831+
810832
if (StringUtils.isNotBlank(commitMessagePrefix)) {
811833
message = commitMessagePrefix + message;
812834
}

0 commit comments

Comments
 (0)