Search in sources :

Example 11 with GitProvider

use of org.eclipse.egit.core.GitProvider in project egit by eclipse.

the class HistoryTest method testDeepHistory_B.

@Test
public void testDeepHistory_B() {
    GitProvider provider = (GitProvider) RepositoryProvider.getProvider(project.project);
    assertNotNull(provider);
    IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
    IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(project.getProject().getWorkspace().getRoot().findMember("Project-1/B.txt"), IFileHistoryProvider.NONE, new NullProgressMonitor());
    IFileRevision[] fileRevisions = fileHistory.getFileRevisions();
    assertEquals(2, fileRevisions.length);
    assertEquals("fd5a571c8a3a4a152e4c413d09d3ecb7d41e1e5f", fileRevisions[0].getContentIdentifier());
    assertEquals("J. Author", fileRevisions[0].getAuthor());
    assertEquals("60f0d7917fe2aed5c92b5bc35dfb55b9b8ada359", fileRevisions[1].getContentIdentifier());
    assertEquals("J. Author", fileRevisions[0].getAuthor());
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileHistoryProvider(org.eclipse.team.core.history.IFileHistoryProvider) IFileRevision(org.eclipse.team.core.history.IFileRevision) GitProvider(org.eclipse.egit.core.GitProvider) Test(org.junit.Test)

Example 12 with GitProvider

use of org.eclipse.egit.core.GitProvider in project egit by eclipse.

the class HistoryTest method testSingleRevision_3.

@Test
public void testSingleRevision_3() {
    GitProvider provider = (GitProvider) RepositoryProvider.getProvider(project.project);
    assertNotNull(provider);
    IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
    IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(project.getProject().getWorkspace().getRoot().findMember("Project-1/B.txt"), IFileHistoryProvider.SINGLE_LINE_OF_DESCENT, new NullProgressMonitor());
    IFileRevision fileRevision = fileHistory.getFileRevision("fd5a571c8a3a4a152e4c413d09d3ecb7d41e1e5f");
    assertEquals("fd5a571c8a3a4a152e4c413d09d3ecb7d41e1e5f", fileRevision.getContentIdentifier());
    assertEquals("J. Author", fileRevision.getAuthor());
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileHistoryProvider(org.eclipse.team.core.history.IFileHistoryProvider) IFileRevision(org.eclipse.team.core.history.IFileRevision) GitProvider(org.eclipse.egit.core.GitProvider) Test(org.junit.Test)

Example 13 with GitProvider

use of org.eclipse.egit.core.GitProvider in project egit by eclipse.

the class HistoryTest method testDeepHistory_A.

@Test
public void testDeepHistory_A() {
    GitProvider provider = (GitProvider) RepositoryProvider.getProvider(project.project);
    assertNotNull(provider);
    IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
    IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(project.getProject().getWorkspace().getRoot().findMember("Project-1/A.txt"), IFileHistoryProvider.NONE, new NullProgressMonitor());
    IFileRevision[] fileRevisions = fileHistory.getFileRevisions();
    assertEquals(1, fileRevisions.length);
    assertEquals("60f0d7917fe2aed5c92b5bc35dfb55b9b8ada359", fileRevisions[0].getContentIdentifier());
    assertEquals("J. Author", fileRevisions[0].getAuthor());
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileHistoryProvider(org.eclipse.team.core.history.IFileHistoryProvider) IFileRevision(org.eclipse.team.core.history.IFileRevision) GitProvider(org.eclipse.egit.core.GitProvider) Test(org.junit.Test)

Example 14 with GitProvider

use of org.eclipse.egit.core.GitProvider in project egit by eclipse.

the class ResourceUtil method getGitProvider.

/**
 * Returns git provider if associated with the given project or
 * <code>null</code> if the project is not associated with a provider or the
 * provider is not fully loaded yet. To check if the git provider is
 * associated with the project, use {@link #isSharedWithGit(IResource)}.
 *
 * @param project
 *            the project to query for a provider
 * @return the repository provider or null
 */
@Nullable
public static final GitProvider getGitProvider(@NonNull IProject project) {
    if (!project.isAccessible()) {
        return null;
    }
    try {
        // Look for an existing provider
        GitProvider provider = lookupProviderProp(project);
        if (provider != null) {
            return provider;
        }
        if (MappingJob.isKnownGitProject(project) || isMarkedAsNotSharedWithGit(project)) {
            // isn't shared with us at all.
            return null;
        }
        String existingID = project.getPersistentProperty(PROVIDER_PROP_KEY);
        if (existingID == null) {
            markAsUnshared(project);
        } else {
            markAsShared(project, existingID);
            boolean isGitProvider = GitProvider.ID.equals(existingID);
            if (isGitProvider) {
                MappingJob.initProviderAsynchronously(project);
            }
        }
        // or not a GitProvider
        return null;
    } catch (CoreException e) {
        Activator.getDefault().getLog().log(e.getStatus());
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) GitProvider(org.eclipse.egit.core.GitProvider) Nullable(org.eclipse.jgit.annotations.Nullable)

Aggregations

GitProvider (org.eclipse.egit.core.GitProvider)14 Test (org.junit.Test)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IFileHistory (org.eclipse.team.core.history.IFileHistory)8 IFileHistoryProvider (org.eclipse.team.core.history.IFileHistoryProvider)8 IFileRevision (org.eclipse.team.core.history.IFileRevision)8 IStorage (org.eclipse.core.resources.IStorage)2 CoreException (org.eclipse.core.runtime.CoreException)2 GitProjectData (org.eclipse.egit.core.project.GitProjectData)2 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)2 Nullable (org.eclipse.jgit.annotations.Nullable)2 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 Repository (org.eclipse.jgit.lib.Repository)1 StoredConfig (org.eclipse.jgit.lib.StoredConfig)1 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)1 Matchers.anyString (org.mockito.Matchers.anyString)1