Example usage for org.eclipse.jgit.api.errors NoMessageException NoMessageException

List of usage examples for org.eclipse.jgit.api.errors NoMessageException NoMessageException

Introduction

In this page you can find the example usage for org.eclipse.jgit.api.errors NoMessageException NoMessageException.

Prototype

public NoMessageException(String message) 

Source Link

Document

Constructor for NoMessageException

Usage

From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareCommitCommand.java

/**
 * Sets default values for not explicitly specified options. Then validates
 * that all required data has been provided.
 *
 * @param state//w w w . j  av  a2s .  c om
 *            the state of the repository we are working on
 * @param rw
 *            the RevWalk to use
 *
 * @throws NoMessageException
 *             if the commit message has not been specified
 */
private void processOptions(RepositoryState state, RevWalk rw) throws NoMessageException {
    if (committer == null) {
        committer = new PersonIdent(repo);
    }
    if (author == null && !amend) {
        author = committer;
    }
    if (allowEmpty == null) {
        // JGit allows empty commits by default. Only when pathes are
        // specified the commit should not be empty. This behaviour differs
        // from native git but can only be adapted in the next release.
        // TODO(ch) align the defaults with native git
        allowEmpty = (only.isEmpty()) ? Boolean.TRUE : Boolean.FALSE;
    }
    // when doing a merge commit parse MERGE_HEAD and MERGE_MSG files
    if (state == RepositoryState.MERGING_RESOLVED || isMergeDuringRebase(state)) {
        try {
            parents = repo.readMergeHeads();
            if (parents != null) {
                for (int i = 0; i < parents.size(); i++) {
                    RevObject ro = rw.parseAny(parents.get(i));
                    if (ro instanceof RevTag)
                        parents.set(i, rw.peel(ro));
                }
            }
        } catch (IOException e) {
            throw new JGitInternalException(MessageFormat.format(
                    JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_HEAD, e), e);
        }
        if (message == null) {
            try {
                message = repo.readMergeCommitMsg();
            } catch (IOException e) {
                throw new JGitInternalException(MessageFormat.format(
                        JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e), e);
            }
        }
    } else if (state == RepositoryState.SAFE && message == null) {
        try {
            message = repo.readSquashCommitMsg();
            if (message != null) {
                repo.writeSquashCommitMsg(null /* delete */);
            }
        } catch (IOException e) {
            throw new JGitInternalException(MessageFormat
                    .format(JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e), e);
        }

    }
    if (message == null) {
        // as long as we don't support -C option we have to have
        // an explicit message
        throw new NoMessageException(JGitText.get().commitMessageNotSpecified);
    }
}