Search in sources :

Example 1 with ReceivePack

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);
    }
}
Also used : TooLargeObjectInPackException(org.eclipse.jgit.errors.TooLargeObjectInPackException) AsyncReceiveCommits(com.google.gerrit.server.git.receive.AsyncReceiveCommits) Capable(com.google.gerrit.common.data.Capable) UnpackException(org.eclipse.jgit.errors.UnpackException) CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ReceivePack(org.eclipse.jgit.transport.ReceivePack) IOException(java.io.IOException)

Example 2 with ReceivePack

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();
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) AdvertiseRefsHook(org.eclipse.jgit.transport.AdvertiseRefsHook) TestRefAdvertiser(com.google.gerrit.server.git.receive.testing.TestRefAdvertiser) ReceivePack(org.eclipse.jgit.transport.ReceivePack)

Example 3 with ReceivePack

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);
    }
}
Also used : SshKey(com.gitblit.transport.ssh.SshKey) ReceivePack(org.eclipse.jgit.transport.ReceivePack)

Aggregations

ReceivePack (org.eclipse.jgit.transport.ReceivePack)3 SshKey (com.gitblit.transport.ssh.SshKey)1 Capable (com.google.gerrit.common.data.Capable)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 AsyncReceiveCommits (com.google.gerrit.server.git.receive.AsyncReceiveCommits)1 TestRefAdvertiser (com.google.gerrit.server.git.receive.testing.TestRefAdvertiser)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 IOException (java.io.IOException)1 TooLargeObjectInPackException (org.eclipse.jgit.errors.TooLargeObjectInPackException)1 UnpackException (org.eclipse.jgit.errors.UnpackException)1 TestRepository (org.eclipse.jgit.junit.TestRepository)1 Repository (org.eclipse.jgit.lib.Repository)1 AdvertiseRefsHook (org.eclipse.jgit.transport.AdvertiseRefsHook)1