Loading
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): .gitChanges
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 tobaseRepo— 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 inrepoRemotestill runs in unrelated git repos when--push/--fillare used. Worth a separate fix — see#8407for 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 lintclean - Manual: from a non-git directory,
glab mr create --repo <owned-project> --source-branch <existing> --target-branch main --title T --description D --yescreates the MR (or fails at the API step, never at git) - Manual: from a git repo, existing
glab mr create --fillandglab mr create(interactive) still work - Manual: fork workflow
glab mr create -R upstream/project -H my-namespace/project --source-branch ...still works