Adds option to clone git submodules.

Fixes gh-717
Fixes gh-1484
This commit is contained in:
Laisky
2019-09-29 15:37:48 +08:00
committed by spencergibb
parent bf2c61f722
commit 73e88e52da
2 changed files with 27 additions and 2 deletions

View File

@@ -40,6 +40,11 @@ public class JGitEnvironmentProperties extends AbstractScmAccessorProperties
*/
private boolean cloneOnStart = false;
/**
* Flag to indicate that the submodules in the repository should be cloned.
*/
private boolean cloneSubmodules = false;
/**
* Flag to indicate that the repository should force pull. If true discard any local
* changes and take from remote repository.
@@ -127,6 +132,14 @@ public class JGitEnvironmentProperties extends AbstractScmAccessorProperties
this.cloneOnStart = cloneOnStart;
}
public boolean isCloneSubmodules() {
return this.cloneSubmodules;
}
public void setCloneSubmodules(boolean cloneSubmodules) {
this.cloneSubmodules = cloneSubmodules;
}
public boolean isForcePull() {
return this.forcePull;
}

View File

@@ -112,7 +112,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
*/
private boolean cloneOnStart;
private JGitEnvironmentRepository.JGitFactory gitFactory = new JGitEnvironmentRepository.JGitFactory();
private JGitEnvironmentRepository.JGitFactory gitFactory;
private String defaultLabel;
@@ -157,6 +157,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
this.deleteUntrackedBranches = properties.isDeleteUntrackedBranches();
this.refreshRate = properties.getRefreshRate();
this.skipSslValidation = properties.isSkipSslValidation();
this.gitFactory = new JGitFactory(properties.isCloneSubmodules());
}
public boolean isCloneOnStart() {
@@ -705,13 +706,24 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
*/
public static class JGitFactory {
private final boolean cloneSubmodules;
public JGitFactory() {
this(false);
}
public JGitFactory(boolean cloneSubmodules) {
this.cloneSubmodules = cloneSubmodules;
}
public Git getGitByOpen(File file) throws IOException {
Git git = Git.open(file);
return git;
}
public CloneCommand getCloneCommandByCloneRepository() {
CloneCommand command = Git.cloneRepository();
CloneCommand command = Git.cloneRepository()
.setCloneSubmodules(cloneSubmodules);
return command;
}