use of org.eclipse.jgit.api.CommitCommand in project egit by eclipse.
the class CommitOperation method commitAll.
// TODO: can the commit message be change by the user in case of a merge commit?
private void commitAll() throws TeamException {
try (Git git = new Git(repo)) {
CommitCommand commitCommand = git.commit();
setAuthorAndCommitter(commitCommand);
commit = commitCommand.setAll(true).setMessage(message).setInsertChangeId(createChangeId).call();
} catch (JGitInternalException e) {
throw new TeamException(CoreText.MergeOperation_InternalError, e);
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(), e);
}
}
use of org.eclipse.jgit.api.CommitCommand in project egit by eclipse.
the class TestRepository method commit.
/**
* Commits the current index
*
* @param message
* commit message
* @return commit object
*
* @throws NoHeadException
* @throws NoMessageException
* @throws UnmergedPathException
* @throws ConcurrentRefUpdateException
* @throws JGitInternalException
* @throws GitAPIException
* @throws WrongRepositoryStateException
*/
public RevCommit commit(String message) throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException, GitAPIException {
try (Git git = new Git(repository)) {
CommitCommand commitCommand = git.commit();
commitCommand.setAuthor("J. Git", "j.git@egit.org");
commitCommand.setCommitter(commitCommand.getAuthor());
commitCommand.setMessage(message);
return commitCommand.call();
}
}
use of org.eclipse.jgit.api.CommitCommand in project egit by eclipse.
the class AbstractGitflowHandlerTest method setContentAddAndCommit.
protected RevCommit setContentAddAndCommit(String newContent) throws Exception, GitAPIException, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, AbortedByHookException, IOException {
setTestFileContent(newContent);
Git git = Git.wrap(repository);
git.add().addFilepattern(".").call();
CommitCommand commit = git.commit().setMessage(newContent);
commit.setAuthor(TestUtil.TESTCOMMITTER_NAME, TestUtil.TESTCOMMITTER_EMAIL);
commit.setCommitter(TestUtil.TESTCOMMITTER_NAME, TestUtil.TESTCOMMITTER_EMAIL);
return commit.call();
}
use of org.eclipse.jgit.api.CommitCommand in project Android-Password-Store by zeapo.
the class GitAsyncTask method doInBackground.
@Override
protected String doInBackground(GitCommand... commands) {
Integer nbChanges = null;
for (GitCommand command : commands) {
Log.d("doInBackground", "Executing the command <" + command.toString() + ">");
try {
if (command instanceof StatusCommand) {
// in case we have changes, we want to keep track of it
org.eclipse.jgit.api.Status status = ((StatusCommand) command).call();
nbChanges = status.getChanged().size() + status.getMissing().size();
} else if (command instanceof CommitCommand) {
// the previous status will eventually be used to avoid a commit
if (nbChanges == null || nbChanges > 0)
command.call();
} else if (command instanceof PushCommand) {
for (final PushResult result : ((PushCommand) command).call()) {
// Code imported (modified) from Gerrit PushOp, license Apache v2
for (final RemoteRefUpdate rru : result.getRemoteUpdates()) {
switch(rru.getStatus()) {
case REJECTED_NONFASTFORWARD:
return activity.getString(R.string.git_push_nff_error);
case REJECTED_NODELETE:
case REJECTED_REMOTE_CHANGED:
case NON_EXISTING:
case NOT_ATTEMPTED:
return activity.getString(R.string.git_push_generic_error) + rru.getStatus().name();
case REJECTED_OTHER_REASON:
if ("non-fast-forward".equals(rru.getMessage())) {
return activity.getString(R.string.git_push_other_error);
} else {
return activity.getString(R.string.git_push_generic_error) + rru.getMessage();
}
default:
break;
}
}
}
} else {
command.call();
}
} catch (Exception e) {
e.printStackTrace();
return e.getMessage() + "\nCaused by:\n" + e.getCause();
}
}
return "";
}
use of org.eclipse.jgit.api.CommitCommand in project jbosstools-openshift by jbosstools.
the class TestRepository method commit.
/**
* Commits the current index
*
* @param message
* commit message
* @return commit object
*
* @throws UnmergedPathException
* @throws JGitInternalException
* @throws GitAPIException
* @throws UnmergedPathsException
*/
public RevCommit commit(String message) throws UnmergedPathException, JGitInternalException, UnmergedPathsException, GitAPIException {
Git git = new Git(repository);
CommitCommand commitCommand = git.commit();
commitCommand.setAuthor("J. Git", "j.git@egit.org");
commitCommand.setCommitter(commitCommand.getAuthor());
commitCommand.setMessage(message);
return commitCommand.call();
}
Aggregations