feat: add subfolder and ssh_host support for GitLab instances
Description
This MR adds support for GitLab instances hosted in subfolders (e.g., example.com/gitlab) and alternate SSH hostnames (e.g., ssh.example.com).
Key Changes
-
New Config Fields:
-
subfolder: For HTTP/API subfolder paths (e.g.,gitlabinexample.com/gitlab) -
ssh_host: For alternate SSH hostnames (e.g.,ssh.example.comorgit.example.com) - Both fields support environment variables:
GITLAB_SUBFOLDER,GITLAB_SSH_HOST
-
-
Auth Login Enhancement:
- Automatically splits
--hostname example.com/gitlabinto hostname + subfolder - Auto-detects SSH hostname from git remotes and prompts user
- Stores config with bare hostname as key
- Automatically splits
-
Remote Resolution:
- Maps SSH hosts to config entries for proper remote recognition
- Allows git remotes with different SSH hostnames to be recognized
-
URL Construction:
- Simplified URL parsing in
FromURL()with cleaner logic - Fixed GraphQL endpoint to support
api_hostandsubfolder(was previously broken) - Updated all
APIEndpoint/GraphQLEndpointcall sites
- Simplified URL parsing in
-
Backward Compatibility:
- Existing
api_hostwith paths continues working - Subfolder extracted from
api_hostautomatically ifsubfolderfield is empty
- Existing
Root Cause
When users ran glab auth login --hostname example.com/gitlab, it created a config key example.com/gitlab. However, git remote URLs extract bare hostname example.com, causing a mismatch in remote resolution where the knownHosts check would fail.
Solution
Now stores config with bare hostname as key and subfolder separately, allowing git remotes to be correctly recognized as authenticated hosts.
Related Issues
-
Closes #7920 (closed)
-
Closes #7879 (closed)
-
Closes #7641 (closed)
-
Closes #8146 (closed)
-
Supersedes !2820 (closed)
-
Supersedes !2782 (closed)
How has this been tested?
Automated Tests:
-
✅ All existing tests pass -
✅ glinstance tests (URL construction with subfolder) -
✅ glrepo tests (simplified URL parsing) -
✅ auth login tests (hostname splitting) -
✅ auth status tests (display new fields) -
✅ cmdutils tests (remote resolution with SSH mapping) -
✅ API client tests (client initialization) -
✅ Build compiles successfully
Testing Scenarios:
- Auth login with subfolder input
- Git remotes with subfolder paths are recognized
- SSH host detection and configuration
- Mixed remotes (HTTP + SSH) both resolve correctly
- Backward compatibility with existing
api_hostconfigurations - GraphQL commands work with subfolders (bug fix)