Skip to content

feat: support SCP-like parent URLs with relative submodules (#492)#520

Open
raza-khan0108 wants to merge 1 commit into
coder:mainfrom
raza-khan0108:fix/492-scp-submodules
Open

feat: support SCP-like parent URLs with relative submodules (#492)#520
raza-khan0108 wants to merge 1 commit into
coder:mainfrom
raza-khan0108:fix/492-scp-submodules

Conversation

@raza-khan0108

Copy link
Copy Markdown

Support SCP-like Parent URLs with Relative Submodules

Closes #492

📝 Problem

When a parent repository uses an SCP-like Git URL (e.g., git@github.com:org/repo.git) and a submodule is configured with a relative path (e.g., ../other/submodule.git), ResolveSubmoduleURL previously converted the resolved endpoint into a standard SSH protocol URL (ssh://git@github.com/org/other/submodule.git).

While ssh://... is a valid protocol, converting an SCP-like URL into an ssh:// URL causes Git over SSH to request an absolute path on the remote server (/org/other/submodule.git starting from /) instead of a relative path (org/other/submodule.git relative to the login user's home directory or Git root). This breaks submodule cloning on standard and self-hosted Git SSH servers (e.g., GitLab, Gitea, standard SSH git accounts) and alters the user's configured protocol style.


💡 Proposed Solution

This PR implements step 4 of the proposed solution in #492 by preserving SCP-like syntax when resolving submodule URLs:

  1. Detects whether the input parentURL lacks a URL scheme (!strings.Contains(parentURL, "://")).
  2. Introduces a reconstructSCP helper function to format a transport.Endpoint struct back into standard SCP syntax (user@host:path or user@host:port:path) without injecting a leading slash into the remote repository path.
  3. Updates existing unit test expectations and introduces new test cases covering SCP-like URLs without user components and with IP addresses.

🛠️ Key Changes

git/git.go

  • Added reconstructSCP(ep *transport.Endpoint) string: Formats endpoint components into SCP syntax while trimming leading slashes on the remote path.
  • Updated ResolveSubmoduleURL: Checks if parentURL is an SCP-like URL. If true, returns reconstructSCP(parentEP) instead of .String().

git/git_test.go

  • Updated expectations for existing SCP test cases (scpRelativeSibling, scpRelativeChild, scpMultiLevelUp, scpWithPort) from ssh://... to git@github.com:....
  • Added scpNoUserRelativeSibling: Verifies SCP URLs without a user component (github.com:org/deps/lib.git).
  • Added scpIPAddressRelativeSibling: Verifies SCP URLs using IP addresses and deploy users (deploy@192.168.1.50:repos/deps/lib.git).

🧪 Verification & Examples

Parent URL Submodule Path Previous Resolution New Resolution
git@github.com:org/main.git ../deps/lib.git ssh://git@github.com/org/deps/lib.git git@github.com:org/deps/lib.git
git@github.com:2222:org/main.git ../deps/lib.git ssh://git@github.com:2222/org/deps/lib.git git@github.com:2222:org/deps/lib.git
github.com:org/main.git ../deps/lib.git ssh://github.com/org/deps/lib.git github.com:org/deps/lib.git

✅ Checklist

  • Code compiles and adheres to coding standards
  • Unit tests updated and new test cases added for SCP resolution
  • Tested against multi-level and custom-port SCP URLs
  • Documentation and walkthrough updated

Copilot AI review requested due to automatic review settings July 3, 2026 18:36

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.

Pull request overview

This PR updates ResolveSubmoduleURL to preserve SCP-like Git URL syntax when resolving relative submodule URLs, avoiding conversion to ssh://... which can change remote path semantics and break submodule cloning on some SSH servers.

Changes:

  • Added reconstructSCP(*transport.Endpoint) to format resolved endpoints back into SCP-like syntax.
  • Updated ResolveSubmoduleURL to return SCP-like output for scheme-less parent URLs.
  • Updated and expanded unit tests to expect SCP-like outputs and cover additional SCP input variants (no user, IP address).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
git/git.go Adds SCP reconstruction helper and changes ResolveSubmoduleURL output formatting for scheme-less parent URLs.
git/git_test.go Updates SCP-related expectations and adds new SCP-oriented test cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread git/git.go
Comment on lines 578 to 583
// Reconstruct the URL with the resolved path.
parentEP.Path = path.Clean(currentPath)
if !strings.Contains(parentURL, "://") {
return reconstructSCP(parentEP), nil
}
return parentEP.String(), nil
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.

Support SCP-like parent URLs with relative submodules

2 participants