Search in sources :

Example 1 with RepositoryMapping

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

the class ResourceUtil method splitResourcesByRepository.

/**
 * The method splits the given resources by their repository. For each
 * occurring repository a list is built containing the repository relative
 * paths of the related resources.
 * <p>
 * When one of the passed resources corresponds to the working directory,
 * <code>""</code> will be returned as part of the collection.
 *
 * @param resources
 * @return a map containing a list of repository relative paths for each
 *         occurring repository
 */
public static Map<Repository, Collection<String>> splitResourcesByRepository(Collection<IResource> resources) {
    Map<Repository, Collection<String>> result = new HashMap<Repository, Collection<String>>();
    for (IResource resource : resources) {
        RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(resource);
        if (repositoryMapping == null)
            continue;
        String path = repositoryMapping.getRepoRelativePath(resource);
        addPathToMap(repositoryMapping.getRepository(), path, result);
    }
    return result;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) HashMap(java.util.HashMap) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) Collection(java.util.Collection) IResource(org.eclipse.core.resources.IResource)

Example 2 with RepositoryMapping

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

the class AddToIndexOperation method execute.

/* (non-Javadoc)
	 * @see org.eclipse.egit.core.op.IEGitOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, rsrcList.size() * 2);
    Map<RepositoryMapping, AddCommand> addCommands = new HashMap<RepositoryMapping, AddCommand>();
    try {
        for (IResource obj : rsrcList) {
            addToCommand(obj, addCommands);
            progress.worked(1);
        }
        progress.setWorkRemaining(addCommands.size());
        for (AddCommand command : addCommands.values()) {
            command.call();
            progress.worked(1);
        }
    } catch (RuntimeException e) {
        throw new CoreException(Activator.error(CoreText.AddToIndexOperation_failed, e));
    } catch (GitAPIException e) {
        throw new CoreException(Activator.error(CoreText.AddToIndexOperation_failed, e));
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) SubMonitor(org.eclipse.core.runtime.SubMonitor) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IResource(org.eclipse.core.resources.IResource) AddCommand(org.eclipse.jgit.api.AddCommand)

Example 3 with RepositoryMapping

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

the class CommitOperation method setRepository.

private void setRepository(IFile file) throws CoreException {
    RepositoryMapping mapping = RepositoryMapping.getMapping(file);
    if (mapping == null)
        throw new CoreException(Activator.error(NLS.bind(CoreText.CommitOperation_couldNotFindRepositoryMapping, file), null));
    repo = mapping.getRepository();
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping)

Example 4 with RepositoryMapping

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

the class CommitOperation method buildFileList.

private Collection<String> buildFileList(Collection<IFile> files) throws CoreException {
    Collection<String> result = new HashSet<String>();
    for (IFile file : files) {
        RepositoryMapping mapping = RepositoryMapping.getMapping(file);
        if (mapping == null)
            throw new CoreException(Activator.error(NLS.bind(CoreText.CommitOperation_couldNotFindRepositoryMapping, file), null));
        String repoRelativePath = mapping.getRepoRelativePath(file);
        result.add(repoRelativePath);
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) HashSet(java.util.HashSet)

Example 5 with RepositoryMapping

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

Aggregations

RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)89 Repository (org.eclipse.jgit.lib.Repository)41 IResource (org.eclipse.core.resources.IResource)32 IProject (org.eclipse.core.resources.IProject)25 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