Example usage for org.eclipse.jgit.api CommitCommand call

List of usage examples for org.eclipse.jgit.api CommitCommand call

Introduction

In this page you can find the example usage for org.eclipse.jgit.api CommitCommand call.

Prototype

@Override
public RevCommit call() throws GitAPIException, NoHeadException, NoMessageException, UnmergedPathsException,
        ConcurrentRefUpdateException, WrongRepositoryStateException, AbortedByHookException 

Source Link

Document

Executes the commit command with all the options and parameters collected by the setter methods of this class.

Usage

From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java

License:Apache License

public void commit(List<String> paths, String msg) throws Exception {
    CommitCommand commit = git.commit().setMessage(msg);
    for (String path : paths)
        commit.setOnly(path);// ww  w  .  j a v  a 2  s  .  c om
    commit.call();
}

From source file:com.cisco.step.jenkins.plugins.jenkow.JenkowWorkflowRepository.java

License:Open Source License

private void addAndCommit(Repository r, String filePattern, String msg) throws IOException {
    try {// w w w. j av a2s.co m
        Git git = new Git(r);
        AddCommand cmd = git.add();
        cmd.addFilepattern(filePattern);
        cmd.call();

        CommitCommand co = git.commit();
        co.setAuthor("Jenkow", "noreply@jenkins-ci.org");
        co.setMessage(msg);
        co.call();
    } catch (GitAPIException e) {
        LOGGER.log(Level.WARNING, "Adding seeded jenkow-repository content to Git failed", e);
    }
}

From source file:com.google.gerrit.acceptance.git.GitUtil.java

License:Apache License

private static Commit createCommit(Git git, PersonIdent i, String msg, String changeId)
        throws GitAPIException, IOException {

    final CommitCommand commitCmd = git.commit();
    commitCmd.setAmend(changeId != null);
    commitCmd.setAuthor(i);// ww  w .jav a  2s .co  m
    commitCmd.setCommitter(i);

    if (changeId == null) {
        ObjectId id = computeChangeId(git, i, msg);
        changeId = "I" + id.getName();
    }
    msg = ChangeIdUtil.insertId(msg, ObjectId.fromString(changeId.substring(1)));
    commitCmd.setMessage(msg);

    RevCommit c = commitCmd.call();
    return new Commit(c, changeId);
}

From source file:com.google.gerrit.acceptance.git.ssh.GitUtil.java

License:Apache License

public static String createCommit(Git git, PersonIdent i, String msg, boolean insertChangeId)
        throws GitAPIException, IOException {
    ObjectId changeId = null;//from   w  ww  . java  2s.  co m
    if (insertChangeId) {
        changeId = computeChangeId(git, i, msg);
        msg = ChangeIdUtil.insertId(msg, changeId);
    }

    final CommitCommand commitCmd = git.commit();
    commitCmd.setAuthor(i);
    commitCmd.setCommitter(i);
    commitCmd.setMessage(msg);
    commitCmd.call();

    return changeId != null ? "I" + changeId.getName() : null;
}

From source file:com.rimerosolutions.ant.git.tasks.CommitTask.java

License:Apache License

@Override
protected void doExecute() throws BuildException {
    try {/*from  ww  w . j a v  a 2s .  co  m*/
        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

/**
 * /*  ww w. j  a v a2  s  .  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 {//from w ww . ja va2  s.c  o  m

        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;//from ww  w  .ja  v  a  2s.c  o m
    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:com.wadpam.gimple.GimpleMojo.java

License:Open Source License

private RevCommit transformPomVersions(Git git, String newVersion)
        throws MojoExecutionException, GitAPIException {
    executeMojo(plugin("org.codehaus.mojo", "versions-maven-plugin", "2.1"), goal("set"),
            configuration(element(name("newVersion"), newVersion)),
            executionEnvironment(mavenProject, mavenSession, pluginManager));

    StatusCommand statusCommand = git.status();
    Status status = statusCommand.call();

    // git add//w  ww . j  ava 2 s .c o m
    for (String uncommitted : status.getUncommittedChanges()) {
        getLog().info("  adding to git index: " + uncommitted);
        AddCommand add = git.add();
        add.addFilepattern(uncommitted);
        add.call();
    }

    // git commit
    CommitCommand commit = git.commit();
    commit.setMessage(GIMPLE_MAVEN_PLUGIN + "pom version " + newVersion);
    return commit.call();
}

From source file:de.br0tbox.gitfx.ui.controllers.CommitDialogController.java

License:Apache License

@FXML
public void commit() {
    try {/*w  w  w .  ja  v a2 s.c  om*/
        final CommitCommand commit = projectModel.getFxProject().getGit().commit();
        final ObservableList<String> unstagedChanges = projectModel.getStagedChangesProperty().get();
        if (unstagedChanges.size() < 1) {
            final Action commitAll = Dialogs.create().owner(getStage())
                    .message("There are no changes staged, do you want to commit every changed File?")
                    .showConfirm();
            if (Dialog.Actions.YES.equals(commitAll)) {
                //FIXME: Threading issue, this is a workaround that seems to work for now.
                stageAll();
                projectModel.getFxProject().getGit().getRepository().getListenerList()
                        .dispatch(new IndexChangedEvent());
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        commit();
                    }
                });
            }
        } else {
            commit.setMessage(commitMessage.getText());
            commit.call();
            this.hide();
        }
    } catch (final GitAPIException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}