Skip to content

git remote helper drops the HTTP error body on failed push/fetch, hiding the server's rejection reason #77

Description

@beardthelion

Summary

The git remote helper discards the HTTP response body on a failed push, so the server's descriptive error never reaches the user. crates/git-remote-gitlawb/src/main.rs:297:

if !pack_resp.status().is_success() {
    bail!("POST /{} returned {}", service, pack_resp.status());
}

It reports only the status line. The JSON body (which carries the message field, e.g. the owner-push rejection "push rejected — only the repo owner may push to this repository (GITLAWB_ENFORCE_OWNER_PUSH is enabled)") is dropped.

Impact

On any non-2xx receive-pack response the user sees POST /git-receive-pack returned 403 Forbidden and nothing about why. This is pre-existing and affects every push error path, not one feature. It became more visible with the owner-push enforcement landed in #68, which returns a 403 whose body explains the rejection and what to do, none of which currently surfaces.

The same pattern is on the fetch path at main.rs:210-213 (GET /info/refs), worth fixing together.

Suggested fix

Read the body before bailing and include it when present:

if !pack_resp.status().is_success() {
    let status = pack_resp.status();
    let body = pack_resp.text().await.unwrap_or_default();
    if body.is_empty() {
        bail!("POST /{service} returned {status}");
    }
    bail!("POST /{service} returned {status}: {body}");
}

AppError serializes as {"error":"<code>","message":"..."}, so surfacing the raw body is already useful; extracting message for a cleaner line is optional.

Scope

Pre-existing, not a regression from #68. Localized to the remote helper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcrate:git-remotegit-remote-gitlawb — the git remote helpergood first issueGood for newcomerskind:bugDefect fix — wrong or unsafe behaviorsev:lowCosmetic, cleanup, or nice-to-have

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions