Search in sources :

Example 1 with NoMessageException

use of org.eclipse.jgit.api.errors.NoMessageException in project MGit by maks.

the class CommitChangesTask method commit.

public static void commit(Repo repo, boolean stageAll, boolean isAmend, String msg, String authorName, String authorEmail) throws Exception, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, GitAPIException, StopTaskException {
    Context context = SGitApplication.getContext();
    StoredConfig config = repo.getGit().getRepository().getConfig();
    String committerEmail = config.getString("user", null, "email");
    String committerName = config.getString("user", null, "name");
    if (committerName == null || committerName.equals("")) {
        committerName = Profile.getUsername(context);
    }
    if (committerEmail == null || committerEmail.equals("")) {
        committerEmail = Profile.getEmail(context);
    }
    if (committerName.isEmpty() || committerEmail.isEmpty()) {
        throw new Exception("Please set your name and email");
    }
    if (msg.isEmpty()) {
        throw new Exception("Please include a commit message");
    }
    CommitCommand cc = repo.getGit().commit().setCommitter(committerName, committerEmail).setAll(stageAll).setAmend(isAmend).setMessage(msg);
    if (authorName != null && authorEmail != null) {
        cc.setAuthor(authorName, authorEmail);
    }
    cc.call();
    repo.updateLatestCommitInfo();
}
Also used : Context(android.content.Context) StoredConfig(org.eclipse.jgit.lib.StoredConfig) CommitCommand(org.eclipse.jgit.api.CommitCommand) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) StopTaskException(me.sheimi.sgit.exception.StopTaskException) UnmergedPathsException(org.eclipse.jgit.api.errors.UnmergedPathsException) NoMessageException(org.eclipse.jgit.api.errors.NoMessageException)

Aggregations

Context (android.content.Context)1 StopTaskException (me.sheimi.sgit.exception.StopTaskException)1 CommitCommand (org.eclipse.jgit.api.CommitCommand)1 ConcurrentRefUpdateException (org.eclipse.jgit.api.errors.ConcurrentRefUpdateException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 NoHeadException (org.eclipse.jgit.api.errors.NoHeadException)1 NoMessageException (org.eclipse.jgit.api.errors.NoMessageException)1 UnmergedPathsException (org.eclipse.jgit.api.errors.UnmergedPathsException)1 WrongRepositoryStateException (org.eclipse.jgit.api.errors.WrongRepositoryStateException)1 StoredConfig (org.eclipse.jgit.lib.StoredConfig)1