fix(mr): allow create with flag-complete inputs outside a git repo

Summary

When all inputs are provided via flags (--repo, --source-branch, --target-branch, --title, --description, --yes) and no local-context options are requested (--push, --fill, --template, or interactive prompts), mr create no longer requires a git repository.

Before this change, from a non-git directory:

$ glab mr create --repo group/project --source-branch feat --target-branch main --title Test --description Test --yes
fatal: not a git repository (or any of the parent directories): .git

Changes

Two narrow edits to internal/commands/mr/create/mr_create.go, both scoped to mr create:

  • Head repo resolution falls back to base repo. Without an explicit --head/GITLAB_HEAD_REPO, the resolver still consults local remotes so fork workflows keep auto-detecting the source. When there is no local repo (or its remotes don't resolve), we default to baseRepo — the non-fork case where source == target.
  • Git remote resolution is now lazy. Previously repoRemote(...) was called eagerly for both head and base, up front. It's now deferred to the point of use — --push, --fill, interactive template with commits, and interactive metadata prompts. The flag-complete API-only path no longer touches git remotes at all.

Also expands the mr create Example: block to follow the # comment + command pattern used by other commands (token create, cluster graph, etc.), and adds two examples for the new working shapes:

  • Non-repo MR: --repo group/project ...
  • Non-repo fork MR: --repo upstream/project --head your-namespace/project ...

Not addressed (out of scope for this change)

  • The git.AddRemote("glab-head"/"glab-base", ...) fallback in repoRemote still runs in unrelated git repos when --push/--fill are used. Worth a separate fix — see #8407 for details.
  • No new UX (-C/--directory, --no-git, etc.). This just makes the natural flag-complete invocation work.

Test plan

  • go test ./internal/commands/mr/create/... passes
  • make lint clean
  • Manual: from a non-git directory, glab mr create --repo <owned-project> --source-branch <existing> --target-branch main --title T --description D --yes creates the MR (or fails at the API step, never at git)
  • Manual: from a git repo, existing glab mr create --fill and glab mr create (interactive) still work
  • Manual: fork workflow glab mr create -R upstream/project -H my-namespace/project --source-branch ... still works

Merge request reports

Loading
Loading