40
40
import org .eclipse .jgit .api .ResetCommand .ResetType ;
41
41
import org .eclipse .jgit .api .Status ;
42
42
import org .eclipse .jgit .api .StatusCommand ;
43
+ import org .eclipse .jgit .api .SubmoduleUpdateCommand ;
43
44
import org .eclipse .jgit .api .TransportCommand ;
44
45
import org .eclipse .jgit .api .TransportConfigCallback ;
45
46
import org .eclipse .jgit .api .errors .GitAPIException ;
@@ -113,7 +114,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
113
114
*/
114
115
private boolean cloneOnStart ;
115
116
116
- private JGitEnvironmentRepository .JGitFactory gitFactory ;
117
+ private JGitEnvironmentRepository .JGitFactory gitFactory = new JGitFactory () ;
117
118
118
119
private String defaultLabel ;
119
120
@@ -146,6 +147,8 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
146
147
*/
147
148
private boolean skipSslValidation ;
148
149
150
+ private boolean cloneSubmodules ;
151
+
149
152
private boolean tryMasterBranch ;
150
153
151
154
private final ObservationRegistry observationRegistry ;
@@ -167,11 +170,19 @@ public JGitEnvironmentRepository(ConfigurableEnvironment environment, JGitEnviro
167
170
this .deleteUntrackedBranches = properties .isDeleteUntrackedBranches ();
168
171
this .refreshRate = properties .getRefreshRate ();
169
172
this .skipSslValidation = properties .isSkipSslValidation ();
170
- this .gitFactory = new JGitFactory ( properties .isCloneSubmodules () );
173
+ this .cloneSubmodules = properties .isCloneSubmodules ();
171
174
this .tryMasterBranch = properties .isTryMasterBranch ();
172
175
this .observationRegistry = observationRegistry ;
173
176
}
174
177
178
+ public boolean isCloneSubmodules () {
179
+ return this .cloneSubmodules ;
180
+ }
181
+
182
+ public void setCloneSubmodules (boolean cloneSubmodules ) {
183
+ this .cloneSubmodules = cloneSubmodules ;
184
+ }
185
+
175
186
public boolean isTryMasterBranch () {
176
187
return tryMasterBranch ;
177
188
}
@@ -315,6 +326,13 @@ public String refresh(String label) {
315
326
if (this .deleteUntrackedBranches && fetchStatus != null ) {
316
327
deleteUntrackedLocalBranches (fetchStatus .getTrackingRefUpdates (), git );
317
328
}
329
+
330
+ // update submodules if needed
331
+ if (cloneSubmodules ) {
332
+ SubmoduleUpdateCommand submoduleUpdate = git .submoduleUpdate ().setFetch (true );
333
+ configureCommand (submoduleUpdate );
334
+ submoduleUpdate .call ();
335
+ }
318
336
}
319
337
320
338
// checkout after fetch so we can get any new branches, tags, ect.
@@ -669,6 +687,7 @@ private Git copyFromLocalRepository() throws IOException {
669
687
670
688
private Git cloneToBasedir () throws GitAPIException {
671
689
CloneCommand clone = this .gitFactory .getCloneCommandByCloneRepository ()
690
+ .setCloneSubmodules (cloneSubmodules )
672
691
.setURI (getUri ())
673
692
.setDirectory (getBasedir ());
674
693
configureCommand (clone );
@@ -776,23 +795,13 @@ public void setLastRefresh(long lastRefresh) {
776
795
*/
777
796
public static class JGitFactory {
778
797
779
- private final boolean cloneSubmodules ;
780
-
781
- public JGitFactory () {
782
- this (false );
783
- }
784
-
785
- public JGitFactory (boolean cloneSubmodules ) {
786
- this .cloneSubmodules = cloneSubmodules ;
787
- }
788
-
789
798
public Git getGitByOpen (File file ) throws IOException {
790
799
Git git = Git .open (file );
791
800
return git ;
792
801
}
793
802
794
803
public CloneCommand getCloneCommandByCloneRepository () {
795
- CloneCommand command = Git .cloneRepository (). setCloneSubmodules ( cloneSubmodules ) ;
804
+ CloneCommand command = Git .cloneRepository ();
796
805
return command ;
797
806
}
798
807
0 commit comments