Search in sources :

Example 1 with GitProvider

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

the class ResourceUtil method isSharedWithGit.

/**
 * @param resource
 *            non null
 * @return true if the project is configured with git provider
 */
public static boolean isSharedWithGit(@NonNull IResource resource) {
    IProject project = resource.getProject();
    if (project == null || !project.isAccessible()) {
        return false;
    }
    try {
        // Look for an existing provider
        GitProvider provider = lookupProviderProp(project);
        if (provider != null || MappingJob.isKnownGitProject(project)) {
            // Is mapped or in the process of being mapped.
            return true;
        } else if (isMarkedAsNotSharedWithGit(project)) {
            return false;
        }
        // There isn't one so check the persistent property
        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);
        }
        return isGitProvider;
    } catch (CoreException e) {
        Activator.getDefault().getLog().log(e.getStatus());
        return false;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) GitProvider(org.eclipse.egit.core.GitProvider)

Example 2 with GitProvider

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

the class RepositoryMapping method getProjectData.

/**
 * Get the git project data for a project.
 *
 * @param project
 *            to find the data for
 * @return the git project data for this project, or null for non
 *         GitProvider.
 */
@Nullable
private static GitProjectData getProjectData(@Nullable final IProject project) {
    if (project == null || isNonWorkspace(project)) {
        return null;
    }
    final GitProvider rp = ResourceUtil.getGitProvider(project);
    GitProjectData data;
    // The provider could not yet be mapped
    if (rp == null) {
        // Load the data directly
        data = GitProjectData.get(project);
        if (data == null) {
            return null;
        }
    } else {
        data = rp.getData();
    }
    return data;
}
Also used : GitProvider(org.eclipse.egit.core.GitProvider) Nullable(org.eclipse.jgit.annotations.Nullable)

Example 3 with GitProvider

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

the class HistoryTest method testSingleRevision_1.

@Test
public void testSingleRevision_1() {
    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.SINGLE_LINE_OF_DESCENT, new NullProgressMonitor());
    IFileRevision fileRevision = fileHistory.getFileRevision("60f0d7917fe2aed5c92b5bc35dfb55b9b8ada359");
    assertEquals("60f0d7917fe2aed5c92b5bc35dfb55b9b8ada359", 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 4 with GitProvider

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

the class HistoryTest method testIndexRevisionSecondCommit.

@Test
public void testIndexRevisionSecondCommit() throws Exception {
    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(GitFileRevision.INDEX);
    assertEquals(GitFileRevision.INDEX, fileRevision.getContentIdentifier());
    IStorage storage = fileRevision.getStorage(null);
    String content = testUtils.slurpAndClose(storage.getContents());
    assertEquals("B.txt - second version\n", content);
}
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) IStorage(org.eclipse.core.resources.IStorage) GitProvider(org.eclipse.egit.core.GitProvider) Test(org.junit.Test)

Example 5 with GitProvider

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

the class HistoryTest method testShallowHistory.

@Test
public void testShallowHistory() {
    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.SINGLE_LINE_OF_DESCENT, 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)

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