Search in sources :

Example 16 with MergeResult

use of org.eclipse.jgit.api.MergeResult in project egit by eclipse.

the class DecoratableResourceMappingTest method testDecorationConflictingOverDirty.

/**
 * Tests that if the resource mapping is both conflicting and dirty, that
 * the conflicting decoration image is used over the dirty decoration image.
 *
 * @throws Exception
 */
@Test
public void testDecorationConflictingOverDirty() throws Exception {
    // commit changes on master
    gitAdd(git, rmContentA);
    gitAdd(git, rmContentB);
    RevCommit masterCommit = gitCommit(git);
    // add change on new branch first_topic
    git.checkout().setCreateBranch(true).setName("first_topic").call();
    rmContentA = findFile(project, RM_CONTENT_A_FILE_NAME);
    write(rmContentA.getLocation().toFile(), "First Topic Content");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    gitAdd(git, rmContentA);
    RevCommit firstTopicCommit = gitCommit(git);
    // add change on new branch second_topic
    git.checkout().setCreateBranch(true).setStartPoint(masterCommit).setName("second_topic").call();
    rmContentA = findFile(project, RM_CONTENT_A_FILE_NAME);
    write(rmContentA.getLocation().toFile(), "Second Topic Content");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    gitAdd(git, rmContentA);
    gitCommit(git);
    // modify b to make it dirty
    write(rmContentB.getLocation().toFile(), "Changed content");
    // merge second_topic with first_topic
    MergeResult mergeResult = git.merge().include(firstTopicCommit).call();
    assertEquals(MergeStatus.CONFLICTING, mergeResult.getMergeStatus());
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { newExpectedDecoratableResource(rmContentA).tracked().conflicts(), newExpectedDecoratableResource(rmContentB).tracked().dirty(), newExpectedDecoratableResourceMapping().tracked().dirty().conflicts() };
    IndexDiffData indexDiffData = waitForIndexDiff(true);
    IDecoratableResource[] actualDRs = { newDecoratableResource(indexDiffData, rmContentA), newDecoratableResource(indexDiffData, rmContentB), newDecoratableResourceMapping(resourceMapping) };
    assertArrayEquals(expectedDRs, actualDRs);
    assertDecorationConflicts(resourceMapping);
}
Also used : MergeResult(org.eclipse.jgit.api.MergeResult) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 17 with MergeResult

use of org.eclipse.jgit.api.MergeResult in project egit by eclipse.

the class DecoratableWorkingSetTest method testDecorationConflictingOverDirty.

@Test
public void testDecorationConflictingOverDirty() throws Exception {
    // Create new file and commit
    IFile file = createFile(project1, TEST_FILE, "Something");
    IFile file2 = createFile(project1, TEST_FILE2, "Another Something");
    gitAdd(git, file);
    gitAdd(git, file2);
    RevCommit masterCommit = gitCommit(git);
    // Create and checkout new branch, change file content, add and commit
    // file
    git.checkout().setCreateBranch(true).setName("first_topic").call();
    file = findFile(project1, TEST_FILE);
    write(file.getLocation().toFile(), "First Topic Content");
    project1.refreshLocal(IResource.DEPTH_INFINITE, null);
    gitAdd(git, file);
    RevCommit firstTopicCommit = gitCommit(git);
    // Create and checkout new branch (from master), change file content,
    // add and commit file
    git.checkout().setCreateBranch(true).setStartPoint(masterCommit).setName("second_topic").call();
    file = findFile(project1, TEST_FILE);
    write(file.getLocation().toFile(), "Second Topic Content");
    project1.refreshLocal(IResource.DEPTH_INFINITE, null);
    gitAdd(git, file);
    gitCommit(git);
    // modify file2 to make it dirty
    write(file2.getLocation().toFile(), "Changed content");
    // merge second_topic with first_topic
    MergeResult mergeResult = git.merge().include(firstTopicCommit).call();
    assertEquals(MergeStatus.CONFLICTING, mergeResult.getMergeStatus());
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { newExpectedDecoratableResource(project1).tracked().dirty().conflicts(), newExpectedDecoratableResource(file).tracked().conflicts(), newExpectedDecoratableResource(file2).tracked().dirty(), newExpectedDecoratableWorkingSet(WORKING_SET).tracked().dirty().conflicts() };
    IndexDiffData indexDiffData = waitForIndexDiff(true);
    IDecoratableResource[] actualDRs = { newDecoratableResource(indexDiffData, project1), newDecoratableResource(indexDiffData, file), newDecoratableResource(indexDiffData, file2), newDecoratableWorkingSet(resourceMapping) };
    assertArrayEquals(expectedDRs, actualDRs);
    assertHasUnstagedChanges(true, actualDRs);
    assertDecorationConflicts(resourceMapping);
}
Also used : IFile(org.eclipse.core.resources.IFile) MergeResult(org.eclipse.jgit.api.MergeResult) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 18 with MergeResult

use of org.eclipse.jgit.api.MergeResult 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)

Example 19 with MergeResult

use of org.eclipse.jgit.api.MergeResult in project egit by eclipse.

the class ReleaseFinishHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
    if (gfRepo == null) {
        return error(UIText.Handlers_noGitflowRepositoryFound);
    }
    final ReleaseFinishOperation releaseFinishOperation;
    try {
        releaseFinishOperation = new ReleaseFinishOperation(gfRepo);
        String releaseBranch = gfRepo.getRepository().getBranch();
        String develop = gfRepo.getConfig().getDevelop();
        JobUtil.scheduleUserWorkspaceJob(releaseFinishOperation, UIText.ReleaseFinishHandler_finishingRelease, JobFamilies.GITFLOW_FAMILY);
        IJobManager jobMan = Job.getJobManager();
        jobMan.join(JobFamilies.GITFLOW_FAMILY, null);
        MergeResult mergeResult = releaseFinishOperation.getMergeResult();
        MergeStatus mergeStatus = mergeResult.getMergeStatus();
        if (!MergeStatus.CONFLICTING.equals(mergeStatus)) {
            return null;
        }
        if (handleConflictsOnMaster(gfRepo)) {
            return null;
        }
        MultiStatus status = createMergeConflictInfo(develop, releaseBranch, mergeResult);
        ErrorDialog.openError(null, UIText.ReleaseFinishHandler_Conflicts, null, status);
    } catch (WrongGitFlowStateException | CoreException | IOException | OperationCanceledException | InterruptedException e) {
        return error(e.getMessage(), e);
    }
    return null;
}
Also used : ReleaseFinishOperation(org.eclipse.egit.gitflow.op.ReleaseFinishOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) MergeResult(org.eclipse.jgit.api.MergeResult) MultiStatus(org.eclipse.core.runtime.MultiStatus) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) MergeStatus(org.eclipse.jgit.api.MergeResult.MergeStatus) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository)

Example 20 with MergeResult

use of org.eclipse.jgit.api.MergeResult in project fuse-karaf by jboss-fuse.

the class GitConflictResolutionIT method mergeConflict.

@Test
public void mergeConflict() throws Exception {
    prepareChanges();
    RevWalk rw = new RevWalk(git.getRepository());
    git.checkout().setName("custom").setCreateBranch(false).call();
    MergeResult result = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(git.getRepository().resolve("patched")).call();
    assertThat(result.getMergeStatus(), equalTo(MergeResult.MergeStatus.CONFLICTING));
    assertThat(result.getConflicts().size(), equalTo(1));
    Map<String, IndexDiff.StageState> conflicts = git.status().call().getConflictingStageState();
    assertThat(conflicts.size(), equalTo(1));
    assertThat(conflicts.get("etc/org.ops4j.pax.logging.cfg"), equalTo(IndexDiff.StageState.BOTH_MODIFIED));
}
Also used : MergeResult(org.eclipse.jgit.api.MergeResult) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Test(org.junit.Test)

Aggregations

MergeResult (org.eclipse.jgit.api.MergeResult)22 IOException (java.io.IOException)10 Test (org.junit.Test)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)7 Git (org.eclipse.jgit.api.Git)6 CoreException (org.eclipse.core.runtime.CoreException)4 IndexDiffData (org.eclipse.egit.core.internal.indexdiff.IndexDiffData)4 MergeCommand (org.eclipse.jgit.api.MergeCommand)3 MergeStatus (org.eclipse.jgit.api.MergeResult.MergeStatus)3 Ref (org.eclipse.jgit.lib.Ref)3 File (java.io.File)2 IFile (org.eclipse.core.resources.IFile)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 CheckoutCommand (org.eclipse.jgit.api.CheckoutCommand)2 CloneCommand (org.eclipse.jgit.api.CloneCommand)2 NoRemoteRepositoryException (org.eclipse.jgit.errors.NoRemoteRepositoryException)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Repository (org.eclipse.jgit.lib.Repository)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2