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();
}
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);
}
Aggregations