List of usage examples for org.eclipse.jgit.api Git pull
public PullCommand pull()
From source file:org.kie.workbench.common.services.backend.compiler.DefaultMavenCompilerTest.java
License:Apache License
@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>() { {// ww w. j a v a2s . c om 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(); assertThat(pullRes.getRebaseResult().getStatus()).isEqualTo(RebaseResult.Status.UP_TO_DATE);// nothing changed yet 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()); }
From source file:org.kie.workbench.common.services.backend.compiler.impl.JGitUtils.java
License:Apache License
public static Boolean applyBefore(final Git git) { Boolean result = Boolean.FALSE; try {// w w w . j a v a 2 s. co m PullCommand pc = git.pull().setRemote(REMOTE).setRebase(Boolean.TRUE); PullResult pullRes = pc.call(); RebaseResult rr = pullRes.getRebaseResult(); if (rr.getStatus().equals(RebaseResult.Status.UP_TO_DATE) || rr.getStatus().equals(RebaseResult.Status.FAST_FORWARD)) { result = Boolean.TRUE; } if (rr.getStatus().equals(RebaseResult.Status.UNCOMMITTED_CHANGES)) { PullResult pr = git.pull().call(); if (pr.isSuccessful()) { result = Boolean.TRUE; } else { result = Boolean.FALSE; } } } catch (Exception e) { logger.error(e.getMessage()); } return result; }
From source file:org.kie.workbench.common.services.backend.compiler.impl.utils.JGitUtils.java
License:Apache License
public static Boolean pullAndRebase(final Git git) { Boolean result = Boolean.FALSE; try {/* w ww. ja v a 2 s.c o m*/ git.reset().setMode(ResetCommand.ResetType.HARD).call(); final RebaseResult rr = git.pull().setRemote(REMOTE).setRebase(Boolean.TRUE).call().getRebaseResult(); if (rr.getStatus().equals(RebaseResult.Status.UP_TO_DATE) || rr.getStatus().equals(RebaseResult.Status.FAST_FORWARD)) { result = Boolean.TRUE; } if (rr.getStatus().equals(RebaseResult.Status.UNCOMMITTED_CHANGES)) { PullResult pr = git.pull().call(); if (pr.isSuccessful()) { result = Boolean.TRUE; } else { result = Boolean.FALSE; } } } catch (Exception e) { logger.error(e.getMessage()); } return result; }
From source file:org.kie.workbench.common.services.backend.compiler.kie.KieDefaultMavenCompilerTest.java
License:Apache License
@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>() { {// w w w.j a va 2 s .c o m 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(); assertThat(pullRes.getRebaseResult().getStatus()).isEqualTo(RebaseResult.Status.UP_TO_DATE);// nothing changed yet 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()); }
From source file:org.kie.workbench.common.services.backend.compiler.nio.DefaultMavenCompilerTest.java
License:Apache License
@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>() { {//from w w w .j av a 2 s .c o m put("init", Boolean.TRUE); put("internal", Boolean.TRUE); put("listMode", "ALL"); } }); ioService.startBatch(origin); ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files .readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath()))); ioService.write(origin.getPath("/dummy/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("/dummy/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("/dummy/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("/dummy/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("git://localhost:9418/repo").setBare(false) .setDirectory(tmpCloned.toFile()).call(); assertNotNull(cloned); PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE); PullResult pullRes = pc.call(); assertTrue(pullRes.getRebaseResult().getStatus().equals(RebaseResult.Status.UP_TO_DATE));// nothing changed yet RebaseCommand rb = cloned.rebase().setUpstream("origin/master"); RebaseResult rbResult = rb.setPreserveMerges(true).call(); assertTrue(rbResult.getStatus().isSuccessful()); //Compile the repo AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.LOG_OUTPUT_AFTER); byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/dummy/pom.xml")); String pomAsAstring = new String(encoded, StandardCharsets.UTF_8); Assert.assertFalse(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>")); Path prjFolder = Paths.get(tmpCloned + "/dummy/"); WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder); CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.TRUE); CompilationResponse res = compiler.compileSync(req); if (res.getMavenOutput().isPresent() && !res.isSuccessful()) { TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithPullRebaseUberfireTest"); } assertTrue(res.isSuccessful()); Path incrementalConfiguration = Paths.get( prjFolder + "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile"); assertTrue(incrementalConfiguration.toFile().exists()); encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml")); pomAsAstring = new String(encoded, StandardCharsets.UTF_8); assertTrue(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>")); TestUtil.rm(tmpRootCloned.toFile()); }
From source file:org.kie.workbench.common.services.backend.compiler.nio.kie.KieDefaultMavenCompilerTest.java
License:Apache License
@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>() { {/* w w w . j a va 2 s. co m*/ put("init", Boolean.TRUE); put("internal", Boolean.TRUE); put("listMode", "ALL"); } }); ioService.startBatch(origin); ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files .readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath()))); ioService.write(origin.getPath("/dummy/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("/dummy/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("/dummy/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("/dummy/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("git://localhost:9418/repo").setBare(false) .setDirectory(tmpCloned.toFile()).call(); assertNotNull(cloned); PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE); PullResult pullRes = pc.call(); assertTrue(pullRes.getRebaseResult().getStatus().equals(RebaseResult.Status.UP_TO_DATE));// nothing changed yet RebaseCommand rb = cloned.rebase().setUpstream("origin/master"); RebaseResult rbResult = rb.setPreserveMerges(true).call(); assertTrue(rbResult.getStatus().isSuccessful()); //Compile the repo AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.LOG_OUTPUT_AFTER); byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/dummy/pom.xml")); String pomAsAstring = new String(encoded, StandardCharsets.UTF_8); Assert.assertFalse(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>")); Path prjFolder = Paths.get(tmpCloned + "/dummy/"); WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder); CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.TRUE); CompilationResponse res = compiler.compileSync(req); if (res.getMavenOutput().isPresent() && !res.isSuccessful()) { TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerTest.buildWithPullRebaseUberfireTest"); } assertTrue(res.isSuccessful()); Path incrementalConfiguration = Paths.get( prjFolder + "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile"); assertTrue(incrementalConfiguration.toFile().exists()); encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml")); pomAsAstring = new String(encoded, StandardCharsets.UTF_8); assertTrue(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>")); TestUtil.rm(tmpRootCloned.toFile()); }
From source file:org.ms123.common.git.GitServiceImpl.java
License:Open Source License
public void pull(@PName("name") String name) throws RpcException { try {/*from ww w . j av a 2 s . com*/ String gitSpace = System.getProperty("git.repos"); File dir = new File(gitSpace, name); if (!dir.exists()) { throw new RpcException(ERROR_FROM_METHOD, 100, "GitService.pull:Repo(" + name + ") not exists"); } Git git = Git.open(dir); PullCommand pull = git.pull(); PullResult result = pull.call(); debug(result.toString()); return; } catch (Exception e) { throw new RpcException(ERROR_FROM_METHOD, INTERNAL_SERVER_ERROR, "GitService.pull:", e); } finally { } }
From source file:org.mule.module.git.GitConnector.java
License:Open Source License
/** * Fetch from and merge with another repository or a local branch * * {@sample.xml ../../../doc/mule-module-git.xml.sample git:pull} * * @param overrideDirectory Name of the directory to use for git repository *//*from w ww . j a v a 2 s . c om*/ @Processor public void pull(@Optional String overrideDirectory) { try { Git git = new Git(getGitRepo(overrideDirectory)); PullCommand pull = git.pull(); pull.call(); } catch (Exception e) { throw new RuntimeException("Unable to pull", e); } }
From source file:org.n52.wps.repository.git.GitAlgorithmRepository.java
License:Open Source License
private Collection<DiffEntry> updateLocalRepository(ObjectId old) throws UpdateGitAlgorithmsRepositoryException { try {//from ww w . ja v a 2 s .co m Git git = new Git(localRepo); logger.debug("Starting pulling from {} ({})", remotePath, old); PullResult result = git.pull().call(); if (!result.isSuccessful()) { printMergeSummary(result); rollbackFromFailedMerge(git, old); return Collections.emptyList(); } logger.info("Successfully pulled changes."); ObjectId current = currentHeadToObjectId(); return getDiffEntries(git, old, current); } catch (IOException | GitAPIException e) { throw new UpdateGitAlgorithmsRepositoryException("Failed to pull from " + remotePath, e); } }
From source file:org.onexus.resource.manager.internal.providers.GitProjectProvider.java
License:Apache License
@Override protected void importProject() { try {//from ww w . jav a2s. c o m File projectFolder = getProjectFolder(); boolean cloneDone = true; if (!projectFolder.exists()) { projectFolder.mkdir(); cloneDone = false; } FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setWorkTree(projectFolder).readEnvironment().build(); Git git = new Git(repository); if (cloneDone) { PullCommand pull = git.pull(); pull.call(); } else { CloneCommand clone = git.cloneRepository(); clone.setBare(false); clone.setCloneAllBranches(true); clone.setDirectory(projectFolder).setURI(getProjectUrl().toString()); clone.call(); //TODO Checkout branch } } catch (Exception e) { LOGGER.error("Importing project '" + getProjectUrl() + "'", e); throw new InvalidParameterException("Error importing project. " + e.getMessage()); } }