Skip to content

CommitAndPushFiles fails with "SHA wasn't supplied" when updating a single existing file on GitHub #188

Description

@roeioshry

When using CommitAndPushFiles to update a single file that already exists in a GitHub repository, the operation fails with:

PUT https://api.github.com/repos/{owner}/{repo}/contents/{path}: 422 Invalid request.
"sha" wasn't supplied. []

Root Cause

PR #163 introduced an optimization where single-file commits use the GitHub Contents API, while multi-file commits use the Git Data API (blobs/trees/commits).

The Contents API requires the sha parameter when updating an existing file. Currently, CommitAndPushFiles doesn't fetch the existing file's SHA before calling the Contents API, causing the error.

Steps to Reproduce

  1. Create a repository with an existing file (e.g., config.yml)
  2. Call CommitAndPushFiles with a single FileToCommit targeting that existing file
  3. Observe the 422 error

Expected Behavior

CommitAndPushFiles should successfully update the existing file by:

  1. Fetching the current file's SHA using GetContents
  2. Including the SHA in the Contents API request

Workaround

Passing 2+ files triggers the Git Data API path, which doesn't require SHA and works correctly for updates.

Environment

  • froggit-go version: v1.21.1
  • VCS Provider: GitHub

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions