Search in sources :

Example 1 with ConnectProviderOperation

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

the class AbstractSynchronizeViewTest method createEmptyRepository.

// based on LocalRepositoryTestCase#createProjectAndCommitToRepository(String)
protected void createEmptyRepository() throws Exception {
    File gitDir = new File(new File(getTestDirectory(), EMPTY_REPOSITORY), Constants.DOT_GIT);
    Repository myRepository = FileRepositoryBuilder.create(gitDir);
    myRepository.create();
    // we need to commit into master first
    IProject firstProject = ResourcesPlugin.getWorkspace().getRoot().getProject(EMPTY_PROJECT);
    if (firstProject.exists()) {
        firstProject.delete(true, null);
        TestUtil.waitForJobs(100, 5000);
    }
    IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(EMPTY_PROJECT);
    desc.setLocation(new Path(new File(myRepository.getWorkTree(), EMPTY_PROJECT).getPath()));
    firstProject.create(desc, null);
    firstProject.open(null);
    assertTrue("Project is not accessible: " + firstProject, firstProject.isAccessible());
    IFolder folder = firstProject.getFolder(FOLDER);
    folder.create(false, true, null);
    IFile textFile = folder.getFile(FILE1);
    textFile.create(new ByteArrayInputStream("Hello, world".getBytes(firstProject.getDefaultCharset())), false, null);
    IFile textFile2 = folder.getFile(FILE2);
    textFile2.create(new ByteArrayInputStream("Some more content".getBytes(firstProject.getDefaultCharset())), false, null);
    TestUtil.waitForJobs(50, 5000);
    try {
        new ConnectProviderOperation(firstProject, gitDir).execute(null);
    } catch (Exception e) {
        Activator.logError("Failed to connect project to repository", e);
    }
    assertConnected(firstProject);
}
Also used : Path(org.eclipse.core.runtime.Path) Repository(org.eclipse.jgit.lib.Repository) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with ConnectProviderOperation

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

the class SynchronizeViewRemoteAwareChangeSetModelTest method createMockLogicalRepository.

protected void createMockLogicalRepository() throws Exception {
    File gitDir = new File(new File(getTestDirectory(), MOCK_LOGICAL_PROJECT), Constants.DOT_GIT);
    Repository repo = FileRepositoryBuilder.create(gitDir);
    repo.create();
    // we need to commit into master first
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(MOCK_LOGICAL_PROJECT);
    if (project.exists()) {
        project.delete(true, null);
        TestUtil.waitForJobs(100, 5000);
    }
    IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(MOCK_LOGICAL_PROJECT);
    desc.setLocation(new Path(new File(repo.getWorkTree(), MOCK_LOGICAL_PROJECT).getPath()));
    project.create(desc, null);
    project.open(null);
    assertTrue("Project is not accessible: " + project, project.isAccessible());
    TestUtil.waitForJobs(50, 5000);
    try {
        new ConnectProviderOperation(project, gitDir).execute(null);
    } catch (Exception e) {
        Activator.logError("Failed to connect project to repository", e);
    }
    assertConnected(project);
    mockLogicalFile = project.getFile("index.mocklogical");
    mockLogicalFile.create(new ByteArrayInputStream("file1.txt\nfile2.txt".getBytes(project.getDefaultCharset())), false, null);
    IFile file1 = project.getFile("file1.txt");
    file1.create(new ByteArrayInputStream("Content 1".getBytes(project.getDefaultCharset())), false, null);
    IFile file2 = project.getFile("file2.txt");
    file2.create(new ByteArrayInputStream("Content 2".getBytes(project.getDefaultCharset())), false, null);
    IFile[] commitables = new IFile[] { mockLogicalFile, file1, file2 };
    List<IFile> untracked = new ArrayList<>();
    untracked.addAll(Arrays.asList(commitables));
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
    op.execute(null);
    RevCommit firstCommit = op.getCommit();
    CreateLocalBranchOperation createBranchOp = new CreateLocalBranchOperation(repo, "refs/heads/stable", firstCommit);
    createBranchOp.execute(null);
    // Delete file2.txt from logical model and add file3
    mockLogicalFile = touch(MOCK_LOGICAL_PROJECT, "index.mocklogical", "file1.txt\nfile3.txt");
    file2.delete(true, null);
    touch(MOCK_LOGICAL_PROJECT, "file1.txt", "Content 1 modified");
    IFile file3 = project.getFile("file3.txt");
    file3.create(new ByteArrayInputStream("Content 3".getBytes(project.getDefaultCharset())), false, null);
    commitables = new IFile[] { mockLogicalFile, file1, file2, file3 };
    untracked = new ArrayList<>();
    untracked.add(file3);
    op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Second commit");
    op.execute(null);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) IProject(org.eclipse.core.resources.IProject) Repository(org.eclipse.jgit.lib.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) CommitOperation(org.eclipse.egit.core.op.CommitOperation) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 3 with ConnectProviderOperation

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

the class SharingWizard method performFinish.

@Override
public boolean performFinish() {
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    if (!existingPage.getInternalMode()) {
        try {
            final Map<IProject, File> projectsToMove = existingPage.getProjects(true);
            final Repository selectedRepository = existingPage.getSelectedRepository();
            getContainer().run(true, false, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    SubMonitor progress = SubMonitor.convert(monitor, projectsToMove.size() * 2);
                    for (Map.Entry<IProject, File> entry : projectsToMove.entrySet()) {
                        closeOpenEditorsForProject(activePage, entry.getKey());
                        IPath targetLocation = new Path(entry.getValue().getPath());
                        IPath currentLocation = entry.getKey().getLocation();
                        if (!targetLocation.equals(currentLocation)) {
                            MoveProjectOperation op = new MoveProjectOperation(entry.getKey(), entry.getValue().toURI(), UIText.SharingWizard_MoveProjectActionLabel);
                            try {
                                IStatus result = op.execute(progress.newChild(1), null);
                                if (!result.isOK())
                                    throw new RuntimeException();
                            } catch (ExecutionException e) {
                                if (e.getCause() != null)
                                    throw new InvocationTargetException(e.getCause());
                                throw new InvocationTargetException(e);
                            }
                        } else {
                            progress.worked(1);
                        }
                        try {
                            new ConnectProviderOperation(entry.getKey(), selectedRepository.getDirectory()).execute(progress.newChild(1));
                        } catch (CoreException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                }
            });
        } catch (InvocationTargetException e) {
            Activator.handleError(UIText.SharingWizard_failed, e.getCause(), true);
            return false;
        } catch (InterruptedException e) {
        // ignore for the moment
        }
        return true;
    } else {
        final ConnectProviderOperation op = new ConnectProviderOperation(existingPage.getProjects(true));
        try {
            getContainer().run(true, false, new IRunnableWithProgress() {

                @Override
                public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                    try {
                        op.execute(monitor);
                        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                            @Override
                            public void run() {
                                Set<File> filesToAdd = new HashSet<>();
                                // collect all files first
                                for (Entry<IProject, File> entry : existingPage.getProjects(true).entrySet()) filesToAdd.add(entry.getValue());
                                // view
                                for (File file : filesToAdd) Activator.getDefault().getRepositoryUtil().addConfiguredRepository(file);
                            }
                        });
                    } catch (CoreException ce) {
                        throw new InvocationTargetException(ce);
                    }
                }
            });
            return true;
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException) {
                e = e.getCause();
            }
            if (e instanceof CoreException) {
                IStatus status = ((CoreException) e).getStatus();
                e = status.getException();
            }
            Activator.handleError(UIText.SharingWizard_failed, e, true);
            return false;
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Entry(java.util.Map.Entry) ExecutionException(org.eclipse.core.commands.ExecutionException) HashSet(java.util.HashSet) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) MoveProjectOperation(org.eclipse.ui.ide.undo.MoveProjectOperation)

Example 4 with ConnectProviderOperation

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

the class ConnectProviderOperationTest method testNewRepositoryCaseSensitive.

@Test
public void testNewRepositoryCaseSensitive() throws CoreException, IOException {
    if (FS.detect().isCaseSensitive()) {
        return;
    }
    Repository repository = FileRepositoryBuilder.create(gitDir);
    repository.create();
    repository.close();
    IPath path = new Path(gitDir.toString());
    String device = path.getDevice();
    if (device == null) {
        // not windows???
        return;
    }
    if (!device.toLowerCase(Locale.ROOT).equals(device)) {
        path = path.setDevice(device.toLowerCase(Locale.ROOT));
    } else {
        path = path.setDevice(device.toUpperCase(Locale.ROOT));
    }
    assertNotEquals(path, new Path(gitDir.toString()));
    assertNotEquals(path.toFile().toString(), new Path(gitDir.toString()).toFile().toString());
    assertEquals(path.toFile(), gitDir);
    ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), path.toFile());
    operation.execute(null);
    assertTrue(RepositoryProvider.isShared(project.getProject()));
    assertTrue(gitDir.exists());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) IPath(org.eclipse.core.runtime.IPath) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) Test(org.junit.Test)

Example 5 with ConnectProviderOperation

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

the class DualRepositoryTestCase method importProject.

protected IProject importProject(TestRepository repo, String projectName) throws Exception {
    IProject firstProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (firstProject.exists())
        firstProject.delete(false, null);
    IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
    File parentFile = repo.getRepository().getWorkTree();
    desc.setLocation(new Path(new File(parentFile, projectName).getPath()));
    firstProject.create(desc, null);
    firstProject.open(null);
    ConnectProviderOperation cop = new ConnectProviderOperation(firstProject, repo.getRepository().getDirectory());
    cop.execute(null);
    return firstProject;
}
Also used : Path(org.eclipse.core.runtime.Path) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Aggregations

ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)29 IProject (org.eclipse.core.resources.IProject)16 File (java.io.File)14 Repository (org.eclipse.jgit.lib.Repository)12 Test (org.junit.Test)11 IFile (org.eclipse.core.resources.IFile)10 CoreException (org.eclipse.core.runtime.CoreException)9 Path (org.eclipse.core.runtime.Path)9 IProjectDescription (org.eclipse.core.resources.IProjectDescription)7 IPath (org.eclipse.core.runtime.IPath)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 ArrayList (java.util.ArrayList)6 IFolder (org.eclipse.core.resources.IFolder)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 TestRepository (org.eclipse.egit.core.test.TestRepository)4 Git (org.eclipse.jgit.api.Git)4 HashMap (java.util.HashMap)3