Search in sources :

Example 1 with PostCloneTask

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

the class CloneOperationTest method testSimplePostCloneTask.

@Test
public void testSimplePostCloneTask() throws Exception {
    URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString());
    CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
    final File[] repoDir = new File[1];
    clop.addPostCloneTask(new PostCloneTask() {

        @Override
        public void execute(Repository repository, IProgressMonitor monitor) throws CoreException {
            repoDir[0] = repository.getDirectory();
        }
    });
    clop.run(null);
    File newRepoDir = new File(workdir2, Constants.DOT_GIT);
    assertEquals(newRepoDir, repoDir[0]);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) PostCloneTask(org.eclipse.egit.core.op.CloneOperation.PostCloneTask) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) CloneOperation(org.eclipse.egit.core.op.CloneOperation) Test(org.junit.Test)

Example 2 with PostCloneTask

use of org.eclipse.egit.core.op.CloneOperation.PostCloneTask 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

File (java.io.File)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 CloneOperation (org.eclipse.egit.core.op.CloneOperation)2 PostCloneTask (org.eclipse.egit.core.op.CloneOperation.PostCloneTask)2 Repository (org.eclipse.jgit.lib.Repository)2 URIish (org.eclipse.jgit.transport.URIish)2 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 UserPasswordCredentials (org.eclipse.egit.core.securestorage.UserPasswordCredentials)1 TestRepository (org.eclipse.egit.core.test.TestRepository)1 EGitCredentialsProvider (org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)1 Ref (org.eclipse.jgit.lib.Ref)1 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)1 IWorkingSet (org.eclipse.ui.IWorkingSet)1 Test (org.junit.Test)1