Source:
private void fillTreeItemWithGitDirectory(RepositoryMapping m, TreeItem treeItem2, boolean isAlternative) { if (m.getGitDir() == null) treeItem2.setText(2, UIText.ExistingOrNewPage_SymbolicValueEmptyMapping); else { IPath container = m.getContainerPath(); if (!container.isEmpty()) container = Path.fromOSString("."); IPath relativePath = container.append(m.getGitDir()); if (isAlternative) { IPath withoutLastSegment = relativePath.removeLastSegments(1); IPath path; if (withoutLastSegment.isEmpty()) path = Path.fromPortableString("."); else path = withoutLastSegment; treeItem2.setText(0, path.toString()); } treeItem2.setText(2, relativePath.toString()); try { IProject project = m.getContainer().getProject(); FileRepository repo = new FileRepository(m.getGitDirAbsolutePath().toFile()); File workTree = repo.getWorkTree(); IPath workTreePath = Path.fromOSString(workTree.getAbsolutePath()); if (workTreePath.isPrefixOf(project.getLocation())) { IPath makeRelativeTo = project.getLocation().makeRelativeTo(workTreePath); String repoRelativePath = makeRelativeTo.append("/.project").toPortableString(); ObjectId headComitId = repo.resolve(Constants.HEAD); if (headComitId != null) { RevWalk revWalk = new RevWalk(repo); RevCommit headCommit = revWalk.parseCommit(headComitId); RevTree headTree = headCommit.getTree(); TreeWalk projectInRepo = TreeWalk.forPath(repo, repoRelativePath, headTree); if (projectInRepo != null) { treeItem2.setChecked(true); } revWalk.dispose(); } } repo.close(); } catch (IOException e1) { Activator.logError("Failed to detect which repository to use", e1); } } }

Target:
private void fillTreeItemWithGitDirectory(RepositoryMapping m, TreeItem treeItem2, boolean isAlternative) { if (m.getGitDir() == null) treeItem2.setText(2, UIText.ExistingOrNewPage_SymbolicValueEmptyMapping); else { IPath container = m.getContainerPath(); if (!container.isEmpty()) container = Path.fromOSString("."); IPath relativePath = container.append(m.getGitDir()); if (isAlternative) { IPath withoutLastSegment = relativePath.removeLastSegments(1); IPath path; if (withoutLastSegment.isEmpty()) path = Path.fromPortableString("."); else path = withoutLastSegment; treeItem2.setText(0, path.toString()); } treeItem2.setText(2, relativePath.toString()); try { IProject project = m.getContainer().getProject(); FileRepository repo = new FileRepository(m.getGitDirAbsolutePath().toFile()); File workTree = repo.getWorkTree(); IPath workTreePath = Path.fromOSString(workTree.getAbsolutePath()); if (workTreePath.isPrefixOf(project.getLocation())) { IPath makeRelativeTo = project.getLocation().makeRelativeTo(workTreePath); String repoRelativePath = makeRelativeTo.append("/.project").toPortableString(); ObjectId headCommitId = repo.resolve(Constants.HEAD); if (headCommitId != null) { RevWalk revWalk = new RevWalk(repo); RevCommit headCommit = revWalk.parseCommit(headCommitId); RevTree headTree = headCommit.getTree(); TreeWalk projectInRepo = TreeWalk.forPath(repo, repoRelativePath, headTree); if (projectInRepo != null) { treeItem2.setChecked(true); } revWalk.dispose(); } } repo.close(); } catch (IOException e1) { Activator.logError("Failed to detect which repository to use", e1); } } }