Sitelet https://web.archive.org/web/20260610201042/https://github.com/cli/cli/pull/2177
Skip to content

Clone repos using canonical username/repo name capitalization#2177

Merged
samcoe merged 3 commits into
cli:trunkfrom
jonathanlloyd:use-canonical-capitalization-in-remotes
Oct 20, 2020
Merged

Clone repos using canonical username/repo name capitalization#2177
samcoe merged 3 commits into
cli:trunkfrom
jonathanlloyd:use-canonical-capitalization-in-remotes

Conversation

@jonathanlloyd

Copy link
Copy Markdown
Contributor

GitHub user/repo names are case insentitive. This can cause issues when dealing with
repos programmatically using systems that aren't aware of this (e.g. go packages).

This commit updates the cloning logic of the CLI to query the API for the canonical
capitalization and uses that for the clone operation.

Fixes: #1845

GitHub user/repo names are case insentitive. This can cause issues when dealing with
repos programmatically using systems that aren't aware of this (e.g. go packages).

This commit updates the cloning logic of the CLI to query the API for the canonical
capitalization and uses that for the clone operation.

Fixes: cli#1845
@jonathanlloyd jonathanlloyd force-pushed the use-canonical-capitalization-in-remotes branch from 82aff39 to a5ec03d Compare October 12, 2020 22:57

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thank you for the contribution 🙇

Comment thread pkg/cmd/repo/clone/clone.go Outdated
cloneDir, err := git.RunClone(cloneURL, opts.GitArgs)
// If the repo is a fork, add the parent as an upstream
var parentRepo ghrepo.Interface
parentRepo, err = api.RepoParent(apiClient, canonicalRepo)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're already making an API request in GitHubRepo() above, a potential improvement here could be to expand (or rather, duplicate) that query to also include its parent repository in the response. That way we could get the information about the repo + its parent in a single request.

You are welcome to amend this PR if you're willing to add this tiny optimization, but you can also leave it as-is and our team can get to this as well. 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a change that achieves this by loading the parent in the GitHubRepo query - it does mean grabbing a few more bytes than required if you don't care about the parent, but I thought it might be good practice because otherwise the parent (which was already in the model) would be nil - this could cause a bug by implying that the repo isn't a fork (when it is).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh repo clone doesn't use canonical capitalisation for remote URL

3 participants