Search in sources :

Example 1 with ProjectRecord

use of org.eclipse.egit.ui.internal.clone.ProjectRecord in project egit by eclipse.

the class SubmoduleFolderTest method setUp.

@Before
public void setUp() throws Exception {
    parentRepositoryGitDir = createProjectAndCommitToRepository();
    childRepositoryGitDir = createProjectAndCommitToRepository(CHILDREPO, CHILDPROJECT);
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(parentRepositoryGitDir);
    parentRepository = lookupRepository(parentRepositoryGitDir);
    childRepository = lookupRepository(childRepositoryGitDir);
    parentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1);
    IFolder folder = parentProject.getFolder(FOLDER);
    IFolder subfolder = folder.getFolder(SUBFOLDER);
    subfolder.create(false, true, null);
    assertTrue(subfolder.exists());
    IFile someFile = subfolder.getFile("dummy.txt");
    touch(PROJ1, someFile.getProjectRelativePath().toOSString(), "Dummy content");
    addAndCommit(someFile, "Commit sub/dummy.txt");
    childFolder = subfolder.getFolder(CHILD);
    Git.wrap(parentRepository).submoduleAdd().setPath(childFolder.getFullPath().toPortableString()).setURI(childRepository.getDirectory().toURI().toString()).call();
    TestRepository parentRepo = new TestRepository(parentRepository);
    parentRepo.trackAllFiles(parentProject);
    parentRepo.commit("Commit submodule");
    assertTrue(SubmoduleWalk.containsGitModulesFile(parentRepository));
    parentProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    assertTrue(childFolder.exists());
    // Let's get rid of the child project imported directly from the child
    // repository.
    childProject = ResourcesPlugin.getWorkspace().getRoot().getProject(CHILDPROJECT);
    childProject.delete(false, true, null);
    // Re-import it from the parent repo's submodule!
    IFile projectFile = childFolder.getFolder(CHILDPROJECT).getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
    assertTrue(projectFile.exists());
    ProjectRecord pr = new ProjectRecord(projectFile.getLocation().toFile());
    ProjectUtils.createProjects(Collections.singleton(pr), null, null);
    assertTrue(childProject.isOpen());
    // Now we have a parent repo in a state as if we had recursively
    // cloned some remote repo with a submodule and then imported all
    // projects. Look up the submodule repository instance through the
    // repository cache, so that we get the same instance that EGit
    // uses.
    subRepository = SubmoduleWalk.getSubmoduleRepository(childFolder.getParent().getLocation().toFile(), CHILD);
    assertNotNull(subRepository);
    subRepositoryGitDir = subRepository.getDirectory();
    subRepository.close();
    subRepository = lookupRepository(subRepositoryGitDir);
    assertNotNull(subRepository);
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) IFile(org.eclipse.core.resources.IFile) ProjectRecord(org.eclipse.egit.ui.internal.clone.ProjectRecord) IFolder(org.eclipse.core.resources.IFolder) Before(org.junit.Before)

Example 2 with ProjectRecord

use of org.eclipse.egit.ui.internal.clone.ProjectRecord in project egit by eclipse.

the class BranchProjectTracker method restore.

/**
 * Restore projects associated with the given branch to the workspace
 *
 * @param branch
 * @param monitor
 */
public void restore(final String branch, final IProgressMonitor monitor) {
    String[] paths = getProjectPaths(branch);
    if (paths.length == 0)
        return;
    Set<ProjectRecord> records = new LinkedHashSet<>();
    File parent = repository.getWorkTree();
    for (String path : paths) {
        File root;
        if (!REPO_ROOT.equals(path)) {
            root = new File(parent, path);
        } else {
            root = parent;
        }
        if (!root.isDirectory()) {
            continue;
        }
        File projectDescription = new File(root, IProjectDescription.DESCRIPTION_FILE_NAME);
        if (!projectDescription.isFile()) {
            continue;
        }
        ProjectRecord record = new ProjectRecord(projectDescription);
        if (record.getProjectDescription() == null) {
            continue;
        }
        records.add(record);
    }
    if (records.isEmpty()) {
        return;
    }
    try {
        ProjectUtils.createProjects(records, true, null, monitor);
    } catch (InvocationTargetException e) {
        Activator.logError("Error restoring branch-project associations", // $NON-NLS-1$
        e);
    } catch (InterruptedException ignored) {
    // Ignored
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProjectRecord(org.eclipse.egit.ui.internal.clone.ProjectRecord) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ProjectRecord (org.eclipse.egit.ui.internal.clone.ProjectRecord)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedHashSet (java.util.LinkedHashSet)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 TestRepository (org.eclipse.egit.core.test.TestRepository)1 Before (org.junit.Before)1