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