#16099

cli: support attaching files to `but pr new` (like `gh pr create --attach`)

OpenBartInTheFieldopened 1mo ago

The desktop app and Lite both let you attach images and other files to a PR description (paste, drop, or the attach button). The files are uploaded to gitbutler.com and linked from the body as markdown. but pr new has no way to do this, so from the CLI the only options are hand-hosting an image or editing the PR on the forge afterwards.

gh pr create already has this as --attach, and but could follow the same shape:

but pr new my-branch -m "Fix login" --attach './login.png#The login error state'
but pr new my-branch -F pr.md --attach ./before.png --attach ./after.png

Proposed behavior

  • --attach <FILE[#ALT]>, repeatable, long form only (gh uses -a for --assignee).
  • Images are appended to the body as ![alt](url), where alt defaults to the filename. Other files are appended as [name](url), matching what the apps insert.
  • If the body already references an attached file's path, for example ![alt](./login.png), that reference is rewritten to the uploaded URL instead of appending a duplicate (as gh does).
  • Works with every body source: -m, -F, -t, and the editor.
  • In a stack, attachments apply only to the selected branch's review, the same way -m does today.
  • All or nothing: check that every file exists, that each is under the 10 MB upload limit, and that the user is signed in before pushing. If any upload fails, stop before creating the review. gh creates the PR with whichever uploads succeeded; failing early avoids leaving a half-illustrated PR to fix by hand.
  • No confirmation prompt: naming the files is the consent. The --help text says that uploads are public, since the forge has to be able to load them.

Notes

  • The upload itself already exists: gitbutler_user::api::upload_file (crates/gitbutler-user/src/api.rs), used by the apps through but_api::legacy::users::upload_file. No backend changes should be needed.
  • The CLI has no GitButler sign-in of its own; it uses the account stored by the desktop app or Lite. A signed-out run should fail early and point the user at signing in there. A but login command would be a separate change.
  • Likely touch points: crates/but/src/args/forge.rs, crates/but/src/lib.rs, crates/but/src/command/legacy/forge/review.rs, and the skill docs under crates/but/skill/.

Activity

0

No activity yet.