/** * Sets the committer for this {@code commit}. If no committer is explicitly * specified because this method is never called then the committer will be * deduced from config info in repository, with current time. * * @param name * the name of the committer used for the {@code commit} * @param email * the email of the committer used for the {@code commit} * @return {@code this} */ public CommitCommand setCommitter(String name, String email) { checkCallable(); return setCommitter(new PersonIdent(name, email)); }
@Signature public Memory commit(String message, ArrayMemory settings) throws GitAPIException { CommitCommand commit = getWrappedObject().commit(); commit.setMessage(message); if (settings != null && settings.isNotNull()) { commit.setAll(settings.valueOfIndex("all").toBoolean()); commit.setAllowEmpty(settings.valueOfIndex("allowEmpty").toBoolean()); commit.setAmend(settings.valueOfIndex("amend").toBoolean()); commit.setInsertChangeId(settings.valueOfIndex("insertChangeId").toBoolean()); commit.setNoVerify(settings.valueOfIndex("noVerify").toBoolean()); Memory author = settings.valueOfIndex("author"); if (author.isArray()) { commit.setAuthor(author.valueOfIndex("name").toString(), author.valueOfIndex("email").toString()); } Memory committer = settings.valueOfIndex("committer"); if (committer.isArray()) { commit.setCommitter(committer.valueOfIndex("name").toString(), committer.valueOfIndex("email").toString()); } if (settings.containsKey("only")) { commit.setOnly(settings.valueOfIndex("only").toString()); } if (settings.containsKey("reflogComment")) { commit.setReflogComment(settings.valueOfIndex("reflogComment").toString()); } } RevCommit call = commit.call(); return GitUtils.valueOf(call); }
/** * Sets the committer for this {@code commit}. If no committer is explicitly * specified because this method is never called then the committer will be * deduced from config info in repository, with current time. * * @param name * the name of the committer used for the {@code commit} * @param email * the email of the committer used for the {@code commit} * @return {@code this} */ public CommitCommand setCommitter(String name, String email) { checkCallable(); return setCommitter(new PersonIdent(name, email)); }
/** * Sets the committer for this {@code commit}. If no committer is explicitly * specified because this method is never called then the committer will be * deduced from config info in repository, with current time. * * @param name * the name of the committer used for the {@code commit} * @param email * the email of the committer used for the {@code commit} * @return {@code this} */ public CommitCommand setCommitter(String name, String email) { checkCallable(); return setCommitter(new PersonIdent(name, email)); }
/** {@inheritDoc} */ @Override public void commit(String message) throws GitException { try (Repository repo = getRepository()) { CommitCommand cmd = git(repo).commit().setMessage(message).setAuthor(author); if (committer!=null) cmd.setCommitter(new PersonIdent(committer,new Date())); cmd.call(); } catch (GitAPIException e) { throw new GitException(e); } }
@Override public String commit(String author, String email, String message) { RevCommit revCommit = null; 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(); }
/** * Commits all working changes to the repository with the passed commit message. * * @param user - CasUserProfile of the logged in user. * @param msg - Commit message. * @return - RevCommit of the new commit. * @throws GitAPIException - failed. */ public RevCommit commit(final CasUserProfile user, final String msg) throws GitAPIException { return git.commit() .setAll(true) .setCommitter(getCommitterId(user)) .setMessage(msg) .call(); }
@Override public FileData copy(String srcName, FileData destData) throws IOException { Lock writeLock = repositoryLock.writeLock(); try { writeLock.lock(); File src = new File(localRepositoryPath, srcName); File dest = new File(localRepositoryPath, destData.getName()); IOUtils.copyAndClose(new FileInputStream(src), new FileOutputStream(dest)); git.add().addFilepattern(destData.getName()).call(); RevCommit commit = git.commit() .setMessage(StringUtils.trimToEmpty(destData.getComment())) .setCommitter(destData.getAuthor(), "") .call(); addTagToCommit(commit); push(); } catch (Exception e) { reset(); throw new IOException(e); } finally { writeLock.unlock(); } return check(destData.getName()); }
.setCommitter(committerName, committerEmail).setAll(stageAll) .setAmend(isAmend).setMessage(msg); if (authorName != null && authorEmail != null) {
.setCommitter(committerName, committerEmail).setAll(stageAll) .setAmend(isAmend).setMessage(msg); if (authorName != null && authorEmail != null) {
@Override public FileData save(FileData data, InputStream stream) throws IOException { Lock writeLock = repositoryLock.writeLock(); try { writeLock.lock(); String fileInRepository = data.getName(); File file = new File(localRepositoryPath, fileInRepository); createParent(file); IOUtils.copyAndClose(stream, new FileOutputStream(file)); git.add().addFilepattern(fileInRepository).call(); // TODO: Add possibility to set committer email RevCommit commit = git.commit() .setMessage(StringUtils.trimToEmpty(data.getComment())) .setCommitter(data.getAuthor(), "") .setOnly(fileInRepository) .call(); addTagToCommit(commit); push(); } catch (Exception e) { reset(); throw new IOException(e); } finally { writeLock.unlock(); } return check(data.getName()); }
/** * Commits a single file into the git repository. * * @param user - the user * @param file - the file * @param msg - commit msg * @return - Commit Id * @throws GitAPIException -failed */ public RevCommit commitSingleFile(final CasUserProfile user, final String file, final String msg) throws GitAPIException { git.add().addFilepattern(file).call(); return git.commit() .setCommitter(getCommitterId(user)) .setMessage(msg) .call(); }
private void updateA() { try { add(git, root, new File("src/test/resources/files/b.json"), "dir"); FileUtils.copyFile(new File("src/test/resources/files/a-v2.json"), new File(root, "dir/a.json")); git.add() .addFilepattern("dir/a.json") .call(); git.commit() .setAuthor("clement", "clement@apache.org") .setCommitter("clement", "clement@apache.org") .setMessage("Update a.json") .call(); push(git); } catch (Exception e) { throw new RuntimeException(e); } }
private void updateA() { try { add(git, root, new File("src/test/resources/files/b.json"), "dir"); FileUtils.copyFile(new File("src/test/resources/files/a-v2.json"), new File(root, "dir/a.json")); git.add() .addFilepattern("dir/a.json") .call(); git.commit() .setAuthor("clement", "clement@apache.org") .setCommitter("clement", "clement@apache.org") .setMessage("Update a.json") .call(); push(git); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public FileData rename(String srcName, FileData destData) throws IOException { Lock writeLock = repositoryLock.writeLock(); try { writeLock.lock(); File src = new File(localRepositoryPath, srcName); File dest = new File(localRepositoryPath, destData.getName()); FileUtils.move(src, dest); git.rm().addFilepattern(srcName).call(); git.add().addFilepattern(destData.getName()).call(); RevCommit commit = git.commit() .setMessage(StringUtils.trimToEmpty(destData.getComment())) .setCommitter(destData.getAuthor(), "") .setOnly(srcName) .setOnly(destData.getName()) .call(); addTagToCommit(commit); push(); } catch (Exception e) { reset(); throw new IOException(e); } finally { writeLock.unlock(); } return check(destData.getName()); }
/** * Commit all changes in the given repository. * * @param targetDirectory The target directory. */ public static void commitAll(Path targetDirectory, String userName, String userEmail, String commitMessage) { Git repository = null; try { repository = Git.open(targetDirectory.toFile()); repository.add().addFilepattern(".").call(); String name = defaultUsernameIfNull(userName); String email = defaultEmailIfNull(name, userEmail); repository.commit().setCommitter(name, email).setMessage(commitMessage).call(); } catch (GitAPIException | IOException e) { throw new GitException("Unable to commit to the git repository", e); } finally { close(repository); } }
/** * This method performs 'git push' programmically * * @throws GitWorkflowException */ public void pushChanges(GitConfiguration gitConfig, String commitMessage) throws GitWorkflowException { try (Git git = Git.open(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId()))) { // Perform 'git add .' git.add().addFilepattern(".").call(); // Perform 'git commit -m' git.commit().setMessage(commitMessage).setCommitter(gitConfig.getBotName(), gitConfig.getBotEmail()).call(); // Push with bot credenials git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitConfig.getBotToken(), "")) .call(); } catch (TransportException t) { logger.error(t.getMessage(), t); throw new GitWorkflowException("Wrong bot token!"); } catch (Exception e) { logger.error(e.getMessage(), e); throw new GitWorkflowException("Could not successfully perform 'git push'!"); } }
public void addAndCommit(String message, GitUser user) { try { git.add().addFilepattern(".").call(); git.commit().setMessage(message).setAuthor(user.getName(), user.getEmail()).setCommitter(user.getName(), user.getEmail()).setAll(true).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
public void commit(String message) throws GitException { verifyGitRepository(); parseEnvVars(getEnvironment()); try { jGitDelegate.commit() .setMessage(message) .setAuthor(getAuthor()) .setCommitter(getCommitter()) .call(); } catch (Exception e) { throw new GitException(Messages.GitAPI_Commit_FailedMsg(message), e); } }
static void addAllAndCommit(Git git, UserProfile user, String commitMsg) throws GitAPIException { AddCommand addCommand = git.add() .addFilepattern(".") .addFilepattern("application.json"); CommitCommand commitCmd = git.commit(); if (user != null && user.name() != null && user.email() != null) { commitCmd.setCommitter(user.name(), user.email()); } if (commitMsg != null) { commitCmd.setMessage(commitMsg); } GitHandler.commit(() -> { addCommand.call(); return commitCmd.call(); }); } }