use of org.eclipse.jgit.api.RebaseResult in project kie-wb-common by kiegroup.
the class PomEditorWithGitTest method testPomEditor.
@Test
public void testPomEditor() throws Exception {
final String repoName = "myrepoxxxx";
HashMap<String, Object> env = new HashMap<>();
env.put("init", Boolean.TRUE);
env.put("internal", Boolean.TRUE);
final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), env);
ioService.startBatch(fs);
ioService.write(fs.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/generic/pom.xml").toPath())));
ioService.endBatch();
Path tmpCloned = Files.createTempDirectory("cloned");
final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");
final Git cloned = Git.cloneRepository().setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(gitClonedFolder).call();
assertNotNull(cloned);
Path pomPath = Paths.get("file://" + gitClonedFolder.toString() + "/pom.xml");
byte[] encoded = Files.readAllBytes(pomPath);
String pomOriginal = new String(encoded, StandardCharsets.UTF_8);
Model model = editor.updatePom(pomPath, cdiWrapper);
assertNotNull(model);
PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
PullResult pullRes = pc.call();
assertEquals(pullRes.getRebaseResult().getStatus(), RebaseResult.Status.UP_TO_DATE);
RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
RebaseResult rbResult = rb.setPreserveMerges(true).call();
assertTrue(rbResult.getStatus().isSuccessful());
pomPath = Paths.get("file://" + gitClonedFolder.toString() + "/pom.xml");
encoded = Files.readAllBytes(pomPath);
String pomUpdated = new String(encoded, StandardCharsets.UTF_8);
assertFalse(pomOriginal.equals(pomUpdated));
}
use of org.eclipse.jgit.api.RebaseResult in project kie-wb-common by kiegroup.
the class DefaultMavenCompilerTest 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
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
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 + "/");
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());
}
use of org.eclipse.jgit.api.RebaseResult 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);
}
}
use of org.eclipse.jgit.api.RebaseResult 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.jgit.api.RebaseResult in project egit by eclipse.
the class FeatureRebaseHandler method openWarning.
private void openWarning(RebaseResult operationResult) {
RebaseResult.Status status = operationResult.getStatus();
String pluginId = Activator.getPluginId();
MultiStatus info = new MultiStatus(pluginId, 1, UIText.FeatureRebaseHandler_problemsOcccurredDuringRebase, null);
info.add(new Status(IStatus.WARNING, pluginId, NLS.bind(UIText.FeatureRebaseHandler_statusWas, status.name())));
if (operationResult.getConflicts() != null && !operationResult.getConflicts().isEmpty()) {
MultiStatus warning = createRebaseConflictWarning(operationResult);
info.addAll(warning);
}
ErrorDialog.openError(null, UIText.FeatureRebaseHandler_problemsOccurred, null, info);
}
Aggregations