List of usage examples for org.eclipse.jgit.transport ReceivePack setRefLogIdent
public void setRefLogIdent(PersonIdent pi)
From source file:com.cisco.step.jenkins.plugins.jenkow.JenkowWorkflowRepository.java
License:Open Source License
/** * Requires the admin access to be able to push *///w w w. j a v a2s . c om @Override public ReceivePack createReceivePack(HttpServletRequest context, Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { Authentication a = Jenkins.getAuthentication(); ReceivePack rp = createReceivePack(db); rp.setRefLogIdent(new PersonIdent(a.getName(), a.getName() + "@" + context.getRemoteAddr())); return rp; }
From source file:com.google.gerrit.sshd.commands.Receive.java
License:Apache License
@Override protected void runImpl() throws IOException, Failure { if (!projectControl.canRunReceivePack()) { throw new Failure(1, "fatal: receive-pack not permitted on this server"); }/* w ww .j a v a 2s . co m*/ final ReceiveCommits receive = factory.create(projectControl, repo).getReceiveCommits(); Capable r = receive.canUpload(); if (r != Capable.OK) { throw new UnloggedFailure(1, "\nfatal: " + r.getMessage()); } verifyProjectVisible("reviewer", reviewerId); verifyProjectVisible("CC", ccId); receive.addReviewers(reviewerId); receive.addExtraCC(ccId); final ReceivePack rp = receive.getReceivePack(); rp.setRefLogIdent(currentUser.newRefLogIdent()); rp.setTimeout(config.getTimeout()); rp.setMaxObjectSizeLimit(config.getEffectiveMaxObjectSizeLimit(projectControl.getProjectState())); init(rp); rp.setPostReceiveHook(PostReceiveHookChain.newChain(Lists.newArrayList(postReceiveHooks))); try { rp.receive(in, out, err); } catch (UnpackException badStream) { // In case this was caused by the user pushing an object whose size // is larger than the receive.maxObjectSizeLimit gerrit.config parameter // we want to present this error to the user if (badStream.getCause() instanceof TooLargeObjectInPackException) { StringBuilder msg = new StringBuilder(); msg.append("Receive error on project \"").append(projectControl.getProject().getName()) .append("\""); msg.append(" (user "); msg.append(currentUser.getAccount().getUserName()); msg.append(" account "); msg.append(currentUser.getAccountId()); msg.append("): "); msg.append(badStream.getCause().getMessage()); log.info(msg.toString()); throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage()); } // This may have been triggered by branch level access controls. // Log what the heck is going on, as detailed as we can. // StringBuilder msg = new StringBuilder(); msg.append("Unpack error on project \"").append(projectControl.getProject().getName()).append("\":\n"); msg.append(" AdvertiseRefsHook: ").append(rp.getAdvertiseRefsHook()); if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) { msg.append("DEFAULT"); } else if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) { msg.append("VisibleRefFilter"); } else { msg.append(rp.getAdvertiseRefsHook().getClass()); } msg.append("\n"); if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) { Map<String, Ref> adv = rp.getAdvertisedRefs(); msg.append(" Visible references (").append(adv.size()).append("):\n"); for (Ref ref : adv.values()) { msg.append(" - ").append(ref.getObjectId().abbreviate(8).name()).append(" ") .append(ref.getName()).append("\n"); } Map<String, Ref> allRefs = rp.getRepository().getRefDatabase().getRefs(RefDatabase.ALL); List<Ref> hidden = new ArrayList<>(); for (Ref ref : allRefs.values()) { if (!adv.containsKey(ref.getName())) { hidden.add(ref); } } msg.append(" Hidden references (").append(hidden.size()).append("):\n"); for (Ref ref : hidden) { msg.append(" - ").append(ref.getObjectId().abbreviate(8).name()).append(" ") .append(ref.getName()).append("\n"); } } IOException detail = new IOException(msg.toString(), badStream); throw new Failure(128, "fatal: Unpack error, check server log", detail); } }
From source file:com.sonatype.sshjgit.core.gitcommand.Receive.java
License:Apache License
@Override protected void runImpl() throws IOException, Failure { final Subject subject = SecurityUtils.getSubject(); subject.checkPermission("gitrepo:push:" + getRepoNameAsPermissionParts(repo)); ReceivePack rp = new ReceivePack(repo); rp.setAllowCreates(true);// w w w .ja v a 2 s . c o m final boolean mayNonFastForward = subject .isPermitted("gitrepo:non-fast-forward:" + getRepoNameAsPermissionParts(repo)); rp.setAllowDeletes(mayNonFastForward); rp.setAllowNonFastForwards(mayNonFastForward); rp.setCheckReceivedObjects(true); // TODO make this be a real email address! final String name; final Object principal = subject.getPrincipal(); if (principal == null) { name = "null_principal"; log.warn("principal was null when trying to setRefLogIdent on repo."); } else { name = principal.toString(); } log.info("setting LogIdent to " + name); rp.setRefLogIdent(new PersonIdent(name, name + "@example.com")); rp.receive(in, out, err); }