Search in sources :

Example 16 with AddToIndexOperation

use of org.eclipse.egit.core.op.AddToIndexOperation in project jbosstools-openshift by jbosstools.

the class EGitUtils method addToRepository.

public static void addToRepository(Collection<IResource> resources, IProgressMonitor monitor) throws CoreException {
    AddToIndexOperation add = new AddToIndexOperation(resources);
    add.execute(monitor);
}
Also used : AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation)

Example 17 with AddToIndexOperation

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

the class GitMoveDeleteHookTest method testMoveButDoNotRenameProjectOutsideWorkspaceContainingGitRepo.

/**
 * Move a project outside the workspace containing a Git repository, but do not rename it.
 * <p>
 * Note the similarity of the code with {@link #testMoveAndRenameProjectContainingGitRepo()}
 *
 * @throws Exception
 */
@Test
public void testMoveButDoNotRenameProjectOutsideWorkspaceContainingGitRepo() 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.setLocationURI(URIUtil.toURI(new Path(new File(project.getWorkspaceSupplement(), "P2").getAbsolutePath())));
    project.getProject().move(description, IResource.FORCE | IResource.SHALLOW, null);
    IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject(// same name
    "Project-1");
    assertNotNull(RepositoryMapping.getMapping(project2.getProject()));
    Repository movedRepo = RepositoryMapping.getMapping(project2).getRepository();
    assertEquals("P2", movedRepo.getDirectory().getParentFile().getName());
    DirCache dc = movedRepo.readDirCache();
    assertEquals(1, dc.getEntryCount());
    assertEquals("file.txt", dc.getEntry(0).getPathString());
    assertFalse(ResourcesPlugin.getWorkspace().getRoot().getProject("P2").exists());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) 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) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Example 18 with AddToIndexOperation

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

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

use of org.eclipse.egit.core.op.AddToIndexOperation 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)

Aggregations

AddToIndexOperation (org.eclipse.egit.core.op.AddToIndexOperation)35 Test (org.junit.Test)26 IFile (org.eclipse.core.resources.IFile)25 TestProject (org.eclipse.egit.core.test.TestProject)9 DirCache (org.eclipse.jgit.dircache.DirCache)9 RemoveFromIndexOperation (org.eclipse.egit.core.op.RemoveFromIndexOperation)7 CommitOperation (org.eclipse.egit.core.op.CommitOperation)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ArrayList (java.util.ArrayList)5 IProject (org.eclipse.core.resources.IProject)5 TestRepository (org.eclipse.egit.core.test.TestRepository)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)4 IResource (org.eclipse.core.resources.IResource)4 CoreException (org.eclipse.core.runtime.CoreException)4 IPath (org.eclipse.core.runtime.IPath)4 Repository (org.eclipse.jgit.lib.Repository)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 File (java.io.File)3 IFolder (org.eclipse.core.resources.IFolder)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3