Search in sources :

Example 1 with RebaseResult

use of org.eclipse.jgit.api.RebaseResult in project che by eclipse.

the class JGitConnection method rebase.

@Override
public RebaseResponse rebase(String operation, String branch) throws GitException {
    RebaseResult result;
    RebaseStatus status;
    List<String> failed;
    List<String> conflicts;
    try {
        RebaseCommand rebaseCommand = getGit().rebase();
        setRebaseOperation(rebaseCommand, operation);
        if (branch != null && !branch.isEmpty()) {
            rebaseCommand.setUpstream(branch);
        }
        result = rebaseCommand.call();
    } catch (GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
    switch(result.getStatus()) {
        case ABORTED:
            status = RebaseStatus.ABORTED;
            break;
        case CONFLICTS:
            status = RebaseStatus.CONFLICTING;
            break;
        case UP_TO_DATE:
            status = RebaseStatus.ALREADY_UP_TO_DATE;
            break;
        case FAST_FORWARD:
            status = RebaseStatus.FAST_FORWARD;
            break;
        case NOTHING_TO_COMMIT:
            status = RebaseStatus.NOTHING_TO_COMMIT;
            break;
        case OK:
            status = RebaseStatus.OK;
            break;
        case STOPPED:
            status = RebaseStatus.STOPPED;
            break;
        case UNCOMMITTED_CHANGES:
            status = RebaseStatus.UNCOMMITTED_CHANGES;
            break;
        case EDIT:
            status = RebaseStatus.EDITED;
            break;
        case INTERACTIVE_PREPARED:
            status = RebaseStatus.INTERACTIVE_PREPARED;
            break;
        case STASH_APPLY_CONFLICTS:
            status = RebaseStatus.STASH_APPLY_CONFLICTS;
            break;
        default:
            status = RebaseStatus.FAILED;
    }
    conflicts = result.getConflicts() != null ? result.getConflicts() : Collections.emptyList();
    failed = result.getFailingPaths() != null ? new ArrayList<>(result.getFailingPaths().keySet()) : Collections.emptyList();
    return newDto(RebaseResponse.class).withStatus(status).withConflicts(conflicts).withFailed(failed);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RebaseResponse(org.eclipse.che.api.git.shared.RebaseResponse) RebaseCommand(org.eclipse.jgit.api.RebaseCommand) GitException(org.eclipse.che.api.git.exception.GitException) ArrayList(java.util.ArrayList) RebaseStatus(org.eclipse.che.api.git.shared.RebaseResponse.RebaseStatus) RebaseResult(org.eclipse.jgit.api.RebaseResult)

Example 2 with RebaseResult

use of org.eclipse.jgit.api.RebaseResult 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 3 with RebaseResult

use of org.eclipse.jgit.api.RebaseResult 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 4 with RebaseResult

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

the class FeatureRebaseHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
    FeatureRebaseOperation rebaseOperation = new FeatureRebaseOperation(gfRepo);
    JobUtil.scheduleUserWorkspaceJob(rebaseOperation, UIText.FeatureRebaseHandler_rebasingFeature, JobFamilies.GITFLOW_FAMILY);
    IJobManager jobMan = Job.getJobManager();
    try {
        jobMan.join(GITFLOW_FAMILY, null);
    } catch (OperationCanceledException | InterruptedException e) {
        return error(e.getMessage(), e);
    }
    RebaseResult operationResult = rebaseOperation.getOperationResult();
    RebaseResult.Status status = operationResult.getStatus();
    if (status.isSuccessful()) {
        return null;
    }
    if (STOPPED.equals(status)) {
        try {
            showInteractiveRebaseView(event);
        } catch (PartInitException e) {
            return error(e.getMessage(), e);
        }
    }
    openWarning(operationResult);
    return null;
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) PartInitException(org.eclipse.ui.PartInitException) FeatureRebaseOperation(org.eclipse.egit.gitflow.op.FeatureRebaseOperation) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) RebaseResult(org.eclipse.jgit.api.RebaseResult)

Example 5 with RebaseResult

use of org.eclipse.jgit.api.RebaseResult in project kie-wb-common by kiegroup.

the class KieDefaultMavenCompilerTest method buildWithPullRebaseUberfireTest.

@Test
public void buildWithPullRebaseUberfireTest() throws Exception {
    // Setup origin in memory
    final URI originRepo = URI.create("git://repo");
    final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo, new HashMap<String, Object>() {

        {
            put("init", Boolean.TRUE);
            put("internal", Boolean.TRUE);
            put("listMode", "ALL");
        }
    });
    ioService.startBatch(origin);
    ioService.write(origin.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
    ioService.write(origin.getPath("/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
    ioService.write(origin.getPath("/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
    ioService.endBatch();
    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone"));
    final Git cloned = Git.cloneRepository().setURI(origin.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(tmpCloned.toFile()).call();
    assertThat(cloned).isNotNull();
    PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
    PullResult pullRes = pc.call();
    // nothing changed yet
    assertThat(pullRes.getRebaseResult().getStatus()).isEqualTo(RebaseResult.Status.UP_TO_DATE);
    RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
    RebaseResult rbResult = rb.setPreserveMerges(true).call();
    assertThat(rbResult.getStatus().isSuccessful()).isTrue();
    // Compile the repo
    byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
    Path prjFolder = Paths.get(tmpCloned + "/");
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    Path incrementalConfiguration = Paths.get(prjFolder + TestConstants.TARGET_TAKARI_PLUGIN);
    assertThat(incrementalConfiguration.toFile()).exists();
    encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).contains(TestConstants.KIE_TAKARI_LIFECYCLE_ARTIFACT);
    TestUtil.rm(tmpRootCloned.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) PullCommand(org.eclipse.jgit.api.PullCommand) HashMap(java.util.HashMap) RebaseCommand(org.eclipse.jgit.api.RebaseCommand) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) URI(java.net.URI) PullResult(org.eclipse.jgit.api.PullResult) TestUtilGit(org.kie.workbench.common.services.backend.compiler.TestUtilGit) Git(org.eclipse.jgit.api.Git) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) File(java.io.File) RebaseResult(org.eclipse.jgit.api.RebaseResult) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) AFCompiler(org.kie.workbench.common.services.backend.compiler.AFCompiler) CompilationRequest(org.kie.workbench.common.services.backend.compiler.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Aggregations

RebaseResult (org.eclipse.jgit.api.RebaseResult)17 Test (org.junit.Test)10 File (java.io.File)9 PullResult (org.eclipse.jgit.api.PullResult)8 HashMap (java.util.HashMap)6 PullCommand (org.eclipse.jgit.api.PullCommand)6 RebaseCommand (org.eclipse.jgit.api.RebaseCommand)6 Git (org.eclipse.jgit.api.Git)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 Path (org.uberfire.java.nio.file.Path)5 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)5 URI (java.net.URI)4 IFile (org.eclipse.core.resources.IFile)4 RebaseOperation (org.eclipse.egit.core.op.RebaseOperation)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Repository (org.eclipse.jgit.lib.Repository)3 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)3 IStatus (org.eclipse.core.runtime.IStatus)2 GitFlowRepository (org.eclipse.egit.gitflow.GitFlowRepository)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2