Search in sources :

Example 6 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class GitSubscriberMergeContext method dispose.

@Override
public void dispose() {
    Activator activator = Activator.getDefault();
    if (activator == null)
        return;
    IndexDiffCache indexDiffCache = activator.getIndexDiffCache();
    if (indexDiffCache != null)
        indexDiffCache.removeIndexDiffChangedListener(indexChangeListener);
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
    subscriber.dispose();
    super.dispose();
}
Also used : Activator(org.eclipse.egit.core.Activator) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)

Example 7 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class MergeToolActionHandler method isEnabled.

@Override
public boolean isEnabled() {
    IPath[] paths = getSelectedLocations();
    Map<Repository, Collection<String>> pathsByRepository = ResourceUtil.splitPathsByRepository(Arrays.asList(paths));
    Set<Repository> repos = pathsByRepository.keySet();
    if (repos.size() != 1)
        return false;
    Repository repo = repos.iterator().next();
    Collection<String> selectedRepoPaths = pathsByRepository.get(repo);
    if (selectedRepoPaths.isEmpty())
        return false;
    IndexDiffCache cache = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache();
    if (cache == null)
        return false;
    IndexDiffCacheEntry entry = cache.getIndexDiffCacheEntry(repo);
    if (entry == null || entry.getIndexDiff() == null)
        return false;
    Set<String> conflictingFiles = entry.getIndexDiff().getConflicting();
    if (conflictingFiles.isEmpty())
        return false;
    for (String selectedRepoPath : selectedRepoPaths) {
        Path selectedPath = new Path(selectedRepoPath);
        for (String conflictingFile : conflictingFiles) if (selectedPath.isPrefixOf(new Path(conflictingFile)))
            return true;
    }
    return false;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Repository(org.eclipse.jgit.lib.Repository) IPath(org.eclipse.core.runtime.IPath) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) Collection(java.util.Collection) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)

Example 8 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class IndexDiffCacheTest method tearDown.

@Override
@After
public void tearDown() throws Exception {
    IndexDiffCache indexDiffCache = Activator.getDefault().getIndexDiffCache();
    indexDiffCache.removeIndexDiffChangedListener(indexDiffListener);
    testRepository.dispose();
    repository = null;
    super.tearDown();
}
Also used : IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) After(org.junit.After)

Example 9 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class LocalRepositoryTestCase method createProjectAndCommitToRepository.

protected File createProjectAndCommitToRepository(String repoName, String project1Name, String project2Name) throws Exception {
    Repository myRepository = createLocalTestRepository(repoName);
    File gitDir = myRepository.getDirectory();
    // we need to commit into master first
    IProject firstProject = createStandardTestProjectInRepository(myRepository, project1Name);
    try {
        new ConnectProviderOperation(firstProject, gitDir).execute(null);
    } catch (Exception e) {
        Activator.logError("Failed to connect project to repository", e);
    }
    assertConnected(firstProject);
    IProject secondProject = null;
    if (project2Name != null) {
        secondProject = createStandardTestProjectInRepository(myRepository, project2Name);
        try {
            new ConnectProviderOperation(secondProject, gitDir).execute(null);
        } catch (Exception e) {
            Activator.logError("Failed to connect project to repository", e);
        }
        assertConnected(secondProject);
    }
    IFile dotProject = firstProject.getFile(".project");
    assertTrue(".project is not accessible: " + dotProject, dotProject.isAccessible());
    IFolder folder = firstProject.getFolder(FOLDER);
    IFile textFile = folder.getFile(FILE1);
    IFile textFile2 = folder.getFile(FILE2);
    IFile[] commitables = null;
    if (secondProject != null) {
        folder = secondProject.getFolder(FOLDER);
        IFile secondtextFile = folder.getFile(FILE1);
        IFile secondtextFile2 = folder.getFile(FILE2);
        commitables = new IFile[] { dotProject, textFile, textFile2, secondtextFile, secondtextFile2 };
    } else {
        commitables = new IFile[] { dotProject, textFile, textFile2 };
    }
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    // commit to stable
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
    op.execute(null);
    // now create a stable branch (from master)
    createStableBranch(myRepository);
    // and check in some stuff into master again
    String newContent = "Touched at " + System.currentTimeMillis();
    IFile file = touch(firstProject.getName(), FOLDER + '/' + FILE1, newContent);
    addAndCommit(file, newContent);
    // Make sure cache entry is already listening for changes
    IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
    cache.getIndexDiffCacheEntry(lookupRepository(gitDir));
    return gitDir;
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) Repository(org.eclipse.jgit.lib.Repository) CommitOperation(org.eclipse.egit.core.op.CommitOperation) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class MergeToolTest method useHeadOptionShouldCauseFileToNotHaveConflictMarkers.

@Test
public void useHeadOptionShouldCauseFileToNotHaveConflictMarkers() throws Exception {
    IPath path = new Path(PROJ1).append("folder/test.txt");
    testRepository.branch("stable").commit().add(path.toString(), "stable").create();
    touchAndSubmit("master", "master");
    MergeOperation mergeOp = new MergeOperation(testRepository.getRepository(), "stable");
    mergeOp.execute(null);
    MergeResult mergeResult = mergeOp.getResult();
    assertThat(mergeResult.getMergeStatus(), is(MergeStatus.CONFLICTING));
    assertThat(mergeResult.getConflicts().keySet(), hasItem(path.toString()));
    IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
    cache.getIndexDiffCacheEntry(testRepository.getRepository());
    TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    SWTBotTree packageExplorer = TestUtil.getExplorerTree();
    SWTBotTreeItem project1 = getProjectItem(packageExplorer, PROJ1).select();
    SWTBotTreeItem folderNode = TestUtil.expandAndWait(project1).getNode(FOLDER);
    SWTBotTreeItem fileNode = TestUtil.expandAndWait(folderNode).getNode(FILE1);
    fileNode.select();
    ContextMenuHelper.clickContextMenu(packageExplorer, util.getPluginLocalizedValue("TeamMenu.label"), util.getPluginLocalizedValue("MergeToolAction.label"));
    CompareEditorTester compareEditor = CompareEditorTester.forTitleContaining("Merging");
    String text = compareEditor.getLeftEditor().getText();
    assertThat(text, is("master"));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) MergeOperation(org.eclipse.egit.core.op.MergeOperation) IPath(org.eclipse.core.runtime.IPath) CompareEditorTester(org.eclipse.egit.ui.common.CompareEditorTester) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) MergeResult(org.eclipse.jgit.api.MergeResult) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) Test(org.junit.Test)

Aggregations

IndexDiffCache (org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)17 IndexDiffCacheEntry (org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)8 Repository (org.eclipse.jgit.lib.Repository)8 File (java.io.File)5 Collection (java.util.Collection)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IProject (org.eclipse.core.resources.IProject)3 IndexDiffData (org.eclipse.egit.core.internal.indexdiff.IndexDiffData)3 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 IFolder (org.eclipse.core.resources.IFolder)2 IResource (org.eclipse.core.resources.IResource)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 CommitOperation (org.eclipse.egit.core.op.CommitOperation)2 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)2 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)2 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)2 Test (org.junit.Test)2