Search in sources :

Example 6 with RepositoryMapping

use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.

the class UntrackOperation method remove.

private void remove(final IResource resource) throws CoreException {
    final IProject proj = resource.getProject();
    if (proj == null) {
        return;
    }
    final GitProjectData pd = GitProjectData.get(proj);
    if (pd == null) {
        return;
    }
    final RepositoryMapping rm = pd.getRepositoryMapping(resource);
    if (rm == null) {
        return;
    }
    db = rm.getRepository();
    remove(resource.getLocation());
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) GitProjectData(org.eclipse.egit.core.project.GitProjectData) IProject(org.eclipse.core.resources.IProject)

Example 7 with RepositoryMapping

use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.

the class RuleUtil method getRuleForRepositories.

/**
 * Calculates a {@link ISchedulingRule} for all repositories related to the
 * given resources.
 *
 * @see RuleUtil#getRule(Repository)
 * @param resources
 * @return scheduling rule
 */
public static ISchedulingRule getRuleForRepositories(IResource[] resources) {
    ISchedulingRule result = null;
    Set<Repository> repositories = new HashSet<Repository>();
    for (IResource resource : resources) {
        RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
        if (mapping != null)
            repositories.add(mapping.getRepository());
    }
    for (Repository repository : repositories) {
        ISchedulingRule rule = getRule(repository);
        result = MultiRule.combine(result, rule);
    }
    return result;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IResource(org.eclipse.core.resources.IResource) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) HashSet(java.util.HashSet)

Example 8 with RepositoryMapping

use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.

the class DisconnectConnectTest method testDisconnectAndReconnect.

@Test
public void testDisconnectAndReconnect() throws Exception {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1);
    RepositoryMapping mapping = RepositoryMapping.getMapping(project);
    assertNotNull(mapping);
    clickOnDisconnect();
    ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
    TestUtil.waitForJobs(500, 5000);
    mapping = RepositoryMapping.getMapping(project);
    assertNull(mapping);
    SWTBotShell connectDialog = openConnectDialog();
    // test the "share with repository in parent folder" scenario
    connectDialog.bot().checkBox(UIText.ExistingOrNewPage_InternalModeCheckbox).select();
    connectDialog.bot().tree().getAllItems()[0].select();
    connectDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
    bot.waitUntil(Conditions.shellCloses(connectDialog));
    ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
    TestUtil.waitForJobs(500, 5000);
    mapping = RepositoryMapping.getMapping(project);
    if (mapping == null) {
        TestUtil.waitForJobs(500, 5000);
    }
    assertNotNull(mapping);
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 9 with RepositoryMapping

use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.

the class DisconnectConnectTest method testDecorations.

@Test
public void testDecorations() throws Exception {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1);
    RepositoryMapping mapping = RepositoryMapping.getMapping(project);
    assertNotNull(mapping);
    SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
    TestUtil.navigateTo(projectExplorerTree, new Path(FILE1_PATH).segments());
    touch("File modified");
    clickOnDisconnect();
    TestUtil.waitForJobs(500, 5000);
    TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    TestUtil.waitForDecorations();
    assertFalse("Project should not have git decorations", getProjectItem(projectExplorerTree, PROJ1).getText().contains("["));
    SWTBotShell connectDialog = openConnectDialog();
    connectDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
    bot.waitUntil(Conditions.shellCloses(connectDialog));
    TestUtil.waitForJobs(500, 5000);
    TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    TestUtil.waitForDecorations();
    assertTrue("Project should have git decorations", getProjectItem(projectExplorerTree, PROJ1).getText().contains("[FirstRepository"));
    SWTBotTreeItem fileNode = TestUtil.navigateTo(projectExplorerTree, new Path(FILE1_PATH).segments());
    assertTrue("File should have git decorations", fileNode.getText().startsWith(">"));
}
Also used : Path(org.eclipse.core.runtime.Path) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 10 with RepositoryMapping

use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.

the class CompareUtils method compareHeadWithWorkspace.

/**
 * Opens a compare editor. The workspace version of the given file is
 * compared with the version in the HEAD commit.
 *
 * @param repository
 * @param file
 */
public static void compareHeadWithWorkspace(Repository repository, @NonNull IFile file) {
    RepositoryMapping mapping = RepositoryMapping.getMapping(file);
    if (mapping == null) {
        Activator.error(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, file.getLocation(), repository), null);
        return;
    }
    String path = mapping.getRepoRelativePath(file);
    ITypedElement base = getHeadTypedElement(repository, path);
    if (base == null)
        return;
    IFileRevision nextFile = new WorkspaceFileRevision(file);
    String encoding = null;
    try {
        encoding = file.getCharset();
    } catch (CoreException e) {
        Activator.handleError(UIText.CompareUtils_errorGettingEncoding, e, true);
    }
    ITypedElement next = new FileRevisionTypedElement(nextFile, encoding);
    GitCompareFileRevisionEditorInput input = new GitCompareFileRevisionEditorInput(next, base, null);
    CompareUI.openCompareDialog(input);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IFileRevision(org.eclipse.team.core.history.IFileRevision) GitCompareFileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput) ITypedElement(org.eclipse.compare.ITypedElement) WorkspaceFileRevision(org.eclipse.egit.core.internal.storage.WorkspaceFileRevision) FileRevisionTypedElement(org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement)

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