Search in sources :

Example 1 with TestProject

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

the class RemoveFromIndexOperationTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    gitDir = new File(project.getProject().getLocationURI().getPath(), Constants.DOT_GIT);
    testRepo = new TestRepository(gitDir);
    testRepo.connect(project.getProject());
    testRepo.commit("initial commit");
    project2 = new TestProject(true, "Project-2");
    gitDir2 = new File(project2.getProject().getLocationURI().getPath(), Constants.DOT_GIT);
    testRepo2 = new TestRepository(gitDir2);
    testRepo2.connect(project2.getProject());
    testRepo2.commit("initial commit repo 2");
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) TestProject(org.eclipse.egit.core.test.TestProject) File(java.io.File) IFile(org.eclipse.core.resources.IFile) Before(org.junit.Before)

Example 2 with TestProject

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

the class CommonUtilsTest method testResourceCompare.

@Test
public void testResourceCompare() throws Exception {
    // we just want to test that we can call the JFace resource name
    // comparator which itself is tested by JFace
    TestProject p = new TestProject();
    p.createFolder("test");
    IFile f1 = p.createFile("test/z.txt", "z".getBytes("UTF-8"));
    IFile f2 = p.createFile("test/d.txt", "d".getBytes("UTF-8"));
    IFile f3 = p.createFile("test/a.txt", "a".getBytes("UTF-8"));
    List<IResource> expected = Arrays.asList(new IResource[] { f3, f2, f1 });
    List<IResource> tmp = new ArrayList<IResource>(expected);
    Collections.shuffle(tmp, new Random(1));
    Collections.sort(tmp, CommonUtils.RESOURCE_NAME_COMPARATOR);
    assertEquals(expected, tmp);
    // Clean up our mess
    IProgressMonitor monitor = new NullProgressMonitor();
    f1.delete(false, monitor);
    f2.delete(false, monitor);
    f3.delete(false, monitor);
    p.getProject().getFolder("test").delete(false, monitor);
    p.getProject().delete(false, monitor);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) TestProject(org.eclipse.egit.core.test.TestProject) Random(java.util.Random) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Example 3 with TestProject

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

the class GitBlobStorageTest method testGitFileHistorySingleProjectOk.

@Test
public void testGitFileHistorySingleProjectOk() throws Exception {
    IProgressMonitor progress = new NullProgressMonitor();
    TestProject singleRepoProject = new TestProject(true, "Project-2");
    IProject proj = singleRepoProject.getProject();
    File singleProjectGitDir = new File(proj.getLocation().toFile(), Constants.DOT_GIT);
    if (singleProjectGitDir.exists())
        FileUtils.delete(singleProjectGitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
    Repository singleProjectRepo = FileRepositoryBuilder.create(singleProjectGitDir);
    singleProjectRepo.create();
    // Repository must be mapped in order to test the GitFileHistory
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(singleProjectGitDir);
    ConnectProviderOperation connectOp = new ConnectProviderOperation(proj, singleProjectGitDir);
    connectOp.execute(progress);
    try (Git git = new Git(singleProjectRepo)) {
        IFile file = proj.getFile("file");
        file.create(new ByteArrayInputStream("data".getBytes("UTF-8")), 0, progress);
        git.add().addFilepattern(".").call();
        RevCommit commit = git.commit().setAuthor("JUnit", "junit@jgit.org").setAll(true).setMessage("First commit").call();
        GitFileHistoryProvider fhProvider = new GitFileHistoryProvider();
        IFileHistory fh = fhProvider.getFileHistoryFor(singleRepoProject.getProject(), 0, null);
        assertNotNull(fh);
        assertEquals(fh.getFileRevisions().length, 1);
        assertNotNull(fh.getFileRevision(commit.getId().getName()));
    } finally {
        DisconnectProviderOperation disconnectOp = new DisconnectProviderOperation(Collections.singletonList(proj));
        disconnectOp.execute(progress);
        Activator.getDefault().getRepositoryUtil().removeDir(singleProjectGitDir);
        singleProjectRepo.close();
        singleRepoProject.dispose();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) IFileHistory(org.eclipse.team.core.history.IFileHistory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) TestProject(org.eclipse.egit.core.test.TestProject) ByteArrayInputStream(java.io.ByteArrayInputStream) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) DisconnectProviderOperation(org.eclipse.egit.core.op.DisconnectProviderOperation) RevCommit(org.eclipse.jgit.revwalk.RevCommit) GitFileHistoryProvider(org.eclipse.egit.core.internal.storage.GitFileHistoryProvider) Test(org.junit.Test)

Example 4 with TestProject

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

the class GitResourceVariantTreeTest method shouldReturnTwoRoots.

/**
 * When we have two or more project associated with repository, roots()
 * method should return list of project. In this case we have two project
 * associated with particular repository, therefore '2' value is expected.
 *
 * @throws Exception
 */
@Test
public void shouldReturnTwoRoots() throws Exception {
    // when
    // create second project
    TestProject secondProject = new TestProject(true, "Project-2");
    try {
        IProject secondIProject = secondProject.project;
        // add connect project with repository
        new ConnectProviderOperation(secondIProject, gitDir).execute(null);
        try (Git git = new Git(repo)) {
            git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
        }
        GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
        GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
        // given
        GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null, null);
        // then
        IResource[] roots = grvt.roots();
        // sort in order to be able to assert the project instances
        Arrays.sort(roots, new Comparator<IResource>() {

            @Override
            public int compare(IResource r1, IResource r2) {
                String path1 = r1.getFullPath().toString();
                String path2 = r2.getFullPath().toString();
                return path1.compareTo(path2);
            }
        });
        assertEquals(2, roots.length);
        IResource actualProject = roots[0];
        assertEquals(this.project.project, actualProject);
        IResource actualProject1 = roots[1];
        assertEquals(secondIProject, actualProject1);
    } finally {
        secondProject.dispose();
    }
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProject(org.eclipse.core.resources.IProject) Git(org.eclipse.jgit.api.Git) TestProject(org.eclipse.egit.core.test.TestProject) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Example 5 with TestProject

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

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