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