List of usage examples for org.eclipse.jgit.api Git commit
public CommitCommand commit()
From source file:org.jboss.forge.addon.git.GitUtilsImpl.java
License:Open Source License
@Override public void commitAll(final Git repo, String message) throws GitAPIException { repo.commit().setMessage(message).setAll(true).call(); }
From source file:org.jboss.forge.git.GitUtils.java
License:Open Source License
public static void commit(final Git repo, String message) throws GitAPIException { repo.commit().setMessage(message).call(); }
From source file:org.jboss.forge.git.GitUtils.java
License:Open Source License
public static void commitAll(final Git repo, String message) throws GitAPIException { repo.commit().setMessage(message).setAll(true).call(); }
From source file:org.jboss.forge.rest.main.GitCommandCompletePostProcessor.java
License:Apache License
protected RevCommit doCommitAndPush(Git git, String message, CredentialsProvider credentials, PersonIdent author, String remote, String branch) throws IOException, GitAPIException { CommitCommand commit = git.commit().setAll(true).setMessage(message); if (author != null) { commit = commit.setAuthor(author); }/*www . j av a 2 s .c om*/ RevCommit answer = commit.call(); if (LOG.isDebugEnabled()) { LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage()); } if (isPushOnCommit()) { Iterable<PushResult> results = git.push().setCredentialsProvider(credentials).setRemote(remote).call(); for (PushResult result : results) { if (LOG.isDebugEnabled()) { LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + GitHelpers.toString(result.getRemoteUpdates())); } } } return answer; }
From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java
License:Open Source License
/** * Commits the current index/*from w w w . jav a 2 s . co m*/ * * @param message * commit message * @return commit object * * @throws UnmergedPathException * @throws JGitInternalException * @throws GitAPIException * @throws UnmergedPathsException */ public RevCommit commit(String message) throws UnmergedPathException, JGitInternalException, UnmergedPathsException, GitAPIException { Git git = new Git(repository); CommitCommand commitCommand = git.commit(); commitCommand.setAuthor("J. Git", "j.git@egit.org"); commitCommand.setCommitter(commitCommand.getAuthor()); commitCommand.setMessage(message); return commitCommand.call(); }
From source file:org.jboss.tools.openshift.ui.bot.test.application.v3.adapter.ImportApplicationWizardGitTest.java
License:Open Source License
private void performCommit(Git repo) { try {//from www. j a v a 2 s . co m File commitFile = new File(projectFolder, "commitFile.txt"); boolean fileCreated = commitFile.createNewFile(); assertTrue("Failed to create commit file!", fileCreated); repo.add().addFilepattern(".").call(); repo.commit().setMessage("Init commit. Required for master creation.").call(); } catch (IOException | GitAPIException e) { e.printStackTrace(); fail(); } }
From source file:org.jenkinsci.git.GitHelper.java
License:Open Source License
/** * Add files to test repository/*ww w .jav a2s . c om*/ * * @param repo * @param paths * @param contents * @param message * @return commit * @throws Exception */ public RevCommit add(File repo, List<String> paths, List<String> contents, String message) throws Exception { Git git = Git.open(repo); for (int i = 0; i < paths.size(); i++) { String path = paths.get(i); String content = contents.get(i); File file = new File(repo.getParentFile(), path); if (!file.getParentFile().exists()) assertTrue(file.getParentFile().mkdirs()); if (!file.exists()) assertTrue(file.createNewFile()); PrintWriter writer = new PrintWriter(file); if (content == null) content = ""; try { writer.print(content); } finally { writer.close(); } git.add().addFilepattern(path).call(); } RevCommit commit = git.commit().setMessage(message).setAuthor(author).setCommitter(committer).call(); assertNotNull(commit); return commit; }
From source file:org.kaazing.bower.dependency.maven.plugin.UploadBowerArtifactMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password); File repoDir = new File(outputDir); Git repo = checkoutGitRepo(repoDir, gitBowerUrl, credentialsProvider); if (preserveFiles == null || preserveFiles.isEmpty()) { preserveFiles = new ArrayList<String>(); preserveFiles.add("README.md"); preserveFiles.add("bower.json"); preserveFiles.add("package.json"); preserveFiles.add(".git"); }/*from ww w . j a v a 2s .c om*/ for (File file : repoDir.listFiles()) { if (!preserveFiles.contains(file.getName())) { file.delete(); try { repo.rm().addFilepattern(file.getName()).call(); } catch (GitAPIException e) { throw new MojoExecutionException("Failed to reset repo", e); } } } for (String include : includes) { File includedFile = new File(includeBaseDir, include); if (!includedFile.exists()) { throw new MojoExecutionException("Included file \"" + include + "\" does not exist at includeBaseDir/{name}: " + includedFile.getAbsolutePath()); } if (includedFile.isDirectory()) { throw new MojoExecutionException("Included files can not be directory: " + includedFile); } try { Files.copy(includedFile.toPath(), new File(outputDir, include).toPath()); } catch (IOException e) { throw new MojoExecutionException("Failed to copy included resource", e); } try { repo.add().addFilepattern(include).call(); } catch (GitAPIException e) { throw new MojoExecutionException("Failed to add included file", e); } } if (directoryToInclude != null && !directoryToInclude.equals("")) { File includedDir = new File(directoryToInclude); if (!includedDir.exists() && includedDir.isDirectory()) { throw new MojoExecutionException( "Included directory \"" + directoryToInclude + "\" does not exist"); } for (File includedFile : includedDir.listFiles()) { String include = includedFile.getName(); if (includedFile.isDirectory()) { throw new MojoExecutionException("Included files can not be directory: " + includedFile); } try { Files.copy(includedFile.toPath(), new File(outputDir, include).toPath()); } catch (IOException e) { throw new MojoExecutionException("Failed to copy included resource", e); } try { repo.add().addFilepattern(include).call(); } catch (GitAPIException e) { throw new MojoExecutionException("Failed to add included file", e); } } } try { repo.commit().setMessage("Added files for next release of " + version).call(); } catch (GitAPIException e) { throw new MojoExecutionException("Failed to commit to repo with changes", e); } try { repo.tag().setName(version).setMessage("Releasing version: " + version).call(); } catch (GitAPIException e) { throw new MojoExecutionException("Failed to tag release", e); } try { repo.push().setPushTags().setCredentialsProvider(credentialsProvider).call(); repo.push().setPushAll().setCredentialsProvider(credentialsProvider).call(); } catch (GitAPIException e) { throw new MojoExecutionException("Failed to push changes", e); } }
From source file:org.kie.wb.test.rest.RestTestBase.java
License:Apache License
@BeforeClass public static void createGitRepository() throws GitAPIException, IOException { gitRepository = new File(System.getProperty("user.dir"), "target/git-repository/"); Git git = Git.init().setDirectory(gitRepository).call(); URL pomUrl = RestTestBase.class.getResource("/pom.xml"); File pomFile = new File(gitRepository, "pom.xml"); FileUtils.copyURLToFile(pomUrl, pomFile); git.add().addFilepattern("pom.xml").call(); git.commit().setMessage("Add pom.xml").call(); }
From source file:org.kie.workbench.common.screens.examples.backend.server.ExamplesServiceImpl.java
License:Apache License
@PostConstruct public void initPlaygroundRepository() { try {// w ww . ja va2 s.com String userDir = System.getProperty("user.dir"); File playgroundDirectory = new File(userDir, ".kie-wb-playground"); if (playgroundDirectory.exists()) { cleanPlaygroundDirectory(playgroundDirectory.toPath()); } playgroundDirectory.mkdirs(); URL resource = getClass().getClassLoader().getResource(KIE_WB_PLAYGROUND_ZIP); if (resource == null) { logger.warn("Playground repository jar not found on classpath."); return; } try (ZipInputStream inputStream = new ZipInputStream(resource.openStream())) { ZipEntry zipEntry = null; while ((zipEntry = inputStream.getNextEntry()) != null) { byte[] buffer = new byte[1024]; File file = new File(playgroundDirectory, zipEntry.getName()); if (zipEntry.isDirectory()) { file.mkdirs(); } else { try (FileOutputStream fos = new FileOutputStream(file)) { int read = -1; while ((read = inputStream.read(buffer)) != -1) { fos.write(buffer, 0, read); } } } } final Git git = Git.init().setBare(false).setDirectory(playgroundDirectory).call(); git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); String repositoryUrl = resolveRepositoryUrl(playgroundDirectory.getAbsolutePath()); playgroundRepository = new ExampleRepository(repositoryUrl); } } catch (java.io.IOException | GitAPIException e) { logger.error( "Unable to initialize playground git repository. Only custom repository definition will be available in the Workbench.", e); } }