Skip to content

Add Heroku-style git:remote command to create a git remote for an app #32

Description

@usiegl00

Summary

Add a Heroku-style git:remote command (and optionally auto-add a remote on apps:create) so users can wire up a git remote for deploying via git push, without manually copying the git URL.

This is a follow-up to #29, which added the git URL to apps:create output. The convention in this repo's skills docs is a remote named bld (see src/commands/skills.cr:58: git remote add bld "$GIT_URL").

Motivation

Today, after creating an app, a user has to manually run:

GIT_URL=$(bld apps:info -a my-app -j | jq -r '.git_url')
git remote add bld "$GIT_URL"
git push bld main

Heroku collapses this into heroku git:remote -a my-app (and heroku create auto-adds a heroku remote). We should match that ergonomics.

Proposed behavior

New command: bld git:remote

  • Usage: bld git:remote [APP] [-a APP] [--remote NAME]
  • Resolves the app from the positional APP argument or the -a/--app option (same pattern as apps:info in src/commands/app.cr).
  • Fetches the app via api.app(app_input) and reads app.git_url.
  • Must be run inside a git work tree (git rev-parse --is-inside-work-tree); otherwise fail with a clear message.
  • Default remote name is bld (override with --remote NAME).
  • If the remote already exists, update it (git remote set-url); otherwise add it (git remote add). Report which action was taken and the URL.
  • Fail clearly if the app has no git_url.

Example:

$ bld git:remote -a my-app
Added git remote 'bld'. Deploy with: git push bld main

Optional: auto-add remote on apps:create

To mirror heroku create, when apps:create runs inside a git repository:

  • Auto-add a bld remote pointing at the new app's git_url.
  • Add --remote NAME to choose the name and --no-remote to opt out.
  • Print a one-line confirmation (e.g. Added git remote 'bld'. Deploy with: git push bld main).

Decide during implementation whether auto-add-on-create is desired or whether the explicit git:remote command alone is preferable (auto-add changes existing apps:create behavior).

Implementation notes

  • Add shared git helpers to Build::Commands::Base (src/commands/base.cr), e.g. git_repo?, git_remote_exists?(name), set_git_remote(name, url), each shelling out via Process.run("git", [...], output: Close, error: Close). Use the args-array form (not shell: true) to avoid quoting/injection issues.
  • Register the new command in src/build_cli.cr alongside the other App::* commands.
  • The App model already exposes git_url (build-client 1.1.37), so no SDK changes are needed.

Acceptance criteria

  • bld git:remote -a my-app adds a bld remote pointing at the app's git URL inside a repo.
  • --remote NAME overrides the remote name.
  • Running an existing remote name updates it rather than erroring.
  • Clear error when not in a git repo or when the app has no git URL.
  • Decision recorded on whether apps:create auto-adds a remote (with --no-remote/--remote if so).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions