glab mr checkout does not support HTTPS

Checklist

  • I'm using the latest version of the extension (Run glab --version)
    • Extension version: glab version 1.33.0 (2023-09-20)
  • Gitlab.com
  • I have performed glab auth status to check for authentication issues

Summary

glab mr checkout generates git SSH url and does not respect git_protocol set in the config. Therefore I am not able to use it without SSH key.

gitlab.com
  ✓ Logged in to gitlab.com as 1oglop1 (/Users/user/.config/glab-cli/config.yml)
  ✓ Git operations for gitlab.com configured to use https protocol.
  ✓ API calls for gitlab.com are made over https protocol
  ✓ REST API Endpoint: https://gitlab.com/api/v4/
  ✓ GraphQL Endpoint: https://gitlab.com/api/graphql/
  x No token provided

Steps to reproduce

  1. Configure git with https, and osxkeychain credential helper
  2. Create project on gitlab
  3. verify https credentials work git clone https://gitlab.com/mygroup/myproject.git
  4. Open MR with a number 1
  5. try to checkout MR with glab cli -> glab mr checkout 1

What is the current bug behavior?

Glab CLI tries to use SSH url instead of HTTPS.

[git remote -v]
[git config --get-regexp ^remote\..*\.glab-resolved$]
[git remote -v]
[git config --get-regexp ^remote\..*\.glab-resolved$]
[git remote -v]
[git config --get-regexp ^remote\..*\.glab-resolved$]
[git remote -v]
[git config --get-regexp ^remote\..*\.glab-resolved$]
[git remote -v]
[git config --get-regexp ^remote\..*\.glab-resolved$]
[git fetch git@gitlab.com:mygroup/myproject.git refs/heads/mr-branch:mr-branch]
git@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
exit status 128

What is the expected correct behavior?

checkout expected branch with git over HTTPS

Possible fixes

This should respect config git_protocol and select HTTPURLToRepo property instead of SSH https://gitlab.com/gitlab-org/cli/-/blob/6a34614218d9e27f3a2942c3729a1520c03ac1c9/commands/mr/checkout/mr_checkout.go#L77

Inspiration from https://gitlab.com/gitlab-org/cli/-/blob/main/commands/mr/create/mr_create.go#L828 might be enough to get this figured out - although I'm surprised we don't have a method for this

EDIT: There is a workaround by configuring git to rewrite URL from SSH to HTTPS #7399 (comment 1728228097)

Edited Jan 16, 2024 by Jan Gazda
Assignee Loading
Time tracking Loading