Search in sources :

Example 81 with RepositoryMapping

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

the class AddToIndexOperation method addToCommand.

private void addToCommand(IResource resource, Map<RepositoryMapping, AddCommand> addCommands) {
    RepositoryMapping map = RepositoryMapping.getMapping(resource);
    if (map == null) {
        return;
    }
    AddCommand command = addCommands.get(map);
    if (command == null) {
        Repository repo = map.getRepository();
        try (Git git = new Git(repo)) {
            command = git.add();
        }
        addCommands.put(map, command);
    }
    String filepattern = map.getRepoRelativePath(resource);
    if (// $NON-NLS-1$
    "".equals(filepattern))
        // $NON-NLS-1$
        filepattern = ".";
    command.addFilepattern(filepattern);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) AddCommand(org.eclipse.jgit.api.AddCommand)

Example 82 with RepositoryMapping

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

the class AssumeUnchangedOperation method assumeValid.

private void assumeValid(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;
    }
    this.db = rm.getRepository();
    assumeValid(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 83 with RepositoryMapping

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

the class ReflogView method reactOnSelection.

private void reactOnSelection(ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    IStructuredSelection ssel = (IStructuredSelection) selection;
    if (ssel.size() != 1) {
        return;
    }
    Repository selectedRepo = null;
    Object first = ssel.getFirstElement();
    IResource adapted = AdapterUtils.adaptToAnyResource(first);
    if (adapted != null) {
        RepositoryMapping mapping = RepositoryMapping.getMapping(adapted);
        if (mapping != null) {
            selectedRepo = mapping.getRepository();
        }
    }
    if (selectedRepo == null) {
        selectedRepo = AdapterUtils.adapt(first, Repository.class);
    }
    if (selectedRepo == null) {
        return;
    }
    // Only update when different repository is selected
    Repository currentRepo = getRepository();
    if (currentRepo == null || !selectedRepo.getDirectory().equals(currentRepo.getDirectory())) {
        showReflogFor(selectedRepo);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Example 84 with RepositoryMapping

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

the class RepositoryActionHandler method getProjectsForSelectedResources.

/**
 * Retrieve the list of projects that contains the given resources. All
 * resources must actually map to a project shared with egit, otherwise an
 * empty array is returned. In case of a linked resource, the project
 * returned is the one that contains the link target and is shared with
 * egit, if any, otherwise an empty array is also returned.
 *
 * @param selection
 * @return the projects hosting the selected resources
 */
private IProject[] getProjectsForSelectedResources(IStructuredSelection selection) {
    Set<IProject> ret = new LinkedHashSet<>();
    for (IResource resource : getSelectedAdaptables(selection, IResource.class)) {
        RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
        if (mapping != null && (mapping.getContainer() instanceof IProject))
            ret.add((IProject) mapping.getContainer());
        else
            return new IProject[0];
    }
    ret.addAll(extractProjectsFromMappings(selection));
    return ret.toArray(new IProject[ret.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 85 with RepositoryMapping

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

the class RepositoryActionHandler method getRepositoriesFor.

/**
 * @param projects
 *            a list of projects
 * @return the repositories that projects map to if all projects are mapped
 */
protected Repository[] getRepositoriesFor(final IProject[] projects) {
    Set<Repository> ret = new LinkedHashSet<>();
    for (IProject project : projects) {
        RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
        if (repositoryMapping == null)
            return new Repository[0];
        ret.add(repositoryMapping.getRepository());
    }
    return ret.toArray(new Repository[ret.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Repository(org.eclipse.jgit.lib.Repository) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IProject(org.eclipse.core.resources.IProject)

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