Search in sources :

Example 6 with RebaseOperation

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

the class RebaseOperationTest method testStopAndAbortOnConflict.

@Test
public void testStopAndAbortOnConflict() throws Exception {
    IFile file = project.createFile("theFile.txt", "Hello, world".getBytes("UTF-8"));
    // first commit in master: add theFile.txt
    RevCommit first = testRepository.addAndCommit(project.project, new File(file.getLocationURI()), "Adding theFile.txt");
    testRepository.createBranch(MASTER, TOPIC);
    file.setContents(new ByteArrayInputStream("master".getBytes("UTF-8")), 0, null);
    // second commit in master: modify theFile.txt
    RevCommit second = git.commit().setAll(true).setMessage("Modify theFile.txt").call();
    assertEquals(first, second.getParent(0));
    // checkout topic
    testRepository.checkoutBranch(TOPIC);
    // set conflicting content in topic
    file.setContents(new ByteArrayInputStream("topic".getBytes("UTF-8")), 0, null);
    // topic commit: add second file
    RevCommit topicCommit = testRepository.addAndCommit(project.project, new File(file.getLocationURI()), "Changing theFile.txt again");
    // parent of topic commit should be first master commit before rebase
    assertEquals(first, topicCommit.getParent(0));
    // rebase topic onto master
    RebaseOperation op = new RebaseOperation(testRepository.getRepository(), testRepository.getRepository().exactRef(MASTER));
    op.execute(null);
    RebaseResult res = op.getResult();
    assertEquals(RebaseResult.Status.STOPPED, res.getStatus());
    // let's try to abort this here
    RebaseOperation abort = new RebaseOperation(repository, Operation.ABORT);
    abort.execute(null);
    RebaseResult abortResult = abort.getResult();
    assertEquals(Status.ABORTED, abortResult.getStatus());
    assertEquals(topicCommit, repository.resolve(Constants.HEAD));
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) IFile(org.eclipse.core.resources.IFile) RebaseResult(org.eclipse.jgit.api.RebaseResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 7 with RebaseOperation

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

the class AbstractRebaseCommandHandler method handleBeginError.

private void handleBeginError(final Repository repository, IStatus result) {
    if (!repository.getRepositoryState().equals(RepositoryState.SAFE)) {
        Throwable t = result.getException();
        try {
            new RebaseOperation(repository, Operation.ABORT).execute(null);
            Activator.showError(t.getMessage(), t);
        } catch (CoreException e1) {
            IStatus childStatus = Activator.createErrorStatus(e1.getMessage(), e1);
            IStatus mStatus = new MultiStatus(Activator.getPluginId(), IStatus.ERROR, new IStatus[] { childStatus }, t.getMessage(), t);
            CoreException mStatusException = new CoreException(mStatus);
            Activator.showError(mStatusException.getMessage(), mStatusException);
        }
    }
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Aggregations

RebaseOperation (org.eclipse.egit.core.op.RebaseOperation)7 File (java.io.File)4 IFile (org.eclipse.core.resources.IFile)4 RebaseResult (org.eclipse.jgit.api.RebaseResult)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CoreException (org.eclipse.core.runtime.CoreException)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 IOException (java.io.IOException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 GitFlowRepository (org.eclipse.egit.gitflow.GitFlowRepository)1 WrongGitFlowStateException (org.eclipse.egit.gitflow.WrongGitFlowStateException)1 RebaseInteractiveHandler (org.eclipse.egit.ui.internal.rebase.RebaseInteractiveHandler)1 InteractiveHandler (org.eclipse.jgit.api.RebaseCommand.InteractiveHandler)1 WrongRepositoryStateException (org.eclipse.jgit.api.errors.WrongRepositoryStateException)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1 Ignore (org.junit.Ignore)1