Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh repo clone https://github.com/xxx/yyy should respect git_protocol config rather than using the protocol scheme #9026

Open
alexjurkiewicz opened this issue Apr 30, 2024 · 4 comments
Labels
blocked enhancement a request to improve CLI gh-repo relating to the gh repo command

Comments

@alexjurkiewicz
Copy link

Describe the bug

When cloning a repository by the Github web UI URL, git_protocol is not respected.

❯ gh --version
gh version 2.48.0 (2024-04-17)
https://github.com/cli/cli/releases/tag/v2.48.0
❯ gh config set git_protocol ssh
❯ gh repo clone https://github.com/xxx/yyy
Cloning into 'reporting'...
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/xxx/yyy.git/'
failed to run git: exit status 128

Expected vs actual behavior

I would expect gh to respect git_protocol, which it does when you specify gh repo clone xxx/yyy

Thank you!!

@alexjurkiewicz alexjurkiewicz added the bug Something isn't working label Apr 30, 2024
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Apr 30, 2024
@alexjurkiewicz alexjurkiewicz changed the title gh repo clone https://github.com/xxx/yyy doesn't respect git_protocol gh repo clone https://github.com/xxx/yyy doesn't respect git_protocol Apr 30, 2024
@williammartin
Copy link
Member

Hey, thanks for the bug report.

If you provide the full URL including protocol then that will override your configured git_protocol. I've created a PR here that documents this behaviour: #9030, could you have a look and tell me if it makes sense?

@alexjurkiewicz
Copy link
Author

Thanks William. IMO, the URL form https://github.com/xxx/yyy should respect git_protocol. If you want to explicitly use https protocol, it's possible to use the "real" HTTPS URL, https://github.com/xxx/yyy.git.

My use case is that I'd like to easily copy and paste URLs from my web browser into my terminal, and have git_protocol respected.

@cli cli deleted a comment Apr 30, 2024
@williammartin
Copy link
Member

williammartin commented Apr 30, 2024

I hear you. That might be a reasonable approach but unfortunately this has been the behaviour since the command was first introduced and changing it would be backwards incompatible.

The best thing I can suggest is that you use a gh alias like so:

gh alias set --shell repo-clone 'gh repo clone ${1#https://github.com/}'

This performs a shell parameter expansion to remove https://github.com. Then you can call:

gh repo-clone https://github.com/xxx/yyy

and it will functionally act as:

gh repo clone xxx/yyy

@williammartin williammartin added the gh-repo relating to the gh repo command label Apr 30, 2024
@williammartin williammartin added enhancement a request to improve CLI blocked and removed bug Something isn't working needs-triage needs to be reviewed labels Apr 30, 2024
@williammartin williammartin changed the title gh repo clone https://github.com/xxx/yyy doesn't respect git_protocol gh repo clone https://github.com/xxx/yyy should respect git_protocol config rather than using the protocol scheme Apr 30, 2024
@williammartin
Copy link
Member

I've updated the title and labels to better reflect your request and updated the docs in #9030 to make it clear what the current behaviour is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked enhancement a request to improve CLI gh-repo relating to the gh repo command
Projects
None yet
Development

No branches or pull requests

4 participants
@alexjurkiewicz @williammartin @cliAutomation and others