perf(mr): skip fetch in checkout when MR head is already local

Description

  • perf(mr): skip fetch in checkout when MR head is already local

Merge Request head SHA is already known from the API request. If the local branch head matches it, or the commit is present and the branch can be recreated from it, we skip fetching.

Resolves #8535 (closed)

How has this been tested?

  1. Checkout current branch with "old" glab: glab mr checkout https://gitlab.com/gitlab-org/cli/-/merge_requests/3864
  2. Compile the new one: make build
  3. Checkout main branch: git checkout main
  4. Run the new tool to try to checkout the same MR again: ./bin/glab mr checkout https://gitlab.com/gitlab-org/cli/-/merge_requests/3864

You should expect this output:

Branch "brodock/mr-checkout-smart-fetch" already at merge request head, skipping fetch.
Switched to branch 'brodock/mr-checkout-smart-fetch'

Screenshots (if appropriate):

Edited by Gabriel Mazzetto

Merge request reports

Loading
Loading