Repository navigation
Keep a leading ssh. endpoint out of the project path - #23
Merged
Merged
Conversation
A forge that moves Git over SSH to a subdomain (bitbucket.org -> ssh.bitbucket.org, and GitHub's ssh.github.com) produced a second tree next to the repository that already existed, because the host went into the path exactly as written. processOneRepository only checks whether the computed directory is non-empty, so the duplicate was cloned again instead of reporting "repository already exists". The leading ssh label now marks a transport endpoint rather than a service name: it is dropped before the path is built, and the host is lowercased in every mode. Hosts without that label keep their directory untouched, so self-hosted instances (git.example.com) are unaffected. --full-host keeps the label for hosts where ssh.<domain> serves a different repository than <domain>. The URL cache is keyed per mode so one URL cannot be served from the wrong normalization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
The host of a repository URL used to go into the project path exactly as written, so a forge that serves Git over SSH on a subdomain produced a second tree next to the repository that already existed:
git@ssh.bitbucket.org:team/service.gitssh.bitbucket.org/team/servicebitbucket.org/team/servicessh://git@ssh.bitbucket.org:443/team/service.gitssh.bitbucket.org/team/servicebitbucket.org/team/servicessh://git@ssh.github.com:443/juev/gclone.gitssh.github.com/juev/gclonegithub.com/juev/gclonegit@SSH.BitBucket.ORG:team/service.gitSSH.BitBucket.ORG/team/servicebitbucket.org/team/servicegit@git.example.com:team/service.gitgit.example.com/team/serviceA leading
sshlabel marks an SSH endpoint of the service, not a service of its own, so it is dropped before the path is built; a host without that label keeps its directory exactly. The host is lowercased in every mode, since a hostname is case-insensitive and an uppercase host used to add a third spelling of the same tree.--full-hostkeeps the label for the rare host wheressh.<domain>serves a different repository than<domain>.normalizeandgetProjectDirtake anormalizeOptionsvalue now, and the URL cache is keyed per mode so one URL cannot be served from the wrong normalization.Background and the full acceptance list: closes #22.
Verification
go test ./...passes, including new cases for the SSH forms, an uppercase host,--full-host, the whole rule (Test_projectHost) and cache separation between the two modes.TestNormalizeSecurityandTestGetProjectDirSecurityare untouched and green.golangci-lint runreports the same 17goconstfindings asmainand none from this change.End-to-end with the built binary and a real clone:
Notes
altssh.gitlab.com, GitLab's SSH-over-443 endpoint, does not start withssh.and keeps its own directory; if that ever matters the rule becomes a set of leading labels.ssh.<host>during a forge's brownout window keeps its tree, and a later clone through<host>creates a second one. The README documents the rule; a migration helper is out of scope here.