Skip to content

Handles SCP-like URLs that don't begin with git@ - #157

Merged
andrew merged 4 commits into
git-pkgs:mainfrom
MatMaul:generic-scp-url
Sep 2, 2026
Merged

Handles SCP-like URLs that don't begin with git@#157
andrew merged 4 commits into
git-pkgs:mainfrom
MatMaul:generic-scp-url

Conversation

@MatMaul

@MatMaul MatMaul commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

The SSH user may not be git, for example on GitHub it may look like org-12345 when dealing with org repos.

This would leads to error like that when working on a repository cloned with such a remote URL:

forge pr checkout 14

Error: parsing remote "origin" URL: invalid URL: parse "https://org-12345@github.com:myorg/myrepo.git": invalid port ":myorg" after host

@andrew andrew 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.

Two regressions need fixes before merge:

  • ParseRepoURL now strips the scheme before checking SCP syntax. A remote such as https://user:token@github.com/owner/repo.git resolves to domain user, and bracketed IPv6 addresses split at the first address colon. Both inputs work on main. Keep inputs containing :// on the net/url path.
  • The numeric-port heuristic rejects git@github.com:123/repo.git, although 123 is 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 ParseRepoURL to recognize SCP-like user@host:path and host:path formats via a new splitSCPLike helper.
  • 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 real git remote values.
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.

Comment thread forge.go
Comment on lines +390 to +393
if at >= 0 {
host = host[at+1:]
}
return host, path, true

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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 andrew 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.

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.

@andrew
andrew merged commit e5991b6 into git-pkgs:main Sep 2, 2026
4 checks passed
@MatMaul

MatMaul commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for getting this over the line!

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.

3 participants