List of usage examples for org.eclipse.jgit.api CommitCommand setAll
public CommitCommand setAll(boolean all)
From source file:com.rimerosolutions.ant.git.tasks.CommitTask.java
License:Apache License
@Override protected void doExecute() throws BuildException { try {/*from w ww.ja v a 2s. c om*/ setFailOnError(true); CommitCommand cmd = git.commit(); if (!GitTaskUtils.isNullOrBlankString(message)) { cmd.setMessage(brandedMessage ? GitTaskUtils.BRANDING_MESSAGE + " " : "" + message); } else { cmd.setMessage(GitTaskUtils.BRANDING_MESSAGE); } String prefix = getDirectory().getCanonicalPath(); String[] allFiles = getPath().list(); if (!GitTaskUtils.isNullOrBlankString(only)) { cmd.setOnly(only); } else if (allFiles.length > 0) { for (String file : allFiles) { String modifiedFile = translateFilePathUsingPrefix(file, prefix); log("Will commit " + modifiedFile); cmd.setOnly(modifiedFile); } } else { cmd.setAll(true); } GitSettings gitSettings = lookupSettings(); if (gitSettings == null) { throw new MissingRequiredGitSettingsException(); } cmd.setAmend(amend).setAuthor(gitSettings.getIdentity()).setCommitter(gitSettings.getIdentity()); if (reflogComment != null) { cmd.setReflogComment(reflogComment); } RevCommit revCommit = cmd.call(); if (revCommitIdProperty != null) { String revisionId = ObjectId.toString(revCommit.getId()); getProject().setProperty(revCommitIdProperty, revisionId); } log(revCommit.getFullMessage()); } catch (IOException ioe) { throw new GitBuildException(MESSAGE_COMMIT_FAILED, ioe); } catch (GitAPIException ex) { throw new GitBuildException(MESSAGE_COMMIT_FAILED, ex); } }
From source file:com.sap.dirigible.ide.jgit.connector.JGitConnector.java
License:Open Source License
/** * /*from ww w . jav a2s . com*/ * Adds changes to the staging index. Then makes commit. * * @param message * the commit message * @param name * the name of the committer used for the commit * @param email * the email of the committer used for the commit * @param all * if set to true, command will automatically stages files that * have been modified and deleted, but new files not known by the * repository are not affected. This corresponds to the parameter * -a on the command line. * * @throws NoHeadException * @throws NoMessageException * @throws UnmergedPathsException * @throws ConcurrentRefUpdateException * @throws WrongRepositoryStateException * @throws GitAPIException * @throws IOException */ public void commit(String message, String name, String email, boolean all) throws NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, GitAPIException, IOException { CommitCommand commitCommand = git.commit(); commitCommand.setMessage(message); commitCommand.setCommitter(name, email); commitCommand.setAuthor(name, email); commitCommand.setAll(all); commitCommand.call(); }
From source file:com.stormcloud.ide.api.git.GitManager.java
License:Open Source License
@Override public void commit(String repository, String message, String[] files, boolean all) throws GitManagerException { try {/*w w w . j av a 2s . c om*/ Git git = Git.open(new File(repository)); CommitCommand commit = git.commit(); commit.setMessage(message); if (all) { commit.setAll(true); } else { for (String file : files) { commit.setOnly(file); } } RevCommit result = commit.call(); // result.... } catch (IOException e) { LOG.error(e); throw new GitManagerException(e); } catch (GitAPIException e) { LOG.error(e); throw new GitManagerException(e); } }
From source file:com.verigreen.jgit.JGitOperator.java
License:Apache License
@Override public String commit(String author, String email, String message) { RevCommit revCommit = null;// w w w .ja v a 2 s . c om CommitCommand command = _git.commit(); command.setCommitter(author, email); command.setMessage(message); command.setAll(true); try { revCommit = command.call(); } catch (Throwable e) { throw new RuntimeException("Failed to commit", e); } return revCommit.getId().getName(); }
From source file:org.ajoberstar.gradle.git.tasks.GitCommit.java
License:Apache License
/** * Commits changes to the Git repository. *///from w w w. j a va2s. c o m @TaskAction public void commit() { final CommitCommand cmd = getGit().commit(); cmd.setMessage(getMessage()); cmd.setAll(getCommitAll()); if (committer != null) { cmd.setCommitter(getCommitter()); } if (author != null) { cmd.setAuthor(getAuthor()); } if (!patternSet.getExcludes().isEmpty() || !patternSet.getIncludes().isEmpty()) { getSource().visit(new FileVisitor() { public void visitDir(FileVisitDetails arg0) { visitFile(arg0); } public void visitFile(FileVisitDetails arg0) { cmd.setOnly(arg0.getPath()); } }); } try { cmd.call(); } catch (Exception e) { throw new GradleException("Problem committing changes.", e); } }
From source file:org.eclipse.orion.server.filesystem.git.GitFileStore.java
License:Open Source License
private void rm() throws CoreException { // TODO: use org.eclipse.jgit.api.RmCommand, see Enhancement 379 if (!isRoot()) { try {/*from w w w. j a v a2s . c o m*/ Repository local = getLocalRepo(); Git git = new Git(local); CommitCommand commit = git.commit(); commit.setAll(true); commit.setMessage("auto-commit of " + toString()); commit.call(); } catch (Exception e) { throw new CoreException( new Status(IStatus.ERROR, Activator.PI_GIT, IStatus.ERROR, e.getMessage(), e)); } push(); } // else {cannot commit/push root removal} }
From source file:org.ms123.common.git.GitServiceImpl.java
License:Open Source License
public void commitAll(@PName("name") String name, @PName("message") String message) throws RpcException { try {/* 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.CommitAll:Repo(" + name + ") not exists"); } Git git = Git.open(dir); CommitCommand ic = git.commit(); ic.setAll(true); ic.setMessage(message); ic.call(); return; } catch (Exception e) { if (e instanceof RpcException) throw (RpcException) e; throw new RpcException(ERROR_FROM_METHOD, INTERNAL_SERVER_ERROR, "GitService.commitAll:", e); } finally { } }
From source file:org.zend.sdkcli.internal.commands.GitPushApplicationCommand.java
License:Open Source License
@Override protected boolean doExecute() { Repository repo = null;//w ww. j a v a 2s . c o m try { File gitDir = getRepo(); if (!gitDir.exists()) { getLogger().error("Git repository is not available in provided location"); return false; } repo = FileRepositoryBuilder.create(getRepo()); } catch (IOException e) { getLogger().error(e); return false; } if (repo != null) { Git git = new Git(repo); String remote = doGetRemote(repo); if (remote == null) { getLogger().error("Invalid remote value: " + getRemote()); return false; } // perform operation only if it is clone of phpCloud repository String repoUrl = git.getRepository().getConfig().getString("remote", remote, "url"); AddCommand addCommand = git.add(); addCommand.setUpdate(false); // add all new files addCommand.addFilepattern("."); try { addCommand.call(); } catch (NoFilepatternException e) { // should not occur because '.' is used getLogger().error(e); return false; } catch (GitAPIException e) { getLogger().error(e); return false; } CommitCommand commitCommand = git.commit(); // automatically stage files that have been modified and deleted commitCommand.setAll(true); PersonIdent ident = getPersonalIdent(repoUrl); if (ident == null) { getLogger().error("Invalid author information provided: " + getAuthor()); return false; } commitCommand.setAuthor(ident); commitCommand.setInsertChangeId(true); commitCommand.setMessage(getMessage()); try { commitCommand.call(); } catch (Exception e) { getLogger().error(e); return false; } // at the end push all changes PushCommand pushCommand = git.push(); pushCommand.setPushAll(); pushCommand.setRemote(remote); pushCommand.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))); try { URIish uri = new URIish(repoUrl); if (GITHUB_HOST.equals(uri.getHost()) && "git".equals(uri.getUser())) { if (!prepareSSHFactory()) { return false; } } else { CredentialsProvider credentials = getCredentials(repoUrl); if (credentials != null) { pushCommand.setCredentialsProvider(credentials); } } Iterable<PushResult> result = pushCommand.call(); for (PushResult pushResult : result) { pushResult.getAdvertisedRefs(); Collection<RemoteRefUpdate> updates = pushResult.getRemoteUpdates(); for (RemoteRefUpdate remoteRefUpdate : updates) { TrackingRefUpdate trackingRefUpdate = remoteRefUpdate.getTrackingRefUpdate(); getLogger().info(MessageFormat.format("Remote name: {0}, status: {1}", remoteRefUpdate.getRemoteName(), remoteRefUpdate.getStatus().toString())); getLogger().info(MessageFormat.format("Remote name: {0}, result: {1}", trackingRefUpdate.getRemoteName(), trackingRefUpdate.getResult().toString())); } } } catch (JGitInternalException e) { getLogger().error(e); return false; } catch (InvalidRemoteException e) { // should not occur because selected remote is available getLogger().error(e); return false; } catch (URISyntaxException e) { getLogger().error(e); return false; } catch (TransportException e) { getLogger().error(e); return false; } catch (GitAPIException e) { getLogger().error(e); return false; } } return true; }