Search in sources :

Example 11 with CloneOperation

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

the class GitRepositoriesViewFetchAndPushTest method before.

@Before
public void before() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    remoteRepositoryFile = createRemoteRepository(repositoryFile);
    // now let's clone the remote repository
    URIish uri = new URIish("file:///" + remoteRepositoryFile.getPath());
    File workdir = new File(getTestDirectory(), "ClonedRepo");
    CloneOperation op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0);
    op.run(null);
    clonedRepositoryFile = new File(workdir, Constants.DOT_GIT);
    // now let's clone the remote repository
    uri = new URIish(remoteRepositoryFile.getPath());
    workdir = new File(getTestDirectory(), "ClonedRepo2");
    op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0);
    op.run(null);
    clonedRepositoryFile2 = new File(workdir, Constants.DOT_GIT);
    clearView();
    deleteAllProjects();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) File(java.io.File) CloneOperation(org.eclipse.egit.core.op.CloneOperation) Before(org.junit.Before)

Example 12 with CloneOperation

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

the class CloneOperationTest method cloneAndAssert.

private void cloneAndAssert(String refName) throws Exception {
    URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString());
    CloneOperation clop = new CloneOperation(uri, true, null, workdir2, refName, "origin", 0);
    clop.run(null);
    Repository clonedRepo = FileRepositoryBuilder.create(new File(workdir2, Constants.DOT_GIT));
    assertEquals("", uri.toString(), clonedRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "url"));
    assertEquals("", "+refs/heads/*:refs/remotes/origin/*", clonedRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch"));
}
Also used : URIish(org.eclipse.jgit.transport.URIish) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) File(java.io.File) CloneOperation(org.eclipse.egit.core.op.CloneOperation)

Example 13 with CloneOperation

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

the class CloneOperationTest method testConfigurePushAfterCloneTask.

@Test
public void testConfigurePushAfterCloneTask() throws Exception {
    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 ConfigurePushAfterCloneTask("origin", "HEAD:refs/for/master", new URIish("file:///pushtarget")));
    clop.run(null);
    Repository clonedRepo = FileRepositoryBuilder.create(new File(workdir2, Constants.DOT_GIT));
    assertEquals("", "HEAD:refs/for/master", clonedRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "push"));
    assertEquals("", "file:///pushtarget", clonedRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "pushurl"));
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ConfigurePushAfterCloneTask(org.eclipse.egit.core.op.ConfigurePushAfterCloneTask) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) File(java.io.File) CloneOperation(org.eclipse.egit.core.op.CloneOperation) Test(org.junit.Test)

Example 14 with CloneOperation

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

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

the class AbstractDualRepositoryTestCase method beforeTestCase.

@Override
@Before
public void beforeTestCase() throws Exception {
    workdir = testUtils.createTempDir("Repository1");
    workdir2 = testUtils.createTempDir("Repository2");
    repository1 = new TestRepository(new File(workdir, DOT_GIT));
    initialCommit = repository1.createInitialCommit("setUp");
    Repository repository = repository1.getRepository();
    new InitOperation(repository).execute(null);
    // 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, R_HEADS + MY_MASTER, DEFAULT_REMOTE_NAME, 0);
    clop.run(null);
    Repository repo2 = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, DOT_GIT));
    repository2 = new TestRepository(repo2);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) TestRepository(org.eclipse.egit.core.test.TestRepository) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) 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) Before(org.junit.Before)

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