use of org.eclipse.jgit.api.CommitCommand in project fabric8 by fabric8io.
the class GitUtils method doCommitAndPush.
public static RevCommit doCommitAndPush(Git git, String message, UserDetails userDetails, PersonIdent author, String branch, String origin, boolean pushOnCommit, int pushRetries) throws GitAPIException {
CommitCommand commit = git.commit().setAll(true).setMessage(message);
if (author != null) {
commit = commit.setAuthor(author);
}
RevCommit answer = commit.call();
if (LOG.isDebugEnabled()) {
LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage());
}
if (pushOnCommit) {
GitAPIException exception = null;
for (int i = 1; i <= pushRetries; i++) {
try {
if (i > 1) {
try {
Thread.sleep(700);
} catch (InterruptedException e) {
//
}
LOG.info("Retrying git push attempt " + i);
}
PushCommand push = git.push();
configureCommand(push, userDetails);
Iterable<PushResult> results = push.setRemote(origin).call();
for (PushResult result : results) {
if (LOG.isDebugEnabled()) {
LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + toString(result.getRemoteUpdates()));
}
}
return answer;
} catch (GitAPIException e) {
if (exception == null) {
exception = e;
}
LOG.error("Failed to git push attempt " + i + " with " + e, e);
}
}
if (exception != null) {
throw exception;
}
}
return answer;
}
Aggregations