| | |
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | |
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.ClientLogger;
|
| | | import com.gitblit.utils.CommitCache;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.RefLogUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
| | | // identity of the merging user.
|
| | | boolean allRejected = false;
|
| | | for (ReceiveCommand cmd : commands) {
|
| | | String linearParent = null;
|
| | | try {
|
| | | List<RevCommit> commits = JGitUtils.getRevLog(rp.getRepository(), cmd.getOldId().name(), cmd.getNewId().name());
|
| | | for (RevCommit commit : commits) {
|
| | | |
| | | if (linearParent != null) {
|
| | | if (!commit.getName().equals(linearParent)) {
|
| | | // ignore: commit is right-descendant of a merge
|
| | | continue;
|
| | | }
|
| | | }
|
| | | |
| | | // update expected next commit id
|
| | | if (commit.getParentCount() == 0) {
|
| | | linearParent = null;
|
| | | } else {
|
| | | linearParent = commit.getParents()[0].getId().getName();
|
| | | }
|
| | | |
| | | PersonIdent committer = commit.getCommitterIdent();
|
| | | if (!user.is(committer.getName(), committer.getEmailAddress())) {
|
| | | String reason;
|
| | | if (StringUtils.isEmpty(user.emailAddress)) {
|
| | | // account does not have en email address
|
| | | reason = MessageFormat.format("{0} by {1} <{2}> was not committed by {3} ({4})", commit.getId().name(), committer.getName(), StringUtils.isEmpty(committer.getEmailAddress()) ? "?":committer.getEmailAddress(), user.getDisplayName(), user.username);
|
| | | // account does not have an email address
|
| | | reason = MessageFormat.format("{0} by {1} <{2}> was not committed by {3} ({4})", |
| | | commit.getId().name(), committer.getName(), StringUtils.isEmpty(committer.getEmailAddress()) ? "?":committer.getEmailAddress(), user.getDisplayName(), user.username);
|
| | | } else {
|
| | | // account has an email address
|
| | | reason = MessageFormat.format("{0} by {1} <{2}> was not committed by {3} ({4}) <{5}>", commit.getId().name(), committer.getName(), StringUtils.isEmpty(committer.getEmailAddress()) ? "?":committer.getEmailAddress(), user.getDisplayName(), user.username, user.emailAddress);
|
| | | reason = MessageFormat.format("{0} by {1} <{2}> was not committed by {3} ({4}) <{5}>", |
| | | commit.getId().name(), committer.getName(), StringUtils.isEmpty(committer.getEmailAddress()) ? "?":committer.getEmailAddress(), user.getDisplayName(), user.username, user.emailAddress);
|
| | | }
|
| | | logger.warn(reason);
|
| | | cmd.setResult(Result.REJECTED_OTHER_REASON, reason);
|
| | |
| | | return;
|
| | | }
|
| | | }
|
| | | |
| | | // reset branch commit cache on REWIND and DELETE
|
| | | for (ReceiveCommand cmd : commands) {
|
| | | String ref = cmd.getRefName();
|
| | | if (ref.startsWith(Constants.R_HEADS)) {
|
| | | switch (cmd.getType()) {
|
| | | case UPDATE_NONFASTFORWARD:
|
| | | case DELETE:
|
| | | CommitCache.instance().clear(repository.name, ref);
|
| | | break;
|
| | | default:
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | Set<String> scripts = new LinkedHashSet<String>();
|
| | | scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));
|