Search in sources :

Example 16 with CloneOperation

use of org.eclipse.egit.core.op.CloneOperation in project egit by eclipse.

the class AbstractGitCloneWizard method performClone.

/**
 * Do the clone using data which were collected on the pages
 * {@code validSource} and {@code cloneDestination}
 *
 * @param gitRepositoryInfo
 * @return if clone was successful
 * @throws URISyntaxException
 */
protected boolean performClone(GitRepositoryInfo gitRepositoryInfo) throws URISyntaxException {
    URIish uri = new URIish(gitRepositoryInfo.getCloneUri());
    UserPasswordCredentials credentials = gitRepositoryInfo.getCredentials();
    setWindowTitle(NLS.bind(UIText.GitCloneWizard_jobName, uri.toString()));
    final boolean allSelected;
    final Collection<Ref> selectedBranches;
    if (validSource.isSourceRepoEmpty()) {
        // fetch all branches of empty repo
        allSelected = true;
        selectedBranches = Collections.emptyList();
    } else {
        allSelected = validSource.isAllSelected();
        selectedBranches = validSource.getSelectedBranches();
    }
    final File workdir = cloneDestination.getDestinationFile();
    final Ref ref = cloneDestination.getInitialBranch();
    final String remoteName = cloneDestination.getRemote();
    boolean created = workdir.exists();
    if (!created)
        created = workdir.mkdirs();
    if (!created || !workdir.isDirectory()) {
        final String errorMessage = NLS.bind(UIText.GitCloneWizard_errorCannotCreate, workdir.getPath());
        ErrorDialog.openError(getShell(), getWindowTitle(), UIText.GitCloneWizard_failed, new Status(IStatus.ERROR, Activator.getPluginId(), 0, errorMessage, null));
        // let's give user a chance to fix this minor problem
        return false;
    }
    int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
    final CloneOperation op = new CloneOperation(uri, allSelected, selectedBranches, workdir, ref != null ? ref.getName() : null, remoteName, timeout);
    CredentialsProvider credentialsProvider = null;
    if (credentials != null) {
        credentialsProvider = new EGitCredentialsProvider(credentials.getUser(), credentials.getPassword());
    } else {
        credentialsProvider = new EGitCredentialsProvider();
    }
    op.setCredentialsProvider(credentialsProvider);
    op.setCloneSubmodules(cloneDestination.isCloneSubmodules());
    rememberHttpHost(op, uri);
    configureFetchSpec(op, gitRepositoryInfo, remoteName);
    configurePush(op, gitRepositoryInfo, remoteName);
    configureRepositoryConfig(op, gitRepositoryInfo);
    configureGerrit(op, gitRepositoryInfo, credentialsProvider, remoteName, timeout);
    if (cloneDestination.isImportProjects()) {
        final IWorkingSet[] sets = cloneDestination.getWorkingSets();
        op.addPostCloneTask(new PostCloneTask() {

            @Override
            public void execute(Repository repository, IProgressMonitor monitor) throws CoreException {
                importProjects(repository, sets);
            }
        });
    }
    alreadyClonedInto = workdir.getPath();
    if (!callerRunsCloneOperation)
        runAsJob(uri, op, gitRepositoryInfo);
    else
        cloneOperation = op;
    return true;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) PostCloneTask(org.eclipse.egit.core.op.CloneOperation.PostCloneTask) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) UserPasswordCredentials(org.eclipse.egit.core.securestorage.UserPasswordCredentials) CloneOperation(org.eclipse.egit.core.op.CloneOperation) Ref(org.eclipse.jgit.lib.Ref) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) IWorkingSet(org.eclipse.ui.IWorkingSet)

Aggregations

CloneOperation (org.eclipse.egit.core.op.CloneOperation)16 File (java.io.File)15 URIish (org.eclipse.jgit.transport.URIish)15 Repository (org.eclipse.jgit.lib.Repository)10 TestRepository (org.eclipse.egit.core.test.TestRepository)7 Before (org.junit.Before)7 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 Test (org.junit.Test)3 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 RepositoryUtil (org.eclipse.egit.core.RepositoryUtil)2 PostCloneTask (org.eclipse.egit.core.op.CloneOperation.PostCloneTask)2 RefUpdate (org.eclipse.jgit.lib.RefUpdate)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedList (java.util.LinkedList)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 ProjectReference (org.eclipse.egit.core.ProjectReference)1