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);
}
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());
}
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);
}
}
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()]);
}
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()]);
}
Aggregations