use of org.eclipse.jgit.transport.ReceivePack in project gerrit by GerritCodeReview.
the class Receive method runImpl.
@Override
protected void runImpl() throws IOException, Failure {
CurrentUser currentUser = session.getUser();
try {
permissionBackend.user(currentUser).project(project.getNameKey()).check(ProjectPermission.RUN_RECEIVE_PACK);
} catch (AuthException e) {
throw new Failure(1, "fatal: receive-pack not permitted on this server", e);
} catch (PermissionBackendException e) {
throw new Failure(1, "fatal: unable to check permissions " + e);
}
AsyncReceiveCommits arc = factory.create(projectState, currentUser.asIdentifiedUser(), repo, null);
try {
Capable r = arc.canUpload();
if (r != Capable.OK) {
throw die(r.getMessage());
}
} catch (PermissionBackendException e) {
throw die(e.getMessage());
}
ReceivePack rp = arc.getReceivePack();
try {
rp.receive(in, out, err);
session.setPeerAgent(rp.getPeerUserAgent());
} catch (UnpackException badStream) {
// 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(projectState.getName()).append("\"");
msg.append(" (user ");
msg.append(currentUser.getUserName().orElse(null));
msg.append(" account ");
msg.append(currentUser.getAccountId());
msg.append("): ");
msg.append(badStream.getCause().getMessage());
logger.atInfo().log(msg.toString());
throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage());
}
StringBuilder msg = new StringBuilder();
msg.append("Unpack error on project \"").append(projectState.getName()).append("\":\n");
msg.append(" AdvertiseRefsHook: ").append(rp.getAdvertiseRefsHook());
if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) {
msg.append("DEFAULT");
} else {
msg.append(rp.getAdvertiseRefsHook().getClass());
}
msg.append("\n");
IOException detail = new IOException(msg.toString(), badStream);
throw new Failure(128, "fatal: Unpack error, check server log", detail);
}
}
use of org.eclipse.jgit.transport.ReceivePack in project gerrit by GerritCodeReview.
the class RefAdvertisementIT method getReceivePackRefs.
private TestRefAdvertiser.Result getReceivePackRefs() throws Exception {
try (Repository repo = repoManager.openRepository(project)) {
AdvertiseRefsHook adv = ReceiveCommitsAdvertiseRefsHookChain.createForTest(queryProvider, project, identifiedUserFactory.create(admin.id()));
ReceivePack rp = new ReceivePack(repo);
rp.setAdvertiseRefsHook(adv);
TestRefAdvertiser advertiser = new TestRefAdvertiser(repo);
rp.sendAdvertisedRefs(advertiser);
return advertiser.result();
}
}
use of org.eclipse.jgit.transport.ReceivePack in project gitblit by gitblit.
the class Receive method runImpl.
@Override
protected void runImpl() throws Failure {
SshKey key = getContext().getClient().getKey();
if (key != null && !key.canPush()) {
throw new Failure(1, "Sorry, your SSH public key is not allowed to push changes!");
}
try {
ReceivePack rp = receivePackFactory.create(getContext().getClient(), repo);
rp.receive(in, out, null);
} catch (Exception e) {
throw new Failure(1, "fatal: Cannot receive pack: ", e);
}
}
Aggregations