fix: do not authenticate to the default host when cloning from a full URL
What does this MR do?
glab repo clone with a full URL argument no longer authenticates to the default host. A full URL is handed straight to git, so a plain clone now makes no API call at all.
--wiki is the one case that still needs the API, to resolve the project. For a full URL it now parses the URL with glrepo.FromURL (through the cloneRepo helper) and builds its API client for the URL's host, with any configured subfolder stripped from the project path.
Before and after
Before, every clone called CurrentUser() against the default host (gitlab.com, or GITLAB_HOST), even for a full URL that git clones without glab's help. So glab repo clone https://other-instance/group/project failed with GET https://gitlab.com/api/v4/user: 401 whenever the default host had no valid token (#1270 (closed)). --wiki with a full URL also queried the default host for the project.
After, a plain full-URL clone makes no API call and is passed to git as-is. --wiki with a full URL authenticates to the URL's host using the credentials configured for that host. Cloning by owner/repo or project ID is unchanged.
How to validate locally
- Point the default host somewhere without a valid token, for example
GITLAB_HOST=gitlab.example.invalid. - Run
glab repo clone https://gitlab.com/<group>/<project>and confirm it clones without any API call. - With a token for the URL's host configured, run
glab repo clone --wiki https://that-instance/group/projectand confirm it authenticates and clones the wiki. - Run
go test ./internal/commands/project/clone/..., which covers the plain URL (no API call), the wiki host, and the subfolder case.
Acceptance checklist
- Plain URL clone makes no API call
- Wiki clone from a full URL uses the URL's host
-
owner/repoand default-host behavior unchanged - Command-level tests added
Closes #1270 (closed)