Search in sources :

Example 1 with RebaseOperation

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

the class RebaseOperationTest method testUpToDate.

@Test
@Ignore
public // currently not working as expected; see also TODO in RebaseCommand
void testUpToDate() 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);
    // checkout topic
    testRepository.checkoutBranch(TOPIC);
    file = project.createFile("theSecondFile.txt", "Hello, world".getBytes("UTF-8"));
    // topic commit: add second file
    RevCommit topicCommit = testRepository.addAndCommit(project.project, new File(file.getLocationURI()), "Adding theSecondFile.txt");
    // 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.UP_TO_DATE, res.getStatus());
    try (RevWalk rw = new RevWalk(repository)) {
        RevCommit newTopic = rw.parseCommit(repository.resolve(TOPIC));
        assertEquals(topicCommit, newTopic);
        assertEquals(first, newTopic.getParent(0));
    }
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) IFile(org.eclipse.core.resources.IFile) RevWalk(org.eclipse.jgit.revwalk.RevWalk) File(java.io.File) IFile(org.eclipse.core.resources.IFile) RebaseResult(org.eclipse.jgit.api.RebaseResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with RebaseOperation

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

the class RebaseOperationTest method testNoConflict.

@Test
public void testNoConflict() 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);
    file = project.createFile("theSecondFile.txt", "Hello, world".getBytes("UTF-8"));
    // topic commit: add second file
    RevCommit topicCommit = testRepository.addAndCommit(project.project, new File(file.getLocationURI()), "Adding theSecondFile.txt");
    // 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.OK, res.getStatus());
    try (RevWalk rw = new RevWalk(repository)) {
        RevCommit newTopic = rw.parseCommit(repository.resolve(TOPIC));
        assertEquals(second, newTopic.getParent(0));
    }
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) RevWalk(org.eclipse.jgit.revwalk.RevWalk) 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 3 with RebaseOperation

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

the class FeatureRebaseOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    try {
        if (!repository.isFeature()) {
            throw new WrongGitFlowStateException(CoreText.FeatureRebaseOperation_notOnAFeatureBranch);
        }
        Repository jgitRepo = repository.getRepository();
        Ref develop = jgitRepo.exactRef(repository.getConfig().getDevelopFull());
        RebaseOperation op = new RebaseOperation(jgitRepo, develop);
        op.execute(monitor);
        operationResult = op.getResult();
    } catch (WrongGitFlowStateException | IOException e) {
        throw new CoreException(error(e.getMessage(), e));
    }
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) CoreException(org.eclipse.core.runtime.CoreException) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) IOException(java.io.IOException)

Example 4 with RebaseOperation

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

the class RebaseCurrentRefCommand method createRebaseOperation.

@Override
protected RebaseOperation createRebaseOperation(Repository repository) throws ExecutionException {
    if (LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
        return null;
    }
    InteractiveHandler handler = interactive ? RebaseInteractiveHandler.INSTANCE : null;
    RebaseOperation operation = new RebaseOperation(repository, ref, handler);
    operation.setPreserveMerges(preserveMerges);
    return operation;
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) RebaseInteractiveHandler(org.eclipse.egit.ui.internal.rebase.RebaseInteractiveHandler) InteractiveHandler(org.eclipse.jgit.api.RebaseCommand.InteractiveHandler)

Example 5 with RebaseOperation

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

the class RebaseOperationTest method testExceptionWhenRestartingStoppedRebase.

@Test
public void testExceptionWhenRestartingStoppedRebase() 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(repository, repository.exactRef(MASTER));
    op.execute(null);
    RebaseResult res = op.getResult();
    assertEquals(RebaseResult.Status.STOPPED, res.getStatus());
    try {
        // let's try to start again, we should get a wrapped
        // WrongRepositoryStateException
        op = new RebaseOperation(repository, repository.exactRef(MASTER));
        op.execute(null);
        fail("Expected Exception not thrown");
    } catch (CoreException e) {
        Throwable cause = e.getCause();
        assertTrue(cause instanceof WrongRepositoryStateException);
    }
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) 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)

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