checkout MR fails if remote has diverged

Checklist

  • I'm using the latest version of the extension (Run glab --version)
    • Extension version: Put your extension version here
  • Operating system and version: Debian 11
  • Gitlab.com or self-managed instance? both
  • GitLab version (if self-managed) GitLab version here (Use the version endpoint, like this: gitlab.my-company.com/api/v4/version)
  • I have performed glab auth status to check for authentication issues
  • Run the command in debug mode (like DEBUG=true glab mr list) and attach any useful output

Summary

checkout MR fails if remote has diverged

Environment

  • OS: Linux 6.1.0-0.deb11.7-amd64 x86_64
  • SHELL: /bin/bash
  • TERM: xterm-256color
  • GLAB: glab 1.57.0 (8f5367a0)

Other:

Steps to reproduce

  • clone a same repo into two folders -- folder1 and folder2
  • create a new branch branchA in folder1 and create a merge request
  • checkout the MR in folder2 using glab
  • make changes in folder1 and make the history diverged by git commit --amend and force push
  • checkout main branch in folder2
  • checkout the MR in folder2 using glab

What is the current bug behavior?

If the remote has diverged from the local branches, glab mr checkout will fail.

the cause is during checkout, the cli invokes git fetch git@gitlab.com/xxx/yyy.git refs/heads/branchA:branchA trying to update the local ref to the remote.

but this happens if the remote has diverged

! [rejected]        branchA -> branchA  (non-fast-forward)

What is the expected correct behavior?

glab mr checkout works

Relevant logs and/or screenshots

Possible fixes

Assignee Loading
Time tracking Loading