Search in sources :

Example 1 with CloneOperation

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

the class GitRepositoriesViewBranchHandlingTest method setUp.

@Before
public void setUp() throws Exception {
    clearView();
    setVerboseBranchMode(false);
    repositoryFile = createProjectAndCommitToRepository();
    remoteRepositoryFile = createRemoteRepository(repositoryFile);
    // now let's clone the remote repository
    final URIish uri = new URIish(remoteRepositoryFile.getPath());
    final File workdir = new File(getTestDirectory(), "Cloned");
    CloneOperation op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0);
    op.run(null);
    clonedRepositoryFile = new File(workdir, Constants.DOT_GIT);
    RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
    repositoryUtil.addConfiguredRepository(repositoryFile);
    repositoryUtil.addConfiguredRepository(remoteRepositoryFile);
    repositoryUtil.addConfiguredRepository(clonedRepositoryFile);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) File(java.io.File) CloneOperation(org.eclipse.egit.core.op.CloneOperation) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) Before(org.junit.Before)

Example 2 with CloneOperation

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

the class ListRemoteOperationTest method setUp.

/**
 * Set up repository1 with branch "master", create some project and commit
 * it; then clone into repository2; finally create a branch "test" on top of
 * "master" in repository2
 *
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    workdir = testUtils.createTempDir("Repository1");
    workdir2 = testUtils.createTempDir("Repository2");
    repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT));
    // now we create a project in repo1
    IProject project = testUtils.createProjectInLocalFileSystem(workdir, projectName);
    testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");
    repository1.connect(project);
    repository1.trackAllFiles(project);
    repository1.commit("Initial commit");
    // let's get rid of the project
    project.delete(false, false, null);
    // let's clone repository1 to repository2
    URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString());
    CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
    clop.run(null);
    Repository existingRepo = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, Constants.DOT_GIT));
    repository2 = new TestRepository(existingRepo);
    // we push to branch "test" of repository2
    RefUpdate createBranch = repository2.getRepository().updateRef("refs/heads/test");
    createBranch.setNewObjectId(repository2.getRepository().resolve("refs/heads/master"));
    createBranch.update();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) TestRepository(org.eclipse.egit.core.test.TestRepository) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) File(java.io.File) IProject(org.eclipse.core.resources.IProject) CloneOperation(org.eclipse.egit.core.op.CloneOperation) RefUpdate(org.eclipse.jgit.lib.RefUpdate) Before(org.junit.Before)

Example 3 with CloneOperation

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

the class PushOperationTest method setUp.

/**
 * Set up repository1 with branch "master", create some project and commit
 * it; then clone into repository2; finally create a branch "test" on top of
 * "master" in repository2
 *
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    workdir = testUtils.createTempDir("Repository1");
    workdir2 = testUtils.createTempDir("Repository2");
    repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT));
    // now we create a project in repo1
    IProject project = testUtils.createProjectInLocalFileSystem(workdir, projectName);
    testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");
    repository1.connect(project);
    repository1.trackAllFiles(project);
    repository1.commit("Initial commit");
    // let's get rid of the project
    project.delete(false, false, null);
    // let's clone repository1 to repository2
    URIish uri = repository1.getUri();
    CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
    clop.run(null);
    Repository repo2 = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, Constants.DOT_GIT));
    repository2 = new TestRepository(repo2);
    // we push to branch "test" of repository2
    RefUpdate createBranch = repository2.getRepository().updateRef("refs/heads/test");
    createBranch.setNewObjectId(repository2.getRepository().resolve("refs/heads/master"));
    createBranch.update();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) TestRepository(org.eclipse.egit.core.test.TestRepository) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) CloneOperation(org.eclipse.egit.core.op.CloneOperation) RefUpdate(org.eclipse.jgit.lib.RefUpdate) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) Before(org.junit.Before)

Example 4 with CloneOperation

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

the class CloneOperationTest method testConfigureFetchAfterCloneTask.

@Test
public void testConfigureFetchAfterCloneTask() throws Exception {
    createNoteInOrigin();
    URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString());
    CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
    clop.addPostCloneTask(new ConfigureFetchAfterCloneTask("origin", "refs/notes/review:refs/notes/review"));
    clop.run(null);
    Repository clonedRepo = FileRepositoryBuilder.create(new File(workdir2, Constants.DOT_GIT));
    assertTrue(clonedRepo.getConfig().getStringList(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch")[1].equals("refs/notes/review:refs/notes/review"));
    Git clonedGit = new Git(clonedRepo);
    assertEquals(1, clonedGit.notesList().setNotesRef("refs/notes/review").call().size());
    clonedGit.close();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) ConfigureFetchAfterCloneTask(org.eclipse.egit.core.op.ConfigureFetchAfterCloneTask) File(java.io.File) CloneOperation(org.eclipse.egit.core.op.CloneOperation) Test(org.junit.Test)

Example 5 with CloneOperation

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

the class ProjectReferenceImporter method cloneIfNecessary.

private static File cloneIfNecessary(final URIish gitUrl, final String refToCheckout, final IPath workDir, final Set<ProjectReference> projects, IProgressMonitor monitor) throws TeamException, InterruptedException {
    final File repositoryPath = workDir.append(Constants.DOT_GIT_EXT).toFile();
    if (workDir.toFile().exists()) {
        if (repositoryAlreadyExistsForUrl(repositoryPath, gitUrl))
            return repositoryPath;
        else {
            final Collection<String> projectNames = new LinkedList<String>();
            for (final ProjectReference projectReference : projects) projectNames.add(projectReference.getProjectDir());
            throw new TeamException(NLS.bind(CoreText.GitProjectSetCapability_CloneToExistingDirectory, new Object[] { workDir, projectNames, gitUrl }));
        }
    } else {
        try {
            int timeout = 60;
            final CloneOperation cloneOperation = new CloneOperation(gitUrl, true, null, workDir.toFile(), refToCheckout, Constants.DEFAULT_REMOTE_NAME, timeout);
            cloneOperation.run(monitor);
            return repositoryPath;
        } catch (final InvocationTargetException e) {
            throw getTeamException(e);
        }
    }
}
Also used : TeamException(org.eclipse.team.core.TeamException) ProjectReference(org.eclipse.egit.core.ProjectReference) File(java.io.File) LinkedList(java.util.LinkedList) CloneOperation(org.eclipse.egit.core.op.CloneOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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