Search in sources :

Example 6 with MergeResult

use of org.eclipse.che.api.git.shared.MergeResult in project che by eclipse.

the class MergeResultWriter method writeTo.

/**
     * @see MessageBodyWriter#writeTo(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType,
     *      javax.ws.rs.core.MultivaluedMap, java.io.OutputStream)
     */
@Override
public void writeTo(MergeResult mergeResult, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    Writer writer = new OutputStreamWriter(entityStream);
    MergeResult.MergeStatus status = mergeResult.getMergeStatus();
    switch(mergeResult.getMergeStatus()) {
        case FAST_FORWARD:
        case ALREADY_UP_TO_DATE:
        case MERGED:
            writer.write(status.toString());
            writer.write('\n');
            break;
        case FAILED:
            writer.write("error: Failed to merge:");
            for (String failed : mergeResult.getFailed()) {
                writer.write("        ");
                writer.write(failed);
                writer.write('\n');
            }
            break;
        case CONFLICTING:
            for (String conflict : mergeResult.getConflicts()) {
                writer.write("CONFLICT(content): Merge conflict in: " + conflict);
                writer.write('\n');
            }
            writer.write("Automatic merge failed; fix conflicts and then commit the result");
            writer.write('\n');
            break;
        case NOT_SUPPORTED:
            writer.write("Operation not supported");
            writer.write('\n');
            break;
        default:
            break;
    }
    writer.flush();
}
Also used : MergeResult(org.eclipse.che.api.git.shared.MergeResult) OutputStreamWriter(java.io.OutputStreamWriter) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 7 with MergeResult

use of org.eclipse.che.api.git.shared.MergeResult in project che by eclipse.

the class MergeTest method testMergeConflict.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testMergeConflict(GitConnectionFactory connectionFactory) throws Exception {
    //given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    connection.checkout(CheckoutParams.create(branchName).withCreateNew(true));
    addFile(connection, "t-merge-conflict", "aaa\n");
    connection.add(AddParams.create(new ArrayList<>(singletonList("."))));
    connection.commit(CommitParams.create("add file in new branch"));
    connection.checkout(CheckoutParams.create("master"));
    addFile(connection, "t-merge-conflict", "bbb\n");
    connection.add(AddParams.create(new ArrayList<>(singletonList("."))));
    connection.commit(CommitParams.create("add file in new branch"));
    //when
    MergeResult mergeResult = connection.merge(branchName);
    //then
    List<String> conflicts = mergeResult.getConflicts();
    assertEquals(conflicts.size(), 1);
    assertEquals(conflicts.get(0), "t-merge-conflict");
    assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.CONFLICTING);
    String expContent = //
    "<<<<<<< HEAD\n" + //
    "bbb\n" + //
    "=======\n" + //
    "aaa\n" + ">>>>>>> MergeTestBranch\n";
    String actual = Files.toString(new File(connection.getWorkingDir(), "t-merge-conflict"), Charsets.UTF_8);
    assertEquals(actual, expContent);
}
Also used : ArrayList(java.util.ArrayList) MergeResult(org.eclipse.che.api.git.shared.MergeResult) GitConnection(org.eclipse.che.api.git.GitConnection) File(java.io.File) GitTestUtil.addFile(org.eclipse.che.git.impl.GitTestUtil.addFile) Test(org.testng.annotations.Test)

Aggregations

MergeResult (org.eclipse.che.api.git.shared.MergeResult)7 ArrayList (java.util.ArrayList)3 GitConnection (org.eclipse.che.api.git.GitConnection)3 Test (org.testng.annotations.Test)3 File (java.io.File)2 GitTestUtil.addFile (org.eclipse.che.git.impl.GitTestUtil.addFile)2 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)1 GitException (org.eclipse.che.api.git.exception.GitException)1 MergeRequest (org.eclipse.che.api.git.shared.MergeRequest)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)1 ServerException (org.eclipse.che.ide.commons.exception.ServerException)1 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)1 CheckoutConflictException (org.eclipse.jgit.api.errors.CheckoutConflictException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1