Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.StatusCommand;
import org.eclipse.jgit.api.SubmoduleUpdateCommand;
import org.eclipse.jgit.api.TransportCommand;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.api.errors.GitAPIException;
Expand Down Expand Up @@ -113,7 +114,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
*/
private boolean cloneOnStart;

private JGitEnvironmentRepository.JGitFactory gitFactory;
private JGitEnvironmentRepository.JGitFactory gitFactory = new JGitFactory();

private String defaultLabel;

Expand Down Expand Up @@ -146,6 +147,8 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
*/
private boolean skipSslValidation;

private boolean cloneSubmodules;

private boolean tryMasterBranch;

private final ObservationRegistry observationRegistry;
Expand All @@ -167,11 +170,19 @@ public JGitEnvironmentRepository(ConfigurableEnvironment environment, JGitEnviro
this.deleteUntrackedBranches = properties.isDeleteUntrackedBranches();
this.refreshRate = properties.getRefreshRate();
this.skipSslValidation = properties.isSkipSslValidation();
this.gitFactory = new JGitFactory(properties.isCloneSubmodules());
this.cloneSubmodules = properties.isCloneSubmodules();
this.tryMasterBranch = properties.isTryMasterBranch();
this.observationRegistry = observationRegistry;
}

public boolean isCloneSubmodules() {
return this.cloneSubmodules;
}

public void setCloneSubmodules(boolean cloneSubmodules) {
this.cloneSubmodules = cloneSubmodules;
}

public boolean isTryMasterBranch() {
return tryMasterBranch;
}
Expand Down Expand Up @@ -315,6 +326,13 @@ public String refresh(String label) {
if (this.deleteUntrackedBranches && fetchStatus != null) {
deleteUntrackedLocalBranches(fetchStatus.getTrackingRefUpdates(), git);
}

// update submodules if needed
if (cloneSubmodules) {
SubmoduleUpdateCommand submoduleUpdate = git.submoduleUpdate().setFetch(true);
configureCommand(submoduleUpdate);
submoduleUpdate.call();
}
}

// checkout after fetch so we can get any new branches, tags, ect.
Expand Down Expand Up @@ -669,6 +687,7 @@ private Git copyFromLocalRepository() throws IOException {

private Git cloneToBasedir() throws GitAPIException {
CloneCommand clone = this.gitFactory.getCloneCommandByCloneRepository()
.setCloneSubmodules(cloneSubmodules)
.setURI(getUri())
.setDirectory(getBasedir());
configureCommand(clone);
Expand Down Expand Up @@ -776,23 +795,13 @@ public void setLastRefresh(long lastRefresh) {
*/
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().setCloneSubmodules(cloneSubmodules);
CloneCommand command = Git.cloneRepository();
return command;
}

Expand Down