Search in sources :

Example 1 with MergeOperation

use of org.eclipse.egit.core.op.MergeOperation in project egit by eclipse.

the class MergeHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ObjectId commitId = getSelectedCommitId(event);
    Repository repository = getRepository(event);
    if (repository == null) {
        return null;
    }
    Shell shell = HandlerUtil.getActiveShellChecked(event);
    if (!MergeActionHandler.checkMergeIsPossible(repository, shell) || LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
        return null;
    }
    List<Ref> nodes;
    try {
        nodes = getBranchesOfCommit(getSelection(event), repository, true);
    } catch (IOException e) {
        throw new ExecutionException(UIText.AbstractHistoryCommitHandler_cantGetBranches, e);
    }
    String refName;
    if (nodes.isEmpty()) {
        refName = commitId.getName();
    } else if (nodes.size() == 1) {
        refName = nodes.get(0).getName();
    } else {
        BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(shell, nodes, UIText.MergeHandler_SelectBranchTitle, UIText.MergeHandler_SelectBranchMessage, SWT.SINGLE);
        if (dlg.open() == Window.OK) {
            refName = dlg.getSelectedNode().getName();
        } else {
            return null;
        }
    }
    MergeOperation op = new MergeOperation(repository, refName);
    MergeActionHandler.doMerge(repository, op, refName);
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) Ref(org.eclipse.jgit.lib.Ref) MergeOperation(org.eclipse.egit.core.op.MergeOperation) ObjectId(org.eclipse.jgit.lib.ObjectId) BranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with MergeOperation

use of org.eclipse.egit.core.op.MergeOperation in project egit by eclipse.

the class MergeOperationTest method testMergeFFOnly.

@Test
public void testMergeFFOnly() throws Exception {
    setMerge(FastForwardMode.FF_ONLY);
    File file2 = testRepository.createFile(project.getProject(), "file2");
    testRepository.appendFileContent(file2, "file2-1");
    RevCommit commit = testRepository.addAndCommit(project.getProject(), file2, "side commit 1");
    MergeOperation operation = new MergeOperation(testRepository.getRepository(), MASTER);
    operation.execute(new NullProgressMonitor());
    assertTrue(testRepository.getRepository().resolve(SIDE).equals(commit));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MergeOperation(org.eclipse.egit.core.op.MergeOperation) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with MergeOperation

use of org.eclipse.egit.core.op.MergeOperation in project egit by eclipse.

the class MergeOperationTest method testMergeFF.

@Test
public void testMergeFF() throws Exception {
    MergeOperation operation = new MergeOperation(testRepository.getRepository(), MASTER);
    operation.execute(new NullProgressMonitor());
    assertTrue(testRepository.getRepository().resolve(SIDE).equals(secondCommit));
    assertEquals(2, countCommitsInHead());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MergeOperation(org.eclipse.egit.core.op.MergeOperation) Test(org.junit.Test)

Example 4 with MergeOperation

use of org.eclipse.egit.core.op.MergeOperation in project egit by eclipse.

the class MergeOperationTest method testMergeNoFF.

@Test
public void testMergeNoFF() throws Exception {
    setMerge(FastForwardMode.NO_FF);
    MergeOperation operation = new MergeOperation(testRepository.getRepository(), MASTER);
    operation.execute(new NullProgressMonitor());
    assertEquals(3, countCommitsInHead());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MergeOperation(org.eclipse.egit.core.op.MergeOperation) Test(org.junit.Test)

Example 5 with MergeOperation

use of org.eclipse.egit.core.op.MergeOperation in project egit by eclipse.

the class MergeWithPreferredStrategyTest method testStrategyCanBeOverridden.

@Test
public void testStrategyCanBeOverridden() throws Exception {
    MergeOperation operation = new MergeOperation(testRepository.getRepository(), SIDE, "recursive");
    operation.execute(new NullProgressMonitor());
    // With the MergeStrategy RECURSIVE, new files from branch 'master' and
    // 'side' should be present
    assertEquals(4, countCommitsInHead());
    assertTrue(testRepository.getIFile(project.getProject(), file2).exists());
    assertTrue(testRepository.getIFile(project.getProject(), file3).exists());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MergeOperation(org.eclipse.egit.core.op.MergeOperation) Test(org.junit.Test)

Aggregations

MergeOperation (org.eclipse.egit.core.op.MergeOperation)14 Test (org.junit.Test)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IOException (java.io.IOException)3 Repository (org.eclipse.jgit.lib.Repository)3 Shell (org.eclipse.swt.widgets.Shell)3 File (java.io.File)2 CoreException (org.eclipse.core.runtime.CoreException)2 MergeTargetSelectionDialog (org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog)2 MergeResult (org.eclipse.jgit.api.MergeResult)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1