Search in sources :

Example 6 with UserPasswordCredentials

use of org.eclipse.egit.core.securestorage.UserPasswordCredentials 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

UserPasswordCredentials (org.eclipse.egit.core.securestorage.UserPasswordCredentials)6 EGitCredentialsProvider (org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)3 File (java.io.File)2 URIish (org.eclipse.jgit.transport.URIish)2 URISyntaxException (java.net.URISyntaxException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 CloneOperation (org.eclipse.egit.core.op.CloneOperation)1 PostCloneTask (org.eclipse.egit.core.op.CloneOperation.PostCloneTask)1 PushOperation (org.eclipse.egit.core.op.PushOperation)1 PushOperationResult (org.eclipse.egit.core.op.PushOperationResult)1 RepositorySelection (org.eclipse.egit.ui.internal.components.RepositorySelection)1 UnsupportedCredentialItem (org.eclipse.jgit.errors.UnsupportedCredentialItem)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1 CredentialItem (org.eclipse.jgit.transport.CredentialItem)1 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)1