use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class AbstractSynchronizeViewTest method createEmptyRepository.
// based on LocalRepositoryTestCase#createProjectAndCommitToRepository(String)
protected void createEmptyRepository() throws Exception {
File gitDir = new File(new File(getTestDirectory(), EMPTY_REPOSITORY), Constants.DOT_GIT);
Repository myRepository = FileRepositoryBuilder.create(gitDir);
myRepository.create();
// we need to commit into master first
IProject firstProject = ResourcesPlugin.getWorkspace().getRoot().getProject(EMPTY_PROJECT);
if (firstProject.exists()) {
firstProject.delete(true, null);
TestUtil.waitForJobs(100, 5000);
}
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(EMPTY_PROJECT);
desc.setLocation(new Path(new File(myRepository.getWorkTree(), EMPTY_PROJECT).getPath()));
firstProject.create(desc, null);
firstProject.open(null);
assertTrue("Project is not accessible: " + firstProject, firstProject.isAccessible());
IFolder folder = firstProject.getFolder(FOLDER);
folder.create(false, true, null);
IFile textFile = folder.getFile(FILE1);
textFile.create(new ByteArrayInputStream("Hello, world".getBytes(firstProject.getDefaultCharset())), false, null);
IFile textFile2 = folder.getFile(FILE2);
textFile2.create(new ByteArrayInputStream("Some more content".getBytes(firstProject.getDefaultCharset())), false, null);
TestUtil.waitForJobs(50, 5000);
try {
new ConnectProviderOperation(firstProject, gitDir).execute(null);
} catch (Exception e) {
Activator.logError("Failed to connect project to repository", e);
}
assertConnected(firstProject);
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class SynchronizeViewRemoteAwareChangeSetModelTest method createMockLogicalRepository.
protected void createMockLogicalRepository() throws Exception {
File gitDir = new File(new File(getTestDirectory(), MOCK_LOGICAL_PROJECT), Constants.DOT_GIT);
Repository repo = FileRepositoryBuilder.create(gitDir);
repo.create();
// we need to commit into master first
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(MOCK_LOGICAL_PROJECT);
if (project.exists()) {
project.delete(true, null);
TestUtil.waitForJobs(100, 5000);
}
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(MOCK_LOGICAL_PROJECT);
desc.setLocation(new Path(new File(repo.getWorkTree(), MOCK_LOGICAL_PROJECT).getPath()));
project.create(desc, null);
project.open(null);
assertTrue("Project is not accessible: " + project, project.isAccessible());
TestUtil.waitForJobs(50, 5000);
try {
new ConnectProviderOperation(project, gitDir).execute(null);
} catch (Exception e) {
Activator.logError("Failed to connect project to repository", e);
}
assertConnected(project);
mockLogicalFile = project.getFile("index.mocklogical");
mockLogicalFile.create(new ByteArrayInputStream("file1.txt\nfile2.txt".getBytes(project.getDefaultCharset())), false, null);
IFile file1 = project.getFile("file1.txt");
file1.create(new ByteArrayInputStream("Content 1".getBytes(project.getDefaultCharset())), false, null);
IFile file2 = project.getFile("file2.txt");
file2.create(new ByteArrayInputStream("Content 2".getBytes(project.getDefaultCharset())), false, null);
IFile[] commitables = new IFile[] { mockLogicalFile, file1, file2 };
List<IFile> untracked = new ArrayList<>();
untracked.addAll(Arrays.asList(commitables));
CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
op.execute(null);
RevCommit firstCommit = op.getCommit();
CreateLocalBranchOperation createBranchOp = new CreateLocalBranchOperation(repo, "refs/heads/stable", firstCommit);
createBranchOp.execute(null);
// Delete file2.txt from logical model and add file3
mockLogicalFile = touch(MOCK_LOGICAL_PROJECT, "index.mocklogical", "file1.txt\nfile3.txt");
file2.delete(true, null);
touch(MOCK_LOGICAL_PROJECT, "file1.txt", "Content 1 modified");
IFile file3 = project.getFile("file3.txt");
file3.create(new ByteArrayInputStream("Content 3".getBytes(project.getDefaultCharset())), false, null);
commitables = new IFile[] { mockLogicalFile, file1, file2, file3 };
untracked = new ArrayList<>();
untracked.add(file3);
op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Second commit");
op.execute(null);
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class SharingWizard method performFinish.
@Override
public boolean performFinish() {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (!existingPage.getInternalMode()) {
try {
final Map<IProject, File> projectsToMove = existingPage.getProjects(true);
final Repository selectedRepository = existingPage.getSelectedRepository();
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
SubMonitor progress = SubMonitor.convert(monitor, projectsToMove.size() * 2);
for (Map.Entry<IProject, File> entry : projectsToMove.entrySet()) {
closeOpenEditorsForProject(activePage, entry.getKey());
IPath targetLocation = new Path(entry.getValue().getPath());
IPath currentLocation = entry.getKey().getLocation();
if (!targetLocation.equals(currentLocation)) {
MoveProjectOperation op = new MoveProjectOperation(entry.getKey(), entry.getValue().toURI(), UIText.SharingWizard_MoveProjectActionLabel);
try {
IStatus result = op.execute(progress.newChild(1), null);
if (!result.isOK())
throw new RuntimeException();
} catch (ExecutionException e) {
if (e.getCause() != null)
throw new InvocationTargetException(e.getCause());
throw new InvocationTargetException(e);
}
} else {
progress.worked(1);
}
try {
new ConnectProviderOperation(entry.getKey(), selectedRepository.getDirectory()).execute(progress.newChild(1));
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
}
});
} catch (InvocationTargetException e) {
Activator.handleError(UIText.SharingWizard_failed, e.getCause(), true);
return false;
} catch (InterruptedException e) {
// ignore for the moment
}
return true;
} else {
final ConnectProviderOperation op = new ConnectProviderOperation(existingPage.getProjects(true));
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException {
try {
op.execute(monitor);
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
Set<File> filesToAdd = new HashSet<>();
// collect all files first
for (Entry<IProject, File> entry : existingPage.getProjects(true).entrySet()) filesToAdd.add(entry.getValue());
// view
for (File file : filesToAdd) Activator.getDefault().getRepositoryUtil().addConfiguredRepository(file);
}
});
} catch (CoreException ce) {
throw new InvocationTargetException(ce);
}
}
});
return true;
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = e.getCause();
}
if (e instanceof CoreException) {
IStatus status = ((CoreException) e).getStatus();
e = status.getException();
}
Activator.handleError(UIText.SharingWizard_failed, e, true);
return false;
}
}
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class ConnectProviderOperationTest method testNewRepositoryCaseSensitive.
@Test
public void testNewRepositoryCaseSensitive() throws CoreException, IOException {
if (FS.detect().isCaseSensitive()) {
return;
}
Repository repository = FileRepositoryBuilder.create(gitDir);
repository.create();
repository.close();
IPath path = new Path(gitDir.toString());
String device = path.getDevice();
if (device == null) {
// not windows???
return;
}
if (!device.toLowerCase(Locale.ROOT).equals(device)) {
path = path.setDevice(device.toLowerCase(Locale.ROOT));
} else {
path = path.setDevice(device.toUpperCase(Locale.ROOT));
}
assertNotEquals(path, new Path(gitDir.toString()));
assertNotEquals(path.toFile().toString(), new Path(gitDir.toString()).toFile().toString());
assertEquals(path.toFile(), gitDir);
ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), path.toFile());
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 DualRepositoryTestCase method importProject.
protected IProject importProject(TestRepository repo, String projectName) throws Exception {
IProject firstProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (firstProject.exists())
firstProject.delete(false, null);
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
File parentFile = repo.getRepository().getWorkTree();
desc.setLocation(new Path(new File(parentFile, projectName).getPath()));
firstProject.create(desc, null);
firstProject.open(null);
ConnectProviderOperation cop = new ConnectProviderOperation(firstProject, repo.getRepository().getDirectory());
cop.execute(null);
return firstProject;
}
Aggregations