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;
}
Aggregations