feat: support SCP-like parent URLs with relative submodules (#492)#520
Open
raza-khan0108 wants to merge 1 commit into
Open
feat: support SCP-like parent URLs with relative submodules (#492)#520raza-khan0108 wants to merge 1 commit into
raza-khan0108 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
ResolveSubmoduleURLto 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 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 |
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.
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),ResolveSubmoduleURLpreviously 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 anssh://URL causes Git over SSH to request an absolute path on the remote server (/org/other/submodule.gitstarting from/) instead of a relative path (org/other/submodule.gitrelative 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:
parentURLlacks a URL scheme (!strings.Contains(parentURL, "://")).reconstructSCPhelper function to format atransport.Endpointstruct back into standard SCP syntax (user@host:pathoruser@host:port:path) without injecting a leading slash into the remote repository path.🛠️ Key Changes
git/git.goreconstructSCP(ep *transport.Endpoint) string: Formats endpoint components into SCP syntax while trimming leading slashes on the remote path.ResolveSubmoduleURL: Checks ifparentURLis an SCP-like URL. If true, returnsreconstructSCP(parentEP)instead of.String().git/git_test.goscpRelativeSibling,scpRelativeChild,scpMultiLevelUp,scpWithPort) fromssh://...togit@github.com:....scpNoUserRelativeSibling: Verifies SCP URLs without a user component (github.com:org/deps/lib.git).scpIPAddressRelativeSibling: Verifies SCP URLs using IP addresses and deploy users (deploy@192.168.1.50:repos/deps/lib.git).🧪 Verification & Examples
git@github.com:org/main.git../deps/lib.gitssh://git@github.com/org/deps/lib.git❌git@github.com:org/deps/lib.git✅git@github.com:2222:org/main.git../deps/lib.gitssh://git@github.com:2222/org/deps/lib.git❌git@github.com:2222:org/deps/lib.git✅github.com:org/main.git../deps/lib.gitssh://github.com/org/deps/lib.git❌github.com:org/deps/lib.git✅✅ Checklist