Source:
private void fillTreeItemWithGitDirectory(RepositoryMapping m, TreeItem treeItem, boolean isAlternative) { if (m.getGitDir() == null) treeItem.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; treeItem.setText(0, path.toString()); } treeItem.setText(2, relativePath.toOSString().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) { treeItem.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 treeItem, boolean isAlternative) { if (m.getGitDir() == null) treeItem.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; treeItem.setText(0, path.toString()); } treeItem.setText(2, relativePath.toOSString()); 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) { treeItem.setChecked(true); } revWalk.dispose(); } } repo.close(); } catch (IOException e1) { Activator.logError("Failed to detect which repository to use", e1); } } }