@@ -90,6 +90,11 @@ public class GitSCM extends SCM implements Serializable {
90
90
*/
91
91
private PreBuildMergeOptions mergeOptions ;
92
92
93
+ /**
94
+ * Use --recursive flag on submodule commands - requires git>=1.6.5
95
+ */
96
+ private boolean recursiveSubmodules ;
97
+
93
98
private boolean doGenerateSubmoduleConfigurations ;
94
99
private boolean authorOrCommitter ;
95
100
@@ -143,7 +148,8 @@ public GitSCM(
143
148
String relativeTargetDir ,
144
149
String excludedRegions ,
145
150
String excludedUsers ,
146
- String localBranch ) {
151
+ String localBranch ,
152
+ boolean recursiveSubmodules ) {
147
153
148
154
// normalization
149
155
this .branches = branches ;
@@ -166,6 +172,7 @@ public GitSCM(
166
172
this .relativeTargetDir = relativeTargetDir ;
167
173
this .excludedRegions = excludedRegions ;
168
174
this .excludedUsers = excludedUsers ;
175
+ this .recursiveSubmodules = recursiveSubmodules ;
169
176
buildChooser .gitSCM = this ; // set the owner
170
177
}
171
178
@@ -183,7 +190,8 @@ public Object readResolve() {
183
190
doGenerateSubmoduleConfigurations = false ;
184
191
mergeOptions = new PreBuildMergeOptions ();
185
192
186
-
193
+ recursiveSubmodules = false ;
194
+
187
195
remoteRepositories .add (newRemoteConfig ("origin" , source , new RefSpec ("+refs/heads/*:refs/remotes/origin/*" )));
188
196
if (branch != null ) {
189
197
branches .add (new BranchSpec (branch ));
@@ -779,7 +787,7 @@ public Revision invoke(File localWorkspace, VirtualChannel channel)
779
787
780
788
if (git .hasGitModules ()) {
781
789
git .submoduleInit ();
782
- git .submoduleUpdate ();
790
+ git .submoduleUpdate (recursiveSubmodules );
783
791
}
784
792
}
785
793
@@ -857,16 +865,17 @@ public Object[] invoke(File localWorkspace, VirtualChannel channel)
857
865
if (getClean ()) {
858
866
listener .getLogger ().println ("Cleaning workspace" );
859
867
git .clean ();
860
- for (RemoteConfig remoteRepository : paramRepos ) {
861
- cleanSubmodules (git ,localWorkspace ,listener ,remoteRepository );
868
+
869
+ if (git .hasGitModules ()) {
870
+ git .submoduleClean (recursiveSubmodules );
862
871
}
863
872
}
864
873
865
874
return new Object []{null , buildData };
866
875
}
867
876
868
877
if (git .hasGitModules ()) {
869
- git .submoduleUpdate ();
878
+ git .submoduleUpdate (recursiveSubmodules );
870
879
}
871
880
872
881
// Tag the successful merge
@@ -897,8 +906,8 @@ public Object[] invoke(File localWorkspace, VirtualChannel channel)
897
906
if (getClean ()) {
898
907
listener .getLogger ().println ("Cleaning workspace" );
899
908
git .clean ();
900
- for ( RemoteConfig remoteRepository : paramRepos ) {
901
- cleanSubmodules ( git , localWorkspace , listener , remoteRepository );
909
+ if ( git . hasGitModules () ) {
910
+ git . submoduleClean ( recursiveSubmodules );
902
911
}
903
912
}
904
913
@@ -948,13 +957,17 @@ public Object[] invoke(File localWorkspace, VirtualChannel channel)
948
957
// we've only just discovered.
949
958
// So - try updating from all RRs, then use the submodule
950
959
// Update to do the checkout
951
-
952
- for (RemoteConfig remoteRepository : paramRepos ) {
953
- fetchFrom (git , localWorkspace , listener , remoteRepository );
960
+ //
961
+ // Also, only do this if we're not doing recursive submodules, since that'll
962
+ // theoretically be dealt with there anyway.
963
+ if (!recursiveSubmodules ) {
964
+ for (RemoteConfig remoteRepository : paramRepos ) {
965
+ fetchFrom (git , localWorkspace , listener , remoteRepository );
966
+ }
954
967
}
955
968
956
969
// Update to the correct checkout
957
- git .submoduleUpdate ();
970
+ git .submoduleUpdate (recursiveSubmodules );
958
971
959
972
}
960
973
@@ -1125,7 +1138,8 @@ public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormExcep
1125
1138
req .getParameter ("git.relativeTargetDir" ),
1126
1139
req .getParameter ("git.excludedRegions" ),
1127
1140
req .getParameter ("git.excludedUsers" ),
1128
- req .getParameter ("git.localBranch" ));
1141
+ req .getParameter ("git.localBranch" ),
1142
+ req .getParameter ("git.recursiveSubmodules" ) != null );
1129
1143
}
1130
1144
1131
1145
/**
@@ -1279,7 +1293,10 @@ public FormValidation doGitRemoteNameCheck(StaplerRequest req, StaplerResponse r
1279
1293
private static final long serialVersionUID = 1L ;
1280
1294
1281
1295
1282
-
1296
+ public boolean getRecursiveSubmodules () {
1297
+ return this .recursiveSubmodules ;
1298
+ }
1299
+
1283
1300
public boolean getDoGenerate () {
1284
1301
return this .doGenerateSubmoduleConfigurations ;
1285
1302
}
0 commit comments