Search in sources :

Example 6 with TestProject

use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.

the class ProjectUtilTest method testGetNestedProjectsContains.

@Test
public void testGetNestedProjectsContains() throws Exception {
    TestProject prj2 = new TestProject(true, "Project-1/dir/Project-1-sub");
    try {
        repository.createFile(project.getProject(), "xxx");
        repository.createFile(project.getProject(), "zzz");
        repository.createFile(prj2.getProject(), "zzz");
        project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
        prj2.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
        IProject[] projectsContaining = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-1/xxx"));
        IProject[] projectsEmpty = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("yyy"));
        IProject[] projectSelf = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-1"));
        Set<String> files = new TreeSet<String>();
        files.add("Project-1/xxx");
        files.add("Project-1/zzz");
        IProject[] multiFile = ProjectUtil.getProjectsContaining(repository.getRepository(), files);
        files.clear();
        files.add("Project-1/dir/Project-1-sub/zzz");
        files.add("Project-1/xxx");
        IProject[] multiProject = ProjectUtil.getProjectsContaining(repository.getRepository(), files);
        IProject[] nonExistProject = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-2"));
        assertEquals(1, projectsContaining.length);
        assertEquals(0, projectsEmpty.length);
        assertEquals(1, projectSelf.length);
        assertEquals(1, multiFile.length);
        assertEquals(2, multiProject.length);
        assertEquals(0, nonExistProject.length);
        IProject p = projectsContaining[0];
        assertEquals("Project-1", p.getDescription().getName());
    } finally {
        prj2.dispose();
    }
}
Also used : TestProject(org.eclipse.egit.core.test.TestProject) TreeSet(java.util.TreeSet) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 7 with TestProject

use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.

the class ResourceUtilTest method getFileForLocationShouldReturnExistingFileInCaseOfNestedProject.

@Ignore
@Test
public void getFileForLocationShouldReturnExistingFileInCaseOfNestedProject() throws Exception {
    TestProject nested = new TestProject(true, "Project-1/Project-2");
    connect(nested.getProject());
    IFile file = nested.createFile("a.txt", new byte[] {});
    IPath location = file.getLocation();
    IFile result = ResourceUtil.getFileForLocation(location, false);
    assertThat(result, notNullValue());
    assertTrue("Returned IFile should exist", result.exists());
    assertThat(result.getProject(), is(project.getProject()));
    result = ResourceUtil.getFileForLocation(location, true);
    assertThat(result, notNullValue());
    assertTrue("Returned IFile should exist", result.exists());
    assertThat(result.getProject(), is(nested.getProject()));
}
Also used : IFile(org.eclipse.core.resources.IFile) TestProject(org.eclipse.egit.core.test.TestProject) IPath(org.eclipse.core.runtime.IPath) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with TestProject

use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.

the class GitMoveDeleteHookTest method initRepoInsideProjectInsideWorkspace.

private TestProject initRepoInsideProjectInsideWorkspace() throws Exception {
    TestProject project = new TestProject(true, "Project-1", true, workspaceSupplement);
    File gitDir = new File(project.getProject().getLocationURI().getPath(), Constants.DOT_GIT);
    testDirs.add(gitDir);
    testRepository = new TestRepository(gitDir);
    repository = testRepository.getRepository();
    testRepository.connect(project.getProject());
    registerWorkspaceRelativeTestDir("Project-1");
    return project;
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) TestProject(org.eclipse.egit.core.test.TestProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 9 with TestProject

use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.

the class GitMoveDeleteHookTest method testMoveFolder.

/**
 * Rename "folder" to "dir".
 * @param autoStageMoves
 * @throws Exception
 */
@Theory
public void testMoveFolder(boolean autoStageMoves) throws Exception {
    configureAutoStageMoves(autoStageMoves);
    TestProject project = initRepoInsideProjectInsideWorkspace();
    testUtils.addFileToProject(project.getProject(), "folder/file.txt", "some text");
    testUtils.addFileToProject(project.getProject(), "folder2/file.txt", "some other text");
    AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("folder/file.txt"), project.getProject().getFile("folder2/file.txt") });
    addToIndexOperation.execute(null);
    DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
    assertNotNull(dirCache.getEntry("folder/file.txt"));
    assertNotNull(dirCache.getEntry("folder2/file.txt"));
    assertNull(dirCache.getEntry("dir/file.txt"));
    assertFalse(project.getProject().getFile("dir/file.txt").exists());
    ObjectId oldContentId = dirCache.getEntry("folder/file.txt").getObjectId();
    // Modify the content before the move
    testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("folder/file.txt"), "other text");
    project.getProject().getFolder("folder").move(project.getProject().getFolder("dir").getFullPath(), false, null);
    dirCache.read();
    assertTrue(project.getProject().getFile("dir/file.txt").exists());
    if (autoStageMoves) {
        assertNull(dirCache.getEntry("folder/file.txt"));
        assertNotNull(dirCache.getEntry("dir/file.txt"));
        // Same content in index as before the move
        assertEquals(oldContentId, dirCache.getEntry("dir/file.txt").getObjectId());
    } else {
        assertNotNull(dirCache.getEntry("folder/file.txt"));
        assertNull(dirCache.getEntry("dir/file.txt"));
    }
    // Not moved file still there
    assertNotNull(dirCache.getEntry("folder2/file.txt"));
}
Also used : DirCache(org.eclipse.jgit.dircache.DirCache) TestProject(org.eclipse.egit.core.test.TestProject) ObjectId(org.eclipse.jgit.lib.ObjectId) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Theory(org.junit.experimental.theories.Theory)

Example 10 with TestProject

use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.

the class GitMoveDeleteHookTest method testRenameProjectOutsideWorkspaceContainingGitRepo.

/**
 * Rename a project outside the workspace containing a Git repository.
 * <p>
 * Note the similarity of the code with {@link #testMoveAndRenameProjectContainingGitRepo()}
 *
 * @throws Exception
 */
@Test
public void testRenameProjectOutsideWorkspaceContainingGitRepo() throws Exception {
    ResourcesPlugin.getWorkspace().getRoot().getProject("Project-1").delete(true, null);
    ResourcesPlugin.getWorkspace().getRoot().getProject("P2").delete(true, null);
    TestProject project = initRepoInsideProjectOutsideWorkspace();
    testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
    AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt") });
    addToIndexOperation.execute(null);
    IProjectDescription description = project.getProject().getDescription();
    description.setName("P2");
    project.getProject().move(description, IResource.FORCE | IResource.SHALLOW, null);
    IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject("P2");
    assertNotNull(RepositoryMapping.getMapping(project2.getProject()));
    Repository movedRepo = RepositoryMapping.getMapping(project2).getRepository();
    assertEquals("Project-1", movedRepo.getDirectory().getParentFile().getName());
    DirCache dc = movedRepo.readDirCache();
    assertEquals(1, dc.getEntryCount());
    assertEquals("file.txt", dc.getEntry(0).getPathString());
    assertFalse(ResourcesPlugin.getWorkspace().getRoot().getProject("Project-1").exists());
}
Also used : DirCache(org.eclipse.jgit.dircache.DirCache) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) TestProject(org.eclipse.egit.core.test.TestProject) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Aggregations

TestProject (org.eclipse.egit.core.test.TestProject)27 IFile (org.eclipse.core.resources.IFile)17 Test (org.junit.Test)17 TestRepository (org.eclipse.egit.core.test.TestRepository)11 DirCache (org.eclipse.jgit.dircache.DirCache)11 File (java.io.File)9 AddToIndexOperation (org.eclipse.egit.core.op.AddToIndexOperation)9 IProject (org.eclipse.core.resources.IProject)8 IPath (org.eclipse.core.runtime.IPath)8 Repository (org.eclipse.jgit.lib.Repository)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Theory (org.junit.experimental.theories.Theory)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)4 Path (org.eclipse.core.runtime.Path)4 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 Ignore (org.junit.Ignore)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 IResource (org.eclipse.core.resources.IResource)2