use of org.eclipse.egit.core.project.RepositoryMapping in project jbosstools-openshift by jbosstools.
the class EGitUtils method isGitFolderInRootOf.
public static boolean isGitFolderInRootOf(IProject project) {
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
if (mapping == null) {
return false;
}
String gitFolderRelativePath = mapping.getGitDir();
if (StringUtils.isEmptyOrNull(gitFolderRelativePath)) {
return false;
}
return !gitFolderRelativePath.startsWith("..");
}
use of org.eclipse.egit.core.project.RepositoryMapping in project jbosstools-openshift by jbosstools.
the class EGitUtils method getRepository.
/**
* Gets the repository that is configured to the given project. Returns
* <code>null</code> if the given project is not git shared.
*
* @param project
* the project
* @return the repository
*/
public static Repository getRepository(IProject project) {
Assert.isLegal(project != null, "Could not get repository. No project provided");
RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
if (repositoryMapping == null) {
return null;
}
return repositoryMapping.getRepository();
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitMoveDeleteHookTest method testDeleteProject.
@Test
public void testDeleteProject() throws Exception {
TestProject project = initRepoAboveProjectInsideWs("P/", "");
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt") });
addToIndexOperation.execute(null);
RepositoryMapping mapping = RepositoryMapping.getMapping(project.getProject());
IPath gitDirAbsolutePath = mapping.getGitDirAbsolutePath();
Repository db = FileRepositoryBuilder.create(gitDirAbsolutePath.toFile());
DirCache index = DirCache.read(db.getIndexFile(), db.getFS());
assertNotNull(index.getEntry("P/Project-1/file.txt"));
db.close();
db = null;
project.getProject().delete(true, null);
assertNull(RepositoryMapping.getMapping(project.getProject()));
// Check that the repo is still there. Being a bit paranoid we look for
// a file
assertTrue(gitDirAbsolutePath.toString(), gitDirAbsolutePath.append("HEAD").toFile().exists());
db = FileRepositoryBuilder.create(gitDirAbsolutePath.toFile());
index = DirCache.read(db.getIndexFile(), db.getFS());
// FIXME: Shouldn't we unstage deleted projects?
assertNotNull(index.getEntry("P/Project-1/file.txt"));
db.close();
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitProjectSetCapabilityTest method testImportWithDifferentBranchesOfSameRepo.
@Test
public void testImportWithDifferentBranchesOfSameRepo() throws Exception {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath reposPath = new Path(testDirectory.getPath()).append("repos");
pathsToClean.add(reposPath.toFile());
IPath xPath = reposPath.append("x");
IProject xaProject = createProject(xPath, "xa");
IProject xbProject = createProject(xPath, "xb");
createRepository(xPath, "notused", "stable");
xaProject.delete(false, true, null);
xbProject.delete(false, true, null);
String xaMasterReference = "1.0," + xPath.toFile().toURI().toString() + ",master,xa";
String xbStableReference = "1.0," + xPath.toFile().toURI().toString() + ",stable,xb";
String[] references = new String[] { xaMasterReference, xbStableReference };
addToWorkspace(references);
pathsToClean.add(root.getLocation().append("x").toFile());
pathsToClean.add(root.getLocation().append("x_stable").toFile());
IProject xaImported = root.getProject("xa");
createdProjects.add(xaImported);
assertTrue(xaImported.exists());
assertEquals(new Path(RepositoryUtil.getDefaultRepositoryDir()).append("x/xa"), xaImported.getLocation());
RepositoryMapping xaMapping = RepositoryMapping.getMapping(xaImported);
assertNotNull(xaMapping);
assertEquals("master", xaMapping.getRepository().getBranch());
IProject xbImported = root.getProject("xb");
createdProjects.add(xbImported);
assertTrue(xbImported.exists());
assertEquals(new Path(RepositoryUtil.getDefaultRepositoryDir()).append("x_stable/xb"), xbImported.getLocation());
RepositoryMapping xbMapping = RepositoryMapping.getMapping(xbImported);
assertNotNull(xbMapping);
assertEquals("stable", xbMapping.getRepository().getBranch());
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitProjectSetCapabilityTest method testImport.
@Test
public void testImport() throws Exception {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath reposPath = new Path(testDirectory.getPath()).append("repos");
pathsToClean.add(reposPath.toFile());
IPath aPath = reposPath.append("a");
IProject aProject = createProject(reposPath, "a");
createRepository(aPath, "notused", "master");
aProject.delete(false, true, null);
IPath bPath = reposPath.append("b");
IProject baProject = createProject(bPath, "ba");
IProject bbProject = createProject(bPath, "bb");
createRepository(bPath, "notused", "master");
baProject.delete(false, true, null);
bbProject.delete(false, true, null);
IPath cPath = reposPath.append("c");
IProject cProject = createProject(reposPath, "c");
createRepository(cPath, "notused", "stable");
cProject.delete(false, true, null);
String aReference = "1.0," + aPath.toFile().toURI().toString() + ",master,.";
String baReference = "1.0," + bPath.toFile().toURI().toString() + ",master,ba";
String bbReference = "1.0," + bPath.toFile().toURI().toString() + ",master,bb";
String cReference = "1.0," + cPath.toFile().toURI().toString() + ",stable,.";
String[] references = new String[] { aReference, baReference, bbReference, cReference };
addToWorkspace(references);
pathsToClean.add(root.getLocation().append("b").toFile());
IProject aImported = root.getProject("a");
createdProjects.add(aImported);
assertTrue(aImported.exists());
assertNotNull(RepositoryMapping.getMapping(aImported));
IProject baImported = root.getProject("ba");
createdProjects.add(baImported);
assertTrue(baImported.exists());
assertEquals(new Path(RepositoryUtil.getDefaultRepositoryDir()).append("b/ba"), baImported.getLocation());
assertNotNull(RepositoryMapping.getMapping(baImported));
IProject bbImported = root.getProject("bb");
createdProjects.add(bbImported);
assertTrue(bbImported.exists());
assertEquals(new Path(RepositoryUtil.getDefaultRepositoryDir()).append("b/bb"), bbImported.getLocation());
assertNotNull(RepositoryMapping.getMapping(bbImported));
IProject cImported = root.getProject("c");
createdProjects.add(cImported);
assertTrue(cImported.exists());
RepositoryMapping cMapping = RepositoryMapping.getMapping(cImported);
assertNotNull(cMapping);
assertEquals("stable", cMapping.getRepository().getBranch());
}
Aggregations