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

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

Introduction

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

Prototype

public CommitCommand setMessage(String message) 

Source Link

Document

Set the commit message

Usage

From source file:com.barchart.jenkins.cascade.PluginScmGit.java

License:BSD License

/**
 * See {@link Git#commit()}/*from   ww  w . java 2 s  . c o  m*/
 */
public static RevCommit doCommit(final File workspace, final PersonIdent person, final String message) {
    try {
        final Git git = Git.open(workspace);
        final CommitCommand command = git.commit();
        if (person != null) {
            command.setAuthor(person).setCommitter(person);
        }
        return command.setMessage(message).call();
    } catch (final Throwable e) {
        throw new RuntimeException(e);
    }
}

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 {//from w  w w.jav  a2  s  . c o  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);/*from   w w w  .jav a2  s .c  om*/
    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;//  ww w .ja va 2 s .c  o  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.osbitools.ws.shared.prj.utils.GitUtils.java

License:Open Source License

public static String commitFile(Git git, String fname, String comment, String user) throws WsSrvException {

    AddCommand add = git.add();//from   w w w  . j av a 2 s .co m
    try {
        add.addFilepattern(fname).call();
    } catch (GitAPIException e) {
        throw new WsSrvException(239, e);
    }

    CommitCommand commit = git.commit();
    try {
        RevCommit rev = commit.setMessage(comment).setCommitter(user, "").call();
        return rev.getName();
    } catch (GitAPIException e) {
        throw new WsSrvException(240, e);
    }
}

From source file:com.peergreen.configuration.git.GitConfiguration.java

License:Apache License

@Override
public ConfigRepository getRepository(String name) throws RepositoryException {
    check();/*  ww w.  j ava 2 s .c om*/

    // Sets the git directory from the given repository name
    File repositoryDir = new File(rootDirectory, name);
    File gitDir = new File(repositoryDir, Constants.DOT_GIT);

    // Find the git directory
    FileRepository fileRepository = null;
    try {
        fileRepository = new FileRepositoryBuilder() //
                .setGitDir(gitDir) // --git-dir if supplied, no-op if null
                .readEnvironment() // scan environment GIT_* variables
                .findGitDir().build();
    } catch (IOException e) {
        throw new RepositoryException("Unable to find a repository for the path '" + name + "'.", e);
    }

    // do not exist yet on the filesystem, create all the directories
    if (!gitDir.exists()) {
        try {
            fileRepository.create();
        } catch (IOException e) {
            throw new RepositoryException("Cannot create repository", e);
        }

        // Create the first commit in order to initiate the repository.
        Git git = new Git(fileRepository);
        CommitCommand commit = git.commit();
        try {
            commit.setMessage("Initial setup for the git configuration of '" + name + "'").call();
        } catch (GitAPIException e) {
            throw new RepositoryException("Cannot init the git repository '" + name + "'", e);
        }

    }

    return new GitRepository(fileRepository);

}

From source file:com.photon.phresco.framework.impl.SCMManagerImpl.java

License:Apache License

private void importToGITRepo(RepoDetail repodetail, ApplicationInfo appInfo, File appDir) throws Exception {
    if (debugEnabled) {
        S_LOGGER.debug("Entering Method  SCMManagerImpl.importToGITRepo()");
    }/*from w w  w .ja v a 2  s.  c  o  m*/
    boolean gitExists = false;
    if (new File(appDir.getPath() + FORWARD_SLASH + DOT + GIT).exists()) {
        gitExists = true;
    }
    try {
        //For https and ssh
        additionalAuthentication(repodetail.getPassPhrase());

        CredentialsProvider cp = new UsernamePasswordCredentialsProvider(repodetail.getUserName(),
                repodetail.getPassword());

        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setGitDir(appDir).readEnvironment().findGitDir().build();
        String dirPath = appDir.getPath();
        File gitignore = new File(dirPath + GITIGNORE_FILE);
        gitignore.createNewFile();
        if (gitignore.exists()) {
            String contents = FileUtils.readFileToString(gitignore);
            if (!contents.isEmpty() && !contents.contains(DO_NOT_CHECKIN_DIR)) {
                String source = NEWLINE + DO_NOT_CHECKIN_DIR + NEWLINE;
                OutputStream out = new FileOutputStream((dirPath + GITIGNORE_FILE), true);
                byte buf[] = source.getBytes();
                out.write(buf);
                out.close();
            } else if (contents.isEmpty()) {
                String source = NEWLINE + DO_NOT_CHECKIN_DIR + NEWLINE;
                OutputStream out = new FileOutputStream((dirPath + GITIGNORE_FILE), true);
                byte buf[] = source.getBytes();
                out.write(buf);
                out.close();
            }
        }

        Git git = new Git(repository);

        InitCommand initCommand = Git.init();
        initCommand.setDirectory(appDir);
        git = initCommand.call();

        AddCommand add = git.add();
        add.addFilepattern(".");
        add.call();

        CommitCommand commit = git.commit().setAll(true);
        commit.setMessage(repodetail.getCommitMessage()).call();
        StoredConfig config = git.getRepository().getConfig();

        config.setString(REMOTE, ORIGIN, URL, repodetail.getRepoUrl());
        config.setString(REMOTE, ORIGIN, FETCH, REFS_HEADS_REMOTE_ORIGIN);
        config.setString(BRANCH, MASTER, REMOTE, ORIGIN);
        config.setString(BRANCH, MASTER, MERGE, REF_HEAD_MASTER);
        config.save();

        try {
            PushCommand pc = git.push();
            pc.setCredentialsProvider(cp).setForce(true);
            pc.setPushAll().call();
        } catch (Exception e) {
            git.getRepository().close();
            PomProcessor appPomProcessor = new PomProcessor(new File(appDir, appInfo.getPhrescoPomFile()));
            appPomProcessor.removeProperty(Constants.POM_PROP_KEY_SRC_REPO_URL);
            appPomProcessor.save();
            throw e;
        }

        if (appInfo != null) {
            updateSCMConnection(appInfo, repodetail.getRepoUrl());
        }
        git.getRepository().close();
    } catch (Exception e) {
        Exception s = e;
        resetLocalCommit(appDir, gitExists, e);
        throw s;
    }
}

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

License:Apache License

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