Search in sources :

Example 21 with TestProject

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

the class GitMoveDeleteHookTest method testDeleteFolder.

@Test
public void testDeleteFolder() throws Exception {
    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"));
    // Modify the content before the move
    testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("folder/file.txt"), "other text");
    project.getProject().getFolder("folder").delete(true, null);
    dirCache.read();
    // Unlike delete file, dircache is untouched... pretty illogical
    // TODO: Change the behavior of the hook.
    assertNotNull(dirCache.getEntry("folder/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) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Example 22 with TestProject

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

the class GitMoveDeleteHookTest method testDeleteProject.

@Test
public void testDeleteProject() throws Exception {
    TestProject project = initRepoAboveProjectInsideWs("P/", "");
    testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
    AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt") });
    addToIndexOperation.execute(null);
    RepositoryMapping mapping = RepositoryMapping.getMapping(project.getProject());
    IPath gitDirAbsolutePath = mapping.getGitDirAbsolutePath();
    Repository db = FileRepositoryBuilder.create(gitDirAbsolutePath.toFile());
    DirCache index = DirCache.read(db.getIndexFile(), db.getFS());
    assertNotNull(index.getEntry("P/Project-1/file.txt"));
    db.close();
    db = null;
    project.getProject().delete(true, null);
    assertNull(RepositoryMapping.getMapping(project.getProject()));
    // Check that the repo is still there. Being a bit paranoid we look for
    // a file
    assertTrue(gitDirAbsolutePath.toString(), gitDirAbsolutePath.append("HEAD").toFile().exists());
    db = FileRepositoryBuilder.create(gitDirAbsolutePath.toFile());
    index = DirCache.read(db.getIndexFile(), db.getFS());
    // FIXME: Shouldn't we unstage deleted projects?
    assertNotNull(index.getEntry("P/Project-1/file.txt"));
    db.close();
}
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) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Example 23 with TestProject

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

the class GitMoveDeleteHookTest method initRepoAboveProject.

private TestProject initRepoAboveProject(String srcParent, String d, boolean insidews) throws Exception {
    registerWorkspaceRelativeTestDir(srcParent);
    TestProject project = new TestProject(true, srcParent + "Project-1", insidews, workspaceSupplement);
    File gd = new File(insidews ? workspace : workspaceSupplement, d);
    File gitDir = new File(gd, Constants.DOT_GIT);
    testDirs.add(gitDir);
    testRepository = new TestRepository(gitDir);
    repository = testRepository.getRepository();
    testRepository.connect(project.getProject());
    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 24 with TestProject

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

the class GitMoveDeleteHookTest method testDeleteFile.

@Theory
public void testDeleteFile(boolean autoStageDelete) throws Exception {
    IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
    p.putBoolean(GitCorePreferences.core_autoStageDeletion, autoStageDelete);
    TestProject project = initRepoInsideProjectInsideWorkspace();
    testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
    testUtils.addFileToProject(project.getProject(), "file2.txt", "some  more text");
    IFile file = project.getProject().getFile("file.txt");
    AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { file, project.getProject().getFile("file2.txt") });
    addToIndexOperation.execute(null);
    // Validate pre-conditions
    DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
    assertEquals(2, dirCache.getEntryCount());
    assertNotNull(dirCache.getEntry("file.txt"));
    assertNotNull(dirCache.getEntry("file2.txt"));
    // Modify the content before the move
    testUtils.changeContentOfFile(project.getProject(), file, "other text");
    TestUtils.waitForJobs(500, 10000, JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    file.delete(true, null);
    TestUtils.waitForJobs(500, 10000, JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    // Check index for the deleted file
    dirCache.read();
    if (autoStageDelete) {
        assertEquals(1, dirCache.getEntryCount());
        assertNull(dirCache.getEntry("file.txt"));
    } else {
        assertEquals(2, dirCache.getEntryCount());
        assertNotNull(dirCache.getEntry("file.txt"));
    }
    assertNotNull(dirCache.getEntry("file2.txt"));
    // Actual file is deleted
    assertFalse(file.exists());
    // But a non-affected file remains
    assertTrue(project.getProject().getFile("file2.txt").exists());
}
Also used : DirCache(org.eclipse.jgit.dircache.DirCache) IFile(org.eclipse.core.resources.IFile) TestProject(org.eclipse.egit.core.test.TestProject) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Theory(org.junit.experimental.theories.Theory)

Example 25 with TestProject

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

the class GitMoveDeleteHookTest method testMoveFile.

@Theory
public void testMoveFile(boolean autoStageMoves) throws Exception {
    configureAutoStageMoves(autoStageMoves);
    TestProject project = initRepoInsideProjectInsideWorkspace();
    testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
    testUtils.addFileToProject(project.getProject(), "file2.txt", "some  more text");
    AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt"), project.getProject().getFile("file2.txt") });
    addToIndexOperation.execute(null);
    // Validate pre-conditions
    DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
    assertNotNull(dirCache.getEntry("file.txt"));
    assertNotNull(dirCache.getEntry("file2.txt"));
    assertNull(dirCache.getEntry("data.txt"));
    assertFalse(project.getProject().getFile("data.txt").exists());
    ObjectId oldContentId = dirCache.getEntry("file.txt").getObjectId();
    // Modify the content before the move
    testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("file.txt"), "other text");
    project.getProject().getFile("file.txt").move(project.getProject().getFile("data.txt").getFullPath(), false, null);
    dirCache.read();
    assertTrue(project.getProject().getFile("data.txt").exists());
    if (autoStageMoves) {
        assertNotNull(dirCache.getEntry("data.txt"));
        // Same content in index as before the move
        assertEquals(oldContentId, dirCache.getEntry("data.txt").getObjectId());
    } else {
        assertNull(dirCache.getEntry("data.txt"));
    }
    // Not moved file still in its old place
    assertNotNull(dirCache.getEntry("file2.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)

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