Search in sources :

Example 1 with GitProjectData

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

the class ConnectProviderOperation method connectProject.

private void connectProject(Entry<IProject, File> entry, MultiStatus ms, IProgressMonitor monitor) throws CoreException {
    IProject project = entry.getKey();
    String taskName = NLS.bind(CoreText.ConnectProviderOperation_ConnectingProject, project.getName());
    SubMonitor subMon = SubMonitor.convert(monitor, taskName, 100);
    if (GitTraceLocation.CORE.isActive()) {
        GitTraceLocation.getTrace().trace(GitTraceLocation.CORE.getLocation(), taskName);
    }
    RepositoryFinder finder = new RepositoryFinder(project);
    finder.setFindInChildren(false);
    Collection<RepositoryMapping> repos = finder.find(subMon.newChild(50));
    if (repos.isEmpty()) {
        ms.add(Activator.error(NLS.bind(CoreText.ConnectProviderOperation_NoRepositoriesError, project.getName()), null));
        return;
    }
    RepositoryMapping actualMapping = findActualRepository(repos, entry.getValue());
    if (actualMapping == null) {
        ms.add(Activator.error(NLS.bind(CoreText.ConnectProviderOperation_UnexpectedRepositoryError, new Object[] { project.getName(), entry.getValue().toString(), repos.toString() }), null));
        return;
    }
    GitProjectData projectData = new GitProjectData(project);
    try {
        projectData.setRepositoryMappings(Arrays.asList(actualMapping));
        projectData.store();
        GitProjectData.add(project, projectData);
    } catch (CoreException ce) {
        ms.add(ce.getStatus());
        deleteGitProvider(ms, project);
        return;
    } catch (RuntimeException ce) {
        ms.add(Activator.error(ce.getMessage(), ce));
        deleteGitProvider(ms, project);
        return;
    }
    RepositoryProvider.map(project, GitProvider.ID);
    IPath gitPath = actualMapping.getGitDirAbsolutePath();
    if (refreshResources) {
        touchGitResources(project, subMon.newChild(10));
        project.refreshLocal(IResource.DEPTH_INFINITE, subMon.newChild(30));
        if (gitPath != null) {
            try {
                Repository repository = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().lookupRepository(gitPath.toFile());
                IndexDiffCacheEntry cacheEntry = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
                if (cacheEntry != null) {
                    cacheEntry.refresh();
                }
            } catch (IOException e) {
                Activator.logError(e.getMessage(), e);
            }
        }
    } else {
        subMon.worked(40);
    }
    autoIgnoreDerivedResources(project, subMon.newChild(10));
    if (gitPath != null) {
        autoIgnoreWorkspaceMetaData(gitPath.toFile());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) RepositoryFinder(org.eclipse.egit.core.project.RepositoryFinder) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) GitProjectData(org.eclipse.egit.core.project.GitProjectData) IProject(org.eclipse.core.resources.IProject) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping)

Example 2 with GitProjectData

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

the class UntrackOperation method remove.

private void remove(final IResource resource) throws CoreException {
    final IProject proj = resource.getProject();
    if (proj == null) {
        return;
    }
    final GitProjectData pd = GitProjectData.get(proj);
    if (pd == null) {
        return;
    }
    final RepositoryMapping rm = pd.getRepositoryMapping(resource);
    if (rm == null) {
        return;
    }
    db = rm.getRepository();
    remove(resource.getLocation());
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) GitProjectData(org.eclipse.egit.core.project.GitProjectData) IProject(org.eclipse.core.resources.IProject)

Example 3 with GitProjectData

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

the class GitModelSynchronizeParticipant method getRepositoryForPath.

private Repository getRepositoryForPath(String containerPath) {
    IPath path = Path.fromPortableString(containerPath);
    IContainer mappedContainer = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path);
    if (mappedContainer == null) {
        return null;
    }
    GitProjectData projectData = GitProjectData.get(mappedContainer.getProject());
    if (projectData == null) {
        return null;
    }
    RepositoryMapping mapping = projectData.getRepositoryMapping(mappedContainer);
    if (mapping != null)
        return mapping.getRepository();
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IContainer(org.eclipse.core.resources.IContainer) GitProjectData(org.eclipse.egit.core.project.GitProjectData)

Example 4 with GitProjectData

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

the class GitResourceDeltaVisitor method visit.

@Override
public boolean visit(IResourceDelta delta) throws CoreException {
    final IResource resource = delta.getResource();
    if (resource.getType() == IResource.ROOT) {
        return true;
    }
    if (resource.getType() == IResource.PROJECT) {
        if (delta.getKind() == IResourceDelta.REMOVED) {
            IPath loc = deletedProjects.remove(resource);
            if (loc != null) {
                projectDeleted |= !loc.toFile().isDirectory();
            }
            return false;
        }
        // Git revision control or from a different repository
        if (!ResourceUtil.isSharedWithGit(resource)) {
            // Ignore the change for project and its children
            return false;
        }
        GitProjectData gitData = GitProjectData.get((IProject) resource);
        if (gitData == null) {
            return false;
        }
        RepositoryMapping mapping = gitData.getRepositoryMapping(resource);
        if (mapping == null || !gitData.hasInnerRepositories() && mapping.getRepository() != repository) {
            return false;
        }
        // continue with children
        return true;
    }
    Repository repositoryOfResource = null;
    if (resource.isLinked()) {
        IPath location = resource.getLocation();
        if (location == null) {
            return false;
        }
        repositoryOfResource = ResourceUtil.getRepository(location);
        // in the same repository
        if (repository != repositoryOfResource) {
            return false;
        }
    } else {
        repositoryOfResource = ResourceUtil.getRepository(resource);
    }
    if (resource.getType() == IResource.FOLDER) {
        GitProjectData gitData = GitProjectData.get(resource.getProject());
        if (gitData == null) {
            return false;
        }
        if (repositoryOfResource == null || !gitData.isProtected(resource) && repositoryOfResource != repository) {
            return false;
        }
        if (delta.getKind() == IResourceDelta.ADDED) {
            IPath repoRelativePath = ResourceUtil.getRepositoryRelativePath(resource.getLocation(), repository);
            if (repoRelativePath == null) {
                return false;
            }
            if (!repoRelativePath.isEmpty()) {
                // $NON-NLS-1$
                String path = repoRelativePath.toPortableString() + "/";
                if (isIgnoredInOldIndex(path)) {
                    // keep going to catch .gitignore files.
                    return true;
                }
                filesToUpdate.add(path);
                resourcesToUpdate.add(resource);
            }
        }
        // continue with children
        return true;
    }
    if (repositoryOfResource != repository) {
        return false;
    }
    if (!isInteresting(delta)) {
        return false;
    }
    if (resource.getName().equals(Constants.DOT_GIT_IGNORE)) {
        gitIgnoreChanged = true;
        return false;
    }
    IPath repoRelativePath = ResourceUtil.getRepositoryRelativePath(resource.getLocation(), repository);
    if (repoRelativePath == null) {
        resourcesToUpdate.add(resource);
        return true;
    }
    String path = repoRelativePath.toPortableString();
    if (isIgnoredInOldIndex(path)) {
        // change: ignore the delta to avoid unnecessary index updates
        return false;
    }
    filesToUpdate.add(path);
    resourcesToUpdate.add(resource);
    return true;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) GitProjectData(org.eclipse.egit.core.project.GitProjectData) IResource(org.eclipse.core.resources.IResource)

Example 5 with GitProjectData

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

the class ResourceMocks method createGitSharedProject.

public static org.eclipse.core.resources.IProject createGitSharedProject(String name, String gitRemoteUri) throws CoreException {
    org.eclipse.core.resources.IProject project = createEclipseProject(name);
    when(project.getPersistentProperty(TeamPlugin.PROVIDER_PROP_KEY)).thenReturn(GitProvider.ID);
    when(project.getWorkingLocation(any())).thenReturn(new Path(ResourcesPlugin.getWorkspace().getRoot().getFullPath().toString()));
    StoredConfig config = mock(StoredConfig.class);
    when(config.getSubsections("remote")).thenReturn(new HashSet<String>(Arrays.asList("origin")));
    when(config.getStringList(any(), any(), any())).thenReturn(new String[] { gitRemoteUri });
    when(config.getStringList("remote", "origin", "url")).thenReturn(new String[] { gitRemoteUri });
    Repository repository = mock(Repository.class);
    when(repository.getConfig()).thenReturn(config);
    RepositoryMapping mapping = mock(RepositoryMapping.class);
    when(mapping.getRepository()).thenReturn(repository);
    GitProjectData data = mock(GitProjectData.class);
    when(data.getRepositoryMapping(project)).thenReturn(mapping);
    GitProvider repositoryProvider = mock(GitProvider.class);
    when(repositoryProvider.getID()).thenReturn(GitProvider.ID);
    when(repositoryProvider.getData()).thenReturn(data);
    when(project.getSessionProperty(TeamPlugin.PROVIDER_PROP_KEY)).thenReturn(repositoryProvider);
    return project;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) Matchers.anyString(org.mockito.Matchers.anyString) GitProjectData(org.eclipse.egit.core.project.GitProjectData) GitProvider(org.eclipse.egit.core.GitProvider)

Aggregations

GitProjectData (org.eclipse.egit.core.project.GitProjectData)9 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)9 IProject (org.eclipse.core.resources.IProject)4 IPath (org.eclipse.core.runtime.IPath)4 GitProvider (org.eclipse.egit.core.GitProvider)3 Repository (org.eclipse.jgit.lib.Repository)3 File (java.io.File)1 IOException (java.io.IOException)1 IContainer (org.eclipse.core.resources.IContainer)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 Path (org.eclipse.core.runtime.Path)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IndexDiffCacheEntry (org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)1 RepositoryFinder (org.eclipse.egit.core.project.RepositoryFinder)1 Git (org.eclipse.jgit.api.Git)1 StoredConfig (org.eclipse.jgit.lib.StoredConfig)1 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)1