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