fix(mr): explain missing local refs when using --fill

Summary

When glab mr create --fill cannot read the local commit range, check which refs Git cannot resolve. Name the missing refs and explain how to proceed. This covers detached CI checkouts and preserves the underlying Git error. Successful autofill continues to read commits the same way.

Closes #7437 (closed).

Validation

  • Reproduced the raw ambiguous-revision error with a real detached Git checkout and missing local refs.
  • The regression test verifies the ref names and guidance. The merge-request creation and Git package suites passed, as did focused Go lint and git diff --check.

AI assistance was used to prepare and validate this change.

/copy_metadata #7437 (closed) /assign me

Command output from local validation

Captured on the main-side and MR command sources in an isolated CLI harness. GitLab API responses were mocked where applicable.

Main

$ glab mr create --source-branch topic --target-branch main --yes --push=false --head demo/upstream --fill
fatal: ambiguous argument 'origin/main...topic': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
git: exit status 128
exit=1

MR

$ glab mr create --source-branch topic --target-branch main --yes --push=false --head demo/upstream --fill
cannot use --fill because Git cannot resolve "origin/main", "topic". To continue, fetch or create these refs locally, or pass --title and --description without --fill
fatal: ambiguous argument 'origin/main...topic': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
git: exit status 128
exit=1

AI assistance was used to prepare and verify this example.

Test fixture follow-up

Commit 85ed2aa uses the shared Git fixture setup in both tests and checks that CommitRefMissing("HEAD") returns false in an initialized repository.

I ran the tests with GIT_DIR, GIT_WORK_TREE, and GIT_INDEX_FILE pointing to a separate repository with a missing-branch ref. TestCommitRefMissing failed on the prior revision. Both updated tests passed with those variables set, and the focused ref and autofill tests passed with the Go race detector.

The broader local mr create package run hit two interactive template prompt timeouts. Both also reproduced on the unchanged merge request head. AI assisted with the follow-up and validation.

Edited by Himanshu Jha

Merge request reports

Loading
Loading