use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class ConnectProviderOperationTest method testNewRepository.
@Test
public void testNewRepository() throws CoreException, IOException {
Repository repository = FileRepositoryBuilder.create(gitDir);
repository.create();
repository.close();
ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
operation.execute(null);
assertTrue(RepositoryProvider.isShared(project.getProject()));
assertTrue(gitDir.exists());
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class ConnectProviderOperationTest method testNoAutoIgnoresDerivedFolder.
@Test
public void testNoAutoIgnoresDerivedFolder() throws Exception {
// disable auto-ignore
IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
boolean autoignore = p.getBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, false);
if (autoignore) {
p.putBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, false);
}
try {
Repository repository = FileRepositoryBuilder.create(gitDir);
repository.create();
repository.close();
project.setBinFolderDerived();
project.createSourceFolder();
// not connected: no ignore
IFolder binFolder = project.getProject().getFolder("bin");
IPath binPath = binFolder.getLocation();
assertTrue(binFolder.exists());
assertFalse(RepositoryUtil.canBeAutoIgnored(binPath));
IFolder srcFolder = project.getProject().getFolder("src");
IPath srcPath = srcFolder.getLocation();
assertTrue(srcFolder.exists());
assertFalse(RepositoryUtil.canBeAutoIgnored(srcPath));
IFolder notThere = project.getProject().getFolder("notThere");
IPath notTherePath = notThere.getLocation();
assertFalse(notThere.exists());
assertFalse(RepositoryUtil.canBeAutoIgnored(notTherePath));
// connect to git
ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
operation.execute(null);
assertTrue(RepositoryProvider.isShared(project.getProject()));
Job.getJobManager().join(JobFamilies.AUTO_IGNORE, null);
// connected, and *can* be automatically ignored
assertTrue(RepositoryUtil.canBeAutoIgnored(binPath));
// connected, and *can* be automatically ignored
assertTrue(RepositoryUtil.canBeAutoIgnored(srcPath));
// connected but not existing: we should not autoignore
assertFalse(RepositoryUtil.canBeAutoIgnored(notTherePath));
assertTrue(gitDir.exists());
} finally {
if (autoignore) {
p.putBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, true);
}
}
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class ConnectProviderOperationTest method testNewUnsharedFile.
@Test
public void testNewUnsharedFile() throws CoreException, Exception {
project.createSourceFolder();
IFile fileA = project.getProject().getFolder("src").getFile("A.java");
String srcA = "class A {\n" + "}\n";
fileA.create(new ByteArrayInputStream(srcA.getBytes("UTF-8")), false, null);
TestRepository thisGit = new TestRepository(gitDir);
File committable = new File(fileA.getLocationURI());
thisGit.addAndCommit(project.project, committable, "testNewUnsharedFile\n\nJunit tests\n");
assertNull(RepositoryProvider.getProvider(project.getProject()));
ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
operation.execute(null);
assertNotNull(RepositoryProvider.getProvider(project.getProject()));
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class ProjectUtils method createProjects.
/**
* Create (import) a set of existing projects. The projects are
* automatically connected to the repository they reside in.
*
* @param projectsToCreate
* the projects to create
* @param open
* true to open existing projects, false to leave in current
* state
* @param selectedWorkingSets
* the workings sets to add the created projects to, may be null
* or empty
* @param monitor
* @throws InvocationTargetException
* @throws InterruptedException
*/
public static void createProjects(final Set<ProjectRecord> projectsToCreate, final boolean open, final IWorkingSet[] selectedWorkingSets, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (projectsToCreate.isEmpty()) {
return;
}
IWorkspaceRunnable wsr = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor actMonitor) throws CoreException {
IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
if (actMonitor.isCanceled()) {
throw new OperationCanceledException();
}
Map<IProject, File> projectsToConnect = new HashMap<>();
SubMonitor progress = SubMonitor.convert(actMonitor, projectsToCreate.size() * 2 + 1);
for (ProjectRecord projectRecord : projectsToCreate) {
if (progress.isCanceled()) {
throw new OperationCanceledException();
}
progress.setTaskName(projectRecord.getProjectLabel());
IProject project = createExistingProject(projectRecord, open, progress.newChild(1));
if (project == null) {
continue;
}
RepositoryFinder finder = new RepositoryFinder(project);
finder.setFindInChildren(false);
Collection<RepositoryMapping> mappings = finder.find(progress.newChild(1));
if (!mappings.isEmpty()) {
RepositoryMapping mapping = mappings.iterator().next();
IPath absolutePath = mapping.getGitDirAbsolutePath();
if (absolutePath != null) {
projectsToConnect.put(project, absolutePath.toFile());
}
}
if (selectedWorkingSets != null && selectedWorkingSets.length > 0) {
workingSetManager.addToWorkingSets(project, selectedWorkingSets);
}
}
if (!projectsToConnect.isEmpty()) {
ConnectProviderOperation connect = new ConnectProviderOperation(projectsToConnect);
connect.execute(progress.newChild(1));
}
}
};
try {
ResourcesPlugin.getWorkspace().run(wsr, monitor);
} catch (OperationCanceledException e) {
throw new InterruptedException();
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
Aggregations