use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitResourceDeltaTestHelper method setUp.
public void setUp() {
resourceChangeListener = new IResourceChangeListener() {
@Override
public void resourceChanged(final IResourceChangeEvent event) {
try {
event.getDelta().accept(new IResourceDeltaVisitor() {
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
final IResource resource = delta.getResource();
IProject project = resource.getProject();
if (project == null)
return true;
RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
if (mapping == null)
return true;
if (mapping.getRepository() != repository)
return false;
GitResourceDeltaVisitor visitor = new GitResourceDeltaVisitor(repository);
try {
event.getDelta().accept(visitor);
} catch (CoreException e) {
String msg = "Exception during accept of GitResourceDeltaVisitor for resource delta";
throw new RuntimeException(msg, e);
}
IPath gitDirAbsolutePath = mapping.getGitDirAbsolutePath();
for (IResource res : visitor.getResourcesToUpdate()) {
if (ignoreTeamPrivateMember && (res.isTeamPrivateMember() || gitDirAbsolutePath.isPrefixOf(res.getRawLocation().makeAbsolute())))
continue;
changedResources.add(res);
}
return false;
}
});
} catch (CoreException e) {
throw new RuntimeException("Exception during accept of test visitor for resource delta", e);
}
}
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class LocalRepositoryTestCase method assertConnected.
protected RepositoryMapping assertConnected(IProject project) {
RepositoryProvider provider = RepositoryProvider.getProvider(project, GitProvider.ID);
if (provider == null) {
TestUtil.waitForJobs(5000, 10000);
assertTrue("Project not shared with git: " + project, ResourceUtil.isSharedWithGit(project));
TestUtil.waitForJobs(1000, 10000);
provider = RepositoryProvider.getProvider(project);
}
assertTrue("Project is not accessible: " + project, project.isAccessible());
assertNotNull("GitProvider not mapped to: " + project, provider);
GitProjectData data = ((GitProvider) provider).getData();
if (data == null) {
TestUtil.waitForJobs(100, 5000);
data = ((GitProvider) provider).getData();
}
assertNotNull("GitProjectData is null for: " + project, data);
RepositoryMapping mapping = data.getRepositoryMapping(project);
if (mapping == null) {
TestUtil.waitForJobs(100, 5000);
mapping = data.getRepositoryMapping(project);
}
assertNotNull("RepositoryMapping is null for: " + project, mapping);
return mapping;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class SubmoduleFolderTest method testChildFolderMapsToSubRepo.
@Test
public void testChildFolderMapsToSubRepo() {
RepositoryMapping mapping = RepositoryMapping.getMapping(childFolder);
assertNotNull("Child folder should have a mapping", mapping);
assertEquals(subRepository, mapping.getRepository());
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class AbstractSynchronizeViewTest method launchSynchronization.
protected void launchSynchronization(String projectName, String srcRef, String dstRef, boolean includeLocal) throws IOException {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
RepositoryMapping mapping = assertConnected(project);
Repository repo = mapping.getRepository();
GitSynchronizeData data = new GitSynchronizeData(repo, srcRef, dstRef, includeLocal);
JobJoiner jobJoiner = JobJoiner.startListening(ISynchronizeManager.FAMILY_SYNCHRONIZE_OPERATION, 60, TimeUnit.SECONDS);
GitModelSynchronize.launch(data, new IResource[] { project });
jobJoiner.join();
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class CompareUtils method compareWorkspaceWithRef.
/**
* Opens a compare editor comparing the working directory version of the
* given file or link with the version of that file corresponding to
* {@code refName}.
*
* @param repository
* The repository to load file revisions from.
* @param file
* Resource to compare revisions for. Must be either
* {@link IFile} or a symbolic link to directory ({@link IFolder}).
* @param refName
* Reference to compare with the workspace version of
* {@code file}. Can be either a commit ID, a reference or a
* branch name.
* @param page
* If not {@null} try to re-use a compare editor on this page if
* any is available. Otherwise open a new one.
*/
public static void compareWorkspaceWithRef(@NonNull final Repository repository, final IResource file, final String refName, final IWorkbenchPage page) {
if (file == null) {
return;
}
final IPath location = file.getLocation();
if (location == null) {
return;
}
Job job = new Job(UIText.CompareUtils_jobName) {
@Override
public IStatus run(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
final RepositoryMapping mapping = RepositoryMapping.getMapping(file);
if (mapping == null) {
return Activator.createErrorStatus(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, location, repository));
}
final ITypedElement base;
if (Files.isSymbolicLink(location.toFile().toPath())) {
base = new LocalNonWorkspaceTypedElement(repository, location);
} else if (file instanceof IFile) {
base = SaveableCompareEditorInput.createFileElement((IFile) file);
} else {
return Activator.createErrorStatus(NLS.bind(UIText.CompareUtils_wrongResourceArgument, location, file));
}
final String gitPath = mapping.getRepoRelativePath(file);
CompareEditorInput in;
try {
in = prepareCompareInput(repository, gitPath, base, refName);
} catch (IOException e) {
return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
openCompareEditorRunnable(page, in);
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
Aggregations