Search in sources :

Example 11 with ConnectProviderOperation

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

the class IndexDiffCacheTest method testAddingAFile.

@Test
public void testAddingAFile() throws Exception {
    new ConnectProviderOperation(project.project, repository.getDirectory()).execute(null);
    // create first commit containing a dummy file
    testRepository.createInitialCommit("testBranchOperation\n\nfirst commit\n");
    prepareCacheEntry();
    waitForListenerCalled();
    final String fileName = "aFile";
    // This call should trigger an indexDiffChanged event (triggered via
    // resource changed event)
    project.createFile(fileName, "content".getBytes("UTF-8"));
    IndexDiffData indexDiffData = waitForListenerCalled();
    String path = project.project.getFile(fileName).getFullPath().toString().substring(1);
    if (!indexDiffData.getUntracked().contains(path))
        fail("IndexDiffData did not contain aFile as untracked");
    // This call should trigger an indexDiffChanged event
    try (Git git = new Git(repository)) {
        git.add().addFilepattern(path).call();
    }
    IndexDiffData indexDiffData2 = waitForListenerCalled();
    if (indexDiffData2.getUntracked().contains(path))
        fail("IndexDiffData contains aFile as untracked");
    if (!indexDiffData2.getAdded().contains(path))
        fail("IndexDiffData does not contain aFile as added");
}
Also used : Git(org.eclipse.jgit.api.Git) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 12 with ConnectProviderOperation

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

the class ProjectUtilTest method testRefreshRepositoryResources.

@Test
public void testRefreshRepositoryResources() throws Exception {
    TestProject subdirProject = new TestProject(true, "subdir/Project-2");
    new ConnectProviderOperation(project.getProject(), repository.getRepository().getDirectory()).execute(null);
    new ConnectProviderOperation(subdirProject.getProject(), repository.getRepository().getDirectory()).execute(null);
    IFile file1 = createOutOfSyncFile(project, "refresh1");
    ProjectUtil.refreshRepositoryResources(repository.getRepository(), Arrays.asList("Project-1/refresh1"), new NullProgressMonitor());
    assertTrue(file1.isSynchronized(IResource.DEPTH_ZERO));
    IFile file2 = createOutOfSyncFile(project, "refresh2");
    ProjectUtil.refreshRepositoryResources(repository.getRepository(), Arrays.asList("Project-1"), new NullProgressMonitor());
    assertTrue(file2.isSynchronized(IResource.DEPTH_ZERO));
    IFile file3 = createOutOfSyncFile(project, "refresh3");
    ProjectUtil.refreshRepositoryResources(repository.getRepository(), Arrays.asList(""), new NullProgressMonitor());
    assertTrue(file3.isSynchronized(IResource.DEPTH_ZERO));
    IFile file4 = createOutOfSyncFile(subdirProject, "refresh4");
    ProjectUtil.refreshRepositoryResources(repository.getRepository(), Arrays.asList("subdir"), new NullProgressMonitor());
    assertTrue(file4.isSynchronized(IResource.DEPTH_ZERO));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) TestProject(org.eclipse.egit.core.test.TestProject) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) Test(org.junit.Test)

Example 13 with ConnectProviderOperation

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

the class ProjectUtilTest method testGetProjects.

@Test
public void testGetProjects() throws Exception {
    ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
    operation.execute(null);
    IProject[] projects = ProjectUtil.getProjects(repository.getRepository());
    assertEquals(1, projects.length);
    IProject p = projects[0];
    assertEquals("Project-1", p.getDescription().getName());
}
Also used : ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 14 with ConnectProviderOperation

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

the class ResourceUtilTest method connect.

private void connect(IProject p) throws CoreException {
    ConnectProviderOperation operation = new ConnectProviderOperation(p, gitDir);
    operation.execute(null);
}
Also used : ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation)

Example 15 with ConnectProviderOperation

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

the class GitCreateProjectViaWizardWizard method importProjects.

private void importProjects(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    switch(mySelectionPage.getWizardSelection()) {
        case GitSelectWizardPage.EXISTING_PROJECTS_WIZARD:
            {
                final Set<ProjectRecord> projectsToCreate = new HashSet<>();
                final List<IWorkingSet> workingSets = new ArrayList<>();
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectsToCreate.addAll(myProjectsImportPage.getCheckedProjects());
                        IWorkingSet[] workingSetArray = myProjectsImportPage.getSelectedWorkingSets();
                        workingSets.addAll(Arrays.asList(workingSetArray));
                        myProjectsImportPage.saveWidgetValues();
                    }
                });
                ProjectUtils.createProjects(projectsToCreate, workingSets.toArray(new IWorkingSet[workingSets.size()]), monitor);
                break;
            }
        case GitSelectWizardPage.NEW_WIZARD:
            {
                final List<IProject> previousProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
                    }
                });
                IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor actMonitor) throws CoreException {
                        IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                        SubMonitor progress = SubMonitor.convert(monitor, currentProjects.length);
                        for (IProject current : currentProjects) {
                            if (!previousProjects.contains(current)) {
                                ConnectProviderOperation cpo = new ConnectProviderOperation(current, myRepository.getDirectory());
                                cpo.execute(progress.newChild(1));
                            } else {
                                progress.worked(1);
                            }
                        }
                    }
                };
                try {
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
        case GitSelectWizardPage.GENERAL_WIZARD:
            {
                final String[] projectName = new String[1];
                final boolean[] defaultLocation = new boolean[1];
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectName[0] = myCreateGeneralProjectPage.getProjectName();
                        defaultLocation[0] = myCreateGeneralProjectPage.isDefaultLocation();
                    }
                });
                try {
                    IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor actMonitor) throws CoreException {
                            final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName[0]);
                            if (!defaultLocation[0]) {
                                desc.setLocation(new Path(myGitDir));
                            }
                            SubMonitor progress = SubMonitor.convert(actMonitor, 4);
                            IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(desc.getName());
                            prj.create(desc, progress.newChild(1));
                            prj.open(progress.newChild(1));
                            ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ONE, progress.newChild(1));
                            File repoDir = myRepository.getDirectory();
                            ConnectProviderOperation cpo = new ConnectProviderOperation(prj, repoDir);
                            cpo.execute(progress.newChild(1));
                        }
                    };
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProjectDescription(org.eclipse.core.resources.IProjectDescription) NewProjectAction(org.eclipse.ui.actions.NewProjectAction) ArrayList(java.util.ArrayList) List(java.util.List) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) File(java.io.File) IWorkingSet(org.eclipse.ui.IWorkingSet)

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