Skip to content

Commit ad64adf

Browse files
Document SCP-like URL limitation for relative submodules
- Add explicit check for SCP-like parent URLs when resolving relative submodules - Return clear error message with link to tracking issue - Document limitation in function doc comment - Add test cases for SCP parent with relative and absolute submodule URLs Addresses review feedback from johnstcn.
1 parent 6f87394 commit ad64adf

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

git/git.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,22 @@ func RedactURL(u string) string {
499499
}
500500

501501
// ResolveSubmoduleURL resolves a potentially relative submodule URL against a parent repository URL.
502+
//
503+
// Limitation: SCP-like URLs (e.g., git@github.com:org/repo.git) are not supported as parent URLs
504+
// when the submodule uses a relative path. This is a known limitation.
505+
// See: https://github.com/coder/envbuilder/issues/487
502506
func ResolveSubmoduleURL(parentURL, submoduleURL string) (string, error) {
503507
// If the submodule URL is absolute (contains ://) or doesn't start with ./ or ../, return it as-is
504508
if strings.Contains(submoduleURL, "://") || (!strings.HasPrefix(submoduleURL, "../") && !strings.HasPrefix(submoduleURL, "./")) {
505509
return submoduleURL, nil
506510
}
507511

512+
// Check if parent URL is SCP-like (e.g., git@github.com:org/repo.git)
513+
// These cannot be properly parsed by net/url and relative submodule resolution is not supported.
514+
if scpLikeURLRegex.MatchString(parentURL) {
515+
return "", fmt.Errorf("relative submodule URL %q cannot be resolved: parent URL %q uses SCP-like syntax which is not supported for relative submodule resolution (see https://github.com/coder/envbuilder/issues/487)", submoduleURL, RedactURL(parentURL))
516+
}
517+
508518
// Parse the parent URL
509519
parentParsed, err := url.Parse(parentURL)
510520
if err != nil {

git/git_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,18 @@ func TestResolveSubmoduleURL(t *testing.T) {
812812
subURL: "./child",
813813
expectErr: "parse parent URL",
814814
},
815+
{
816+
name: "scpParentWithRelativeSubmodule",
817+
parentURL: "git@github.com:org/main.git",
818+
subURL: "../other/submodule.git",
819+
expectErr: "SCP-like syntax which is not supported",
820+
},
821+
{
822+
name: "scpParentWithAbsoluteSubmodule",
823+
parentURL: "git@github.com:org/main.git",
824+
subURL: "https://github.com/other/submodule.git",
825+
expect: "https://github.com/other/submodule.git",
826+
},
815827
}
816828

817829
for _, tc := range cases {

0 commit comments

Comments
 (0)