@Before public void setUp() throws Exception { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); FileUtils.mkdir(new File(root.getLocation().toFile(), "Sub"), true); gitDir = new File(new File(root.getLocation().toFile(), "Sub"), Constants.DOT_GIT); repository = FileRepositoryBuilder.create(gitDir); repository.create(); project = root.getProject(TEST_PROJECT); project.create(null); project.open(null); IProjectDescription description = project.getDescription(); description.setLocation(root.getLocation().append(TEST_PROJECT_LOC)); project.move(description, IResource.FORCE, null); project2 = root.getProject(TEST_PROJECT2); project2.create(null); project2.open(null); gitDir2 = new File(project2.getLocation().toFile().getAbsoluteFile(), Constants.DOT_GIT); repository2 = FileRepositoryBuilder.create(gitDir2); repository2.create(); RepositoryMapping mapping = RepositoryMapping.create(project, gitDir); RepositoryMapping mapping2 = RepositoryMapping.create(project2, gitDir2); GitProjectData projectData = new GitProjectData(project); GitProjectData projectData2 = new GitProjectData(project2); projectData.setRepositoryMappings(Collections.singletonList(mapping)); projectData.store(); projectData2.setRepositoryMappings(Collections.singletonList(mapping2)); projectData2.store(); GitProjectData.add(project, projectData); GitProjectData.add(project2, projectData2); RepositoryProvider.map(project, GitProvider.class.getName()); RepositoryProvider.map(project2, GitProvider.class.getName()); JGitTestUtil.write( new File(repository.getWorkTree(), TEST_PROJECT + "/" + TEST_FILE), "Some data"); JGitTestUtil.write(new File(repository2.getWorkTree(), TEST_FILE2), "Some other data"); project.refreshLocal(IResource.DEPTH_INFINITE, null); project2.refreshLocal(IResource.DEPTH_INFINITE, null); git = new Git(repository); git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); git = new Git(repository2); git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); git.branchRename().setNewName("main").call(); }
/* (non-Javadoc) * @see org.eclipse.egit.core.op.IEGitOperation#execute(org.eclipse.core.runtime.IProgressMonitor) */ public void execute(IProgressMonitor m) throws CoreException { if (m == null) { m = new NullProgressMonitor(); } m.beginTask(CoreText.ConnectProviderOperation_connecting, 100 * projects.size()); try { for (Iterator iterator = projects.keySet().iterator(); iterator.hasNext(); ) { IProject project = (IProject) iterator.next(); m.setTaskName( NLS.bind(CoreText.ConnectProviderOperation_ConnectingProject, project.getName())); // TODO is this the right location? if (GitTraceLocation.CORE.isActive()) GitTraceLocation.getTrace() .trace( GitTraceLocation.CORE.getLocation(), "Locating repository for " + project); // $NON-NLS-1$ Collection<RepositoryMapping> repos = new RepositoryFinder(project).find(new SubProgressMonitor(m, 40)); File suggestedRepo = projects.get(project); RepositoryMapping actualMapping = findActualRepository(repos, suggestedRepo); if (actualMapping != null) { GitProjectData projectData = new GitProjectData(project); try { projectData.setRepositoryMappings(Arrays.asList(actualMapping)); projectData.store(); } catch (CoreException ce) { GitProjectData.delete(project); throw ce; } catch (RuntimeException ce) { GitProjectData.delete(project); throw ce; } RepositoryProvider.map(project, GitProvider.class.getName()); projectData = GitProjectData.get(project); project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(m, 50)); m.worked(10); } else { // TODO is this the right location? if (GitTraceLocation.CORE.isActive()) GitTraceLocation.getTrace() .trace( GitTraceLocation.CORE.getLocation(), "Attempted to share project without repository ignored :" //$NON-NLS-1$ + project); m.worked(60); } } } finally { m.done(); } }