Handles SCP-like URLs that don't begin with git@ - #157
Conversation
andrew
left a comment
There was a problem hiding this comment.
Two regressions need fixes before merge:
ParseRepoURLnow strips the scheme before checking SCP syntax. A remote such ashttps://user:token@github.com/owner/repo.gitresolves to domainuser, and bracketed IPv6 addresses split at the first address colon. Both inputs work onmain. Keep inputs containing://on thenet/urlpath.- The numeric-port heuristic rejects
git@github.com:123/repo.git, although123is the repository owner. An@before the separator makes this unambiguously SCP syntax, so the port heuristic should not apply.
Please add regression coverage through resolve.Repo with a real temporary Git remote. The current tests only call ParseRepoURL directly.
There was a problem hiding this comment.
🟡 Changes recommended
splitSCPLike can currently accept malformed inputs with an empty host and return a successful parse result (domain == ""), which should be rejected.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes repository remote URL parsing to support SCP-like SSH remotes that don’t start with git@ (e.g. org-12345@github.com:owner/repo.git), preventing schemeless URLs from being misinterpreted as https://... with an invalid :owner “port”.
Changes:
- Extend
ParseRepoURLto recognize SCP-likeuser@host:pathandhost:pathformats via a newsplitSCPLikehelper. - Add unit tests covering additional remote URL shapes (arbitrary SSH user, schemeless SCP-like, HTTPS userinfo, bracketed IPv6 via
ssh://). - Add an integration-style resolver test that exercises
Repo()against realgit remotevalues.
File summaries
| File | Description |
|---|---|
forge.go |
Adds SCP-like parsing support to ParseRepoURL via splitSCPLike. |
forges_test.go |
Expands ParseRepoURL test cases to cover SCP-like and userinfo variants. |
internal/resolve/resolve_test.go |
Adds a git-backed resolver test to ensure Repo() resolves varied remote URL formats. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if at >= 0 { | ||
| host = host[at+1:] | ||
| } | ||
| return host, path, true |
There was a problem hiding this comment.
🔵 Needs a closer look
splitSCPLike currently mis-parses bracketed-IPv6 scp-like remotes (separator colon detection and bracket stripping), which can break domain extraction and lookup.
Review details
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
forge.go:365
- splitSCPLike will mis-parse scp-like remotes that use a bracketed IPv6 host (e.g. "git@[2001:db8::1]:owner/repo") because it finds the first ':' which occurs inside the IPv6 literal instead of the host/path separator colon.
This issue also appears on line 390 of the same file.
forges_test.go:94
- The new scp-like parsing logic isn’t covered by a bracketed-IPv6 scp-like test case ("git@[2001:db8::1]:owner/repo.git"). Adding it would prevent regressions in splitSCPLike’s IPv6 handling.
forge.go:396
- For scp-like remotes with bracketed IPv6 hosts, splitSCPLike currently returns the host including brackets (e.g. "[2001:db8::1]") which won’t match the hostname form returned by url.URL.Hostname() ("2001:db8::1") and can break domain-based lookup.
if at >= 0 {
host = host[at+1:]
}
if host == "" {
return "", "", false
}
return host, path, true
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
andrew
left a comment
There was a problem hiding this comment.
The parsing regressions are fixed. SCP-like remotes now handle arbitrary SSH users, numeric owners, empty hosts, and bracketed IPv6, with coverage through the Git remote resolution path.
|
Thanks for getting this over the line! |
The SSH user may not be
git, for example on GitHub it may look likeorg-12345when dealing with org repos.This would leads to error like that when working on a repository cloned with such a remote URL: