package bluej.groupwork.git;

import bluej.groupwork.TeamworkCommandAborted;
import bluej.groupwork.TeamworkCommandError;
import bluej.groupwork.TeamworkCommandResult;
import static bluej.groupwork.git.GitProvider.connectionDiagnosis;
import bluej.utility.DialogManager;
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.lib.StoredConfig;


| Clone a remote repository into a local directory. | @author Fabio Hedayioglu | public class GitCloneCommand extends GitCommand { private File clonePath; public GitCloneCommand(GitRepository repository, File projectPath) { super(repository); this.clonePath = projectPath; } @Override public TeamworkCommandResult getResult() { String reposUrl= ""; try { reposUrl = getRepository().getReposUrl(); CloneCommand cloneCommand = Git.cloneRepository(); disableFingerprintCheck(cloneCommand); cloneCommand.setDirectory(clonePath); cloneCommand.setURI(reposUrl); StoredConfig repoConfig = cloneCommand.call().getRepository().getConfig(); repoConfig.setString("user", null, "name", getRepository().getYourName()); repoConfig.setString("user", null, "email", getRepository().getYourEmail()); repoConfig.save(); if (!isCancelled()) { return new TeamworkCommandResult(); } return new TeamworkCommandAborted(); } catch (GitAPIException | IOException ex) { if (ex.getCause() instanceof NoRemoteRepositoryException){ String message = DialogManager.getMessage("team-noRepository-uri", ex.getLocalizedMessage()); return new TeamworkCommandError(message, message); } if (ex instanceof InvalidRemoteException) { return new TeamworkCommandError(DialogManager.getMessage("team-cant-connect"), DialogManager.getMessage("team-cant-connect")); } if (ex.getCause() instanceof TransportException){ if (ex.getLocalizedMessage().contains("Auth fail")) { return new TeamworkCommandError(DialogManager.getMessage("team-denied-invalidUser"), DialogManager.getMessage("team-denied-invalidUser")); } TeamworkCommandResult diagnosis = connectionDiagnosis(reposUrl); if (diagnosis.isError()) { return diagnosis; } } return new TeamworkCommandError(ex.getMessage(), ex.getLocalizedMessage()); } } }
top, use, map, class GitCloneCommand

.   GitCloneCommand
.   getResult




88 neLoCode + 2 LoComm