Search in sources :

Example 51 with RepositoryMapping

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

the class GitResourceDeltaTestHelper method setUp.

public void setUp() {
    resourceChangeListener = new IResourceChangeListener() {

        @Override
        public void resourceChanged(final IResourceChangeEvent event) {
            try {
                event.getDelta().accept(new IResourceDeltaVisitor() {

                    @Override
                    public boolean visit(IResourceDelta delta) throws CoreException {
                        final IResource resource = delta.getResource();
                        IProject project = resource.getProject();
                        if (project == null)
                            return true;
                        RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
                        if (mapping == null)
                            return true;
                        if (mapping.getRepository() != repository)
                            return false;
                        GitResourceDeltaVisitor visitor = new GitResourceDeltaVisitor(repository);
                        try {
                            event.getDelta().accept(visitor);
                        } catch (CoreException e) {
                            String msg = "Exception during accept of GitResourceDeltaVisitor for resource delta";
                            throw new RuntimeException(msg, e);
                        }
                        IPath gitDirAbsolutePath = mapping.getGitDirAbsolutePath();
                        for (IResource res : visitor.getResourcesToUpdate()) {
                            if (ignoreTeamPrivateMember && (res.isTeamPrivateMember() || gitDirAbsolutePath.isPrefixOf(res.getRawLocation().makeAbsolute())))
                                continue;
                            changedResources.add(res);
                        }
                        return false;
                    }
                });
            } catch (CoreException e) {
                throw new RuntimeException("Exception during accept of test visitor for resource delta", e);
            }
        }
    };
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IProject(org.eclipse.core.resources.IProject) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) GitResourceDeltaVisitor(org.eclipse.egit.core.internal.indexdiff.GitResourceDeltaVisitor) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 52 with RepositoryMapping

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

the class LocalRepositoryTestCase method assertConnected.

protected RepositoryMapping assertConnected(IProject project) {
    RepositoryProvider provider = RepositoryProvider.getProvider(project, GitProvider.ID);
    if (provider == null) {
        TestUtil.waitForJobs(5000, 10000);
        assertTrue("Project not shared with git: " + project, ResourceUtil.isSharedWithGit(project));
        TestUtil.waitForJobs(1000, 10000);
        provider = RepositoryProvider.getProvider(project);
    }
    assertTrue("Project is not accessible: " + project, project.isAccessible());
    assertNotNull("GitProvider not mapped to: " + project, provider);
    GitProjectData data = ((GitProvider) provider).getData();
    if (data == null) {
        TestUtil.waitForJobs(100, 5000);
        data = ((GitProvider) provider).getData();
    }
    assertNotNull("GitProjectData is null for: " + project, data);
    RepositoryMapping mapping = data.getRepositoryMapping(project);
    if (mapping == null) {
        TestUtil.waitForJobs(100, 5000);
        mapping = data.getRepositoryMapping(project);
    }
    assertNotNull("RepositoryMapping is null for: " + project, mapping);
    return mapping;
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) GitProjectData(org.eclipse.egit.core.project.GitProjectData) GitProvider(org.eclipse.egit.core.GitProvider)

Example 53 with RepositoryMapping

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

the class SubmoduleFolderTest method testChildFolderMapsToSubRepo.

@Test
public void testChildFolderMapsToSubRepo() {
    RepositoryMapping mapping = RepositoryMapping.getMapping(childFolder);
    assertNotNull("Child folder should have a mapping", mapping);
    assertEquals(subRepository, mapping.getRepository());
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) Test(org.junit.Test)

Example 54 with RepositoryMapping

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

the class AbstractSynchronizeViewTest method launchSynchronization.

protected void launchSynchronization(String projectName, String srcRef, String dstRef, boolean includeLocal) throws IOException {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    RepositoryMapping mapping = assertConnected(project);
    Repository repo = mapping.getRepository();
    GitSynchronizeData data = new GitSynchronizeData(repo, srcRef, dstRef, includeLocal);
    JobJoiner jobJoiner = JobJoiner.startListening(ISynchronizeManager.FAMILY_SYNCHRONIZE_OPERATION, 60, TimeUnit.SECONDS);
    GitModelSynchronize.launch(data, new IResource[] { project });
    jobJoiner.join();
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) JobJoiner(org.eclipse.egit.ui.test.JobJoiner) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IProject(org.eclipse.core.resources.IProject)

Example 55 with RepositoryMapping

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

the class CompareUtils method compareWorkspaceWithRef.

/**
 * Opens a compare editor comparing the working directory version of the
 * given file or link with the version of that file corresponding to
 * {@code refName}.
 *
 * @param repository
 *            The repository to load file revisions from.
 * @param file
 *            Resource to compare revisions for. Must be either
 *            {@link IFile} or a symbolic link to directory ({@link IFolder}).
 * @param refName
 *            Reference to compare with the workspace version of
 *            {@code file}. Can be either a commit ID, a reference or a
 *            branch name.
 * @param page
 *            If not {@null} try to re-use a compare editor on this page if
 *            any is available. Otherwise open a new one.
 */
public static void compareWorkspaceWithRef(@NonNull final Repository repository, final IResource file, final String refName, final IWorkbenchPage page) {
    if (file == null) {
        return;
    }
    final IPath location = file.getLocation();
    if (location == null) {
        return;
    }
    Job job = new Job(UIText.CompareUtils_jobName) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final RepositoryMapping mapping = RepositoryMapping.getMapping(file);
            if (mapping == null) {
                return Activator.createErrorStatus(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, location, repository));
            }
            final ITypedElement base;
            if (Files.isSymbolicLink(location.toFile().toPath())) {
                base = new LocalNonWorkspaceTypedElement(repository, location);
            } else if (file instanceof IFile) {
                base = SaveableCompareEditorInput.createFileElement((IFile) file);
            } else {
                return Activator.createErrorStatus(NLS.bind(UIText.CompareUtils_wrongResourceArgument, location, file));
            }
            final String gitPath = mapping.getRepoRelativePath(file);
            CompareEditorInput in;
            try {
                in = prepareCompareInput(repository, gitPath, base, refName);
            } catch (IOException e) {
                return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
            }
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            openCompareEditorRunnable(page, in);
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareEditorInput(org.eclipse.compare.CompareEditorInput) GitCompareEditorInput(org.eclipse.egit.ui.internal.merge.GitCompareEditorInput) SaveableCompareEditorInput(org.eclipse.team.ui.synchronize.SaveableCompareEditorInput) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) ITypedElement(org.eclipse.compare.ITypedElement) LocalNonWorkspaceTypedElement(org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)87 Repository (org.eclipse.jgit.lib.Repository)40 IResource (org.eclipse.core.resources.IResource)31 IProject (org.eclipse.core.resources.IProject)23 IPath (org.eclipse.core.runtime.IPath)20 IOException (java.io.IOException)18 File (java.io.File)17 CoreException (org.eclipse.core.runtime.CoreException)15 IFile (org.eclipse.core.resources.IFile)12 Path (org.eclipse.core.runtime.Path)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 GitProjectData (org.eclipse.egit.core.project.GitProjectData)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 HashMap (java.util.HashMap)5