Search in sources :

Example 11 with EGitCredentialsProvider

use of org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider 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

EGitCredentialsProvider (org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 PushOperationResult (org.eclipse.egit.core.op.PushOperationResult)4 Repository (org.eclipse.jgit.lib.Repository)4 URIish (org.eclipse.jgit.transport.URIish)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 PushOperationSpecification (org.eclipse.egit.core.op.PushOperationSpecification)3 UserPasswordCredentials (org.eclipse.egit.core.securestorage.UserPasswordCredentials)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 URISyntaxException (java.net.URISyntaxException)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Job (org.eclipse.core.runtime.jobs.Job)2 ListRemoteOperation (org.eclipse.egit.core.op.ListRemoteOperation)2 PushOperation (org.eclipse.egit.core.op.PushOperation)2 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)2 Ref (org.eclipse.jgit.lib.Ref)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 RefSpec (org.eclipse.jgit.transport.RefSpec)2