}
private boolean validCommit(final RefControl ctl, final ReceiveCommand cmd,
final RevCommit c) throws MissingObjectException, IOException {
rp.getRevWalk().parseBody(c);
final PersonIdent committer = c.getCommitterIdent();
final PersonIdent author = c.getAuthorIdent();
// Require permission to upload merges.
if (c.getParentCount() > 1 && !ctl.canUploadMerges()) {
reject(cmd, "you are not allowed to upload merges");
return false;
}
// Don't allow the user to amend a merge created by Gerrit Code Review.
// This seems to happen all too often, due to users not paying any
// attention to what they are doing.
//
if (c.getParentCount() > 1
&& author.getName().equals(gerritIdent.getName())
&& author.getEmailAddress().equals(gerritIdent.getEmailAddress())
&& !ctl.canForgeGerritServerIdentity()) {
reject(cmd, "do not amend merges not made by you");
return false;
}
// Require that author matches the uploader.
//
if (!currentUser.getEmailAddresses().contains(author.getEmailAddress())
&& !ctl.canForgeAuthor()) {
sendInvalidEmailError(c, "author", author);
reject(cmd, "invalid author");
return false;
}
// Require that committer matches the uploader.
//
if (!currentUser.getEmailAddresses().contains(committer.getEmailAddress())
&& !ctl.canForgeCommitter()) {
sendInvalidEmailError(c, "committer", committer);
reject(cmd, "invalid committer");
return false;
}
if (project.isUseSignedOffBy()) {
// If the project wants Signed-off-by / Acked-by lines, verify we
// have them for the blamable parties involved on this change.
//
boolean sboAuthor = false, sboCommitter = false, sboMe = false;
for (final FooterLine footer : c.getFooterLines()) {
if (footer.matches(FooterKey.SIGNED_OFF_BY)) {
final String e = footer.getEmailAddress();
if (e != null) {
sboAuthor |= author.getEmailAddress().equals(e);
sboCommitter |= committer.getEmailAddress().equals(e);
sboMe |= currentUser.getEmailAddresses().contains(e);
}
}
}