return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
"Missing commit message.", null));
}
Git git = new Git(db);
CommitCommand cc = git.commit();
Config config = git.getRepository().getConfig();
boolean amend = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_COMMIT_AMEND, null));
boolean insertChangeId = config.getBoolean(ConfigConstants.CONFIG_GERRIT_SECTION, ConfigConstants.CONFIG_KEY_CREATECHANGEID, false)
|| Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_CHANGE_ID, null));
String committerName = requestObject.optString(GitConstants.KEY_COMMITTER_NAME, null);
String committerEmail = requestObject.optString(GitConstants.KEY_COMMITTER_EMAIL, null);
String authorName = requestObject.optString(GitConstants.KEY_AUTHOR_NAME, null);
String authorEmail = requestObject.optString(GitConstants.KEY_AUTHOR_EMAIL, null);
// workaround of a bug in JGit which causes invalid
// support of null values of author/committer name/email, see bug
// 352984
PersonIdent defPersonIdent = new PersonIdent(db);
if (committerName == null)
committerName = defPersonIdent.getName();
if (committerEmail == null)
committerEmail = defPersonIdent.getEmailAddress();
if (authorName == null)
authorName = committerName;
if (authorEmail == null)
authorEmail = committerEmail;
cc.setCommitter(committerName, committerEmail);
cc.setAuthor(authorName, authorEmail);
if (insertChangeId)
cc.setInsertChangeId(true);
// support for committing by path: "git commit -o path"
if (!pattern.isEmpty()) {
cc.setOnly(pattern);
}
try {
// "git commit [--amend] -m '{message}' [-a|{path}]"
RevCommit lastCommit = cc.setAmend(amend).setMessage(message).call();
URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.COMMIT_REFRANGE);
Commit commit = new Commit(cloneLocation, db, lastCommit, pattern);
JSONObject result = commit.toJSON();
OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);