Search in sources :

Example 46 with RepositoryMapping

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("..");
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping)

Example 47 with RepositoryMapping

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();
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping)

Example 48 with RepositoryMapping

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();
}
Also used : DirCache(org.eclipse.jgit.dircache.DirCache) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) TestProject(org.eclipse.egit.core.test.TestProject) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Example 49 with RepositoryMapping

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());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 50 with RepositoryMapping

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());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)87 Repository (org.eclipse.jgit.lib.Repository)40 IResource (org.eclipse.core.resources.IResource)31 IProject (org.eclipse.core.resources.IProject)23 IPath (org.eclipse.core.runtime.IPath)20 IOException (java.io.IOException)18 File (java.io.File)17 CoreException (org.eclipse.core.runtime.CoreException)15 IFile (org.eclipse.core.resources.IFile)12 Path (org.eclipse.core.runtime.Path)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 GitProjectData (org.eclipse.egit.core.project.GitProjectData)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 HashMap (java.util.HashMap)5