use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class GitProjectSetCapabilityTest method connectProject.
private void connectProject(IProject project, File gitDir) throws CoreException {
ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
operation.execute(null);
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class ProjectReferenceImporter method importProjects.
private List<IProject> importProjects(final Set<ProjectReference> projects, final IPath workDir, final File repositoryPath, final IProgressMonitor monitor) throws TeamException {
try {
List<IProject> importedProjects = new ArrayList<IProject>();
// import projects from the current repository to workspace
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot root = workspace.getRoot();
SubMonitor progress = SubMonitor.convert(monitor, projects.size());
for (final ProjectReference projectToImport : projects) {
SubMonitor subProgress = SubMonitor.convert(progress.newChild(1), 3);
final IPath projectDir = workDir.append(projectToImport.getProjectDir());
final IProjectDescription projectDescription = workspace.loadProjectDescription(projectDir.append(IProjectDescription.DESCRIPTION_FILE_NAME));
final IProject project = root.getProject(projectDescription.getName());
if (!project.exists()) {
project.create(projectDescription, subProgress.newChild(1));
importedProjects.add(project);
}
subProgress.setWorkRemaining(2);
project.open(subProgress.newChild(1));
final ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation(project, repositoryPath);
connectProviderOperation.execute(subProgress.newChild(1));
}
return importedProjects;
} catch (final CoreException e) {
throw TeamException.asTeamException(e);
}
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class AddCommand method autoShareProjects.
private void autoShareProjects(File repositoryDir) {
// Don't even try to auto-share for bare repositories.
IPath workingDirPath;
try {
Repository repo = Activator.getDefault().getRepositoryCache().lookupRepository(repositoryDir);
if (repo.isBare()) {
return;
}
workingDirPath = new Path(repo.getWorkTree().getAbsolutePath());
} catch (IOException e) {
org.eclipse.egit.ui.Activator.logError(e.getLocalizedMessage(), e);
return;
}
Map<IProject, File> connections = new HashMap<>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
// Skip closed projects
if (!project.isAccessible()) {
continue;
}
RepositoryProvider provider = RepositoryProvider.getProvider(project);
if (provider != null) {
continue;
}
IPath location = project.getLocation();
if (location == null) {
continue;
}
// even search for a mapping.
if (!workingDirPath.isPrefixOf(location)) {
continue;
}
RepositoryFinder f = new RepositoryFinder(project);
f.setFindInChildren(false);
try {
List<RepositoryMapping> mappings = f.find(new NullProgressMonitor());
if (!mappings.isEmpty()) {
// Connect to the first one; it's the innermost.
IPath gitDir = mappings.get(0).getGitDirAbsolutePath();
if (gitDir != null) {
connections.put(project, gitDir.toFile());
}
}
} catch (CoreException e) {
// Ignore this project in that case
continue;
}
}
if (!connections.isEmpty()) {
ConnectProviderOperation operation = new ConnectProviderOperation(connections);
operation.setRefreshResources(false);
JobUtil.scheduleUserJob(operation, CoreText.Activator_AutoShareJobName, JobFamilies.AUTO_SHARE);
}
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class GitBlobStorageTest method testGitFileHistorySingleProjectOk.
@Test
public void testGitFileHistorySingleProjectOk() throws Exception {
IProgressMonitor progress = new NullProgressMonitor();
TestProject singleRepoProject = new TestProject(true, "Project-2");
IProject proj = singleRepoProject.getProject();
File singleProjectGitDir = new File(proj.getLocation().toFile(), Constants.DOT_GIT);
if (singleProjectGitDir.exists())
FileUtils.delete(singleProjectGitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
Repository singleProjectRepo = FileRepositoryBuilder.create(singleProjectGitDir);
singleProjectRepo.create();
// Repository must be mapped in order to test the GitFileHistory
Activator.getDefault().getRepositoryUtil().addConfiguredRepository(singleProjectGitDir);
ConnectProviderOperation connectOp = new ConnectProviderOperation(proj, singleProjectGitDir);
connectOp.execute(progress);
try (Git git = new Git(singleProjectRepo)) {
IFile file = proj.getFile("file");
file.create(new ByteArrayInputStream("data".getBytes("UTF-8")), 0, progress);
git.add().addFilepattern(".").call();
RevCommit commit = git.commit().setAuthor("JUnit", "junit@jgit.org").setAll(true).setMessage("First commit").call();
GitFileHistoryProvider fhProvider = new GitFileHistoryProvider();
IFileHistory fh = fhProvider.getFileHistoryFor(singleRepoProject.getProject(), 0, null);
assertNotNull(fh);
assertEquals(fh.getFileRevisions().length, 1);
assertNotNull(fh.getFileRevision(commit.getId().getName()));
} finally {
DisconnectProviderOperation disconnectOp = new DisconnectProviderOperation(Collections.singletonList(proj));
disconnectOp.execute(progress);
Activator.getDefault().getRepositoryUtil().removeDir(singleProjectGitDir);
singleProjectRepo.close();
singleRepoProject.dispose();
}
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class GitResourceVariantTreeTest method shouldReturnTwoRoots.
/**
* When we have two or more project associated with repository, roots()
* method should return list of project. In this case we have two project
* associated with particular repository, therefore '2' value is expected.
*
* @throws Exception
*/
@Test
public void shouldReturnTwoRoots() throws Exception {
// when
// create second project
TestProject secondProject = new TestProject(true, "Project-2");
try {
IProject secondIProject = secondProject.project;
// add connect project with repository
new ConnectProviderOperation(secondIProject, gitDir).execute(null);
try (Git git = new Git(repo)) {
git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
}
GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null, null);
// then
IResource[] roots = grvt.roots();
// sort in order to be able to assert the project instances
Arrays.sort(roots, new Comparator<IResource>() {
@Override
public int compare(IResource r1, IResource r2) {
String path1 = r1.getFullPath().toString();
String path2 = r2.getFullPath().toString();
return path1.compareTo(path2);
}
});
assertEquals(2, roots.length);
IResource actualProject = roots[0];
assertEquals(this.project.project, actualProject);
IResource actualProject1 = roots[1];
assertEquals(secondIProject, actualProject1);
} finally {
secondProject.dispose();
}
}
Aggregations